-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optional insert operation #15
base: master
Are you sure you want to change the base?
Conversation
I think i forgot to add a test for applying an op, will add tomorrow |
At a glance it looks good, but you're right we also need tests for applying. Also you need to update the randomizer to emit @nornagon can you take a quick look at this? |
This seems a bit hacky, would a potential alternative solution be to have the document start with an initial value? so if all clients do 'open or create doc with {default}' where 'default' is the same across all clients, then they can all submit ops to the doc without having the initial od+oi? |
What, like a default document template for each collection? We already support the ability to initialize a document with data. When you create a document you can give it initial content. But you can't initialize everything - eg, if I want an object which has counts of the number of times different actions have happened - eg, |
... A way to think about it which avoids the hacky feeling is that Maybe a cleaner way to implement it would be a variant of
|
... In that case, setNull() would be |
@josephg if I understand you correctly, then if I do sequence like
Then if someone inserted before me, my value will be removed. But also tranform() will remove all operations on removed value, and I feel I'll need a real bad hack to avoid this. |
small update: actually "apply" test already there, on line 330, just forgot I added it :) |
Well whats the right outcome if one client does |
Uhh, that was 2 months ago. After your comment I've returned to my code and it took me half day to recall the problem and finally fix the test :) |
something fails on invert with new seed, have to figure it out |
:) I recommend cranking up the randomiser iterations while you're messing -J |
see PR discussion for details
Ok I fully recalled the problem with randomizer. The idea behind
With randomizer, I'm deciding whatever I need to create
Now when you'll try to transform Client B operations against Client A, you'll get:
The way to fix it is to run |
Well, we can do better than that. Instead of quietly breaking, lets define the semantics of what happens if two clients both execute those operations at the same time. In this case, I think its simpler to think of As for hacking the tests, those operations will be interspersed in any given JSON object - if we hack the randomizer to only use one kind of operation at a time, it'll stop being able to find some bugs. |
@josephg hope you're still with me. I haven't had time to think more about this yet, but yesterday fuzzer found a problem which I'm not sure how to deal with. test case is simple:
The problem is because later ops working on the same path need to be aware that |
Initial version of the "optional insert" operation. The best name I've found is "oin" which means Object Insert if Null.
The goal is to solve situation when both clients to start offline with empty doc and want to collaborate on subobject with known name. Without this operation, last client that syncs to the server will overwrite everything first client did.
Basic transform rules:
Composition rules:
Inversion:
The operation will be deterministic only with sane usage (including invert rule). For example, everyone should try to init document with the same initial value. Everyone should not try to shot operation if he knows for sure that object exists.