-
Notifications
You must be signed in to change notification settings - Fork 466
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
API for initializing a document with a 'null' author and timestamp? #374
Comments
I like the idea of this becoming a part of the library as it seems like a very easy thing to trip up on otherwise, I wonder if there are use cases where you wouldn't always want a common shared ancestor for all peers? I'd expect that in that case you could use separate documents. Anyway I'd be for adding functionality to the Do we know how Yjs handles this? Just may be a point of reference. |
I agree that we need a solution for this problem, but I'm not totally convinced that this approach is the best one. Special-casing the initialisation change to make it deterministic helps in the simple case when all peers perform exactly the same initialisation. However, if the developer ever changes the initialisation code, it will produce a different change with a different hash, and then we're back to square one again with conflicts on the top-level I think a better approach would be to revive what was discussed years ago in #4: if two users concurrently create objects of the same type under the same key, then we don't make a conflict, but rather we merge the operations on those objects into a single object. That would have the desired effect in many common cases. There might still be some cases of initialisation where a deterministic initialisation change is needed, but they would be much less common. |
Thanks @ept - I knew something along these lines had come up in the past. I've reread #4 and I agree that's the right approach. |
I think , we could create 2 new data type. SharedArray and SharedMap (or other name like NoConflictArray , NoConflictMap user A set data.todo = SharedArray(1) user A set data.todo = SharedArray(1) |
then we can add some action like makeConfictFreeList and makeConfictFreeMap |
@DiamondYuan That would be a big API change, which I'm not keen on. I think we can change the semantics for concurrently created objects on the same key without otherwise changing the API. |
Suppose Alice initializes a document as follows:
Alice adds some todos:
Now Bob initializes his document using the same code as Alice:
Alice and Bob connect using the new sync protocol, perhaps using an implementation like this one. https://github.com/HerbCaudill/todomvc-automerge/blob/master/src/AutomergeSync.tsx
Half of the time, they will converge on Alice's list with two items; the other half, they will converge on Bob's empty list. It seems to me that the preferred outcome here is always going to be converge on Alice's list.
I asked about this on Slack and @ept suggested initializing the document with a "null" authorId like
0000
, and a timestamp of0
.conversation from slack fwiw
This is the code I've ended up with, which solves the problem:
It seems like this is a fairly common use case, if not the most likely scenario & as such, it seems like it deserves better than this ugly user-land solution. A couple of possibilities come to mind:
My preferred solution would be to treat
init
andfrom
as special cases, with no author, and timestamp 0. Seems to me that it's not really meaningful to talk about "conflicts" in the context of the initial creation of the document. Alice's initialization and Bob's initialization are, for practical purposes, the same event. So basicallyinit
would have{ authorId: '0000' }
as the default options, andfrom
would have{ time: 0}
as the change options by default.Alternatively, we could expose my
initWithNullAuthor
as its own top-level Automerge function (hopefully with a better name!)The text was updated successfully, but these errors were encountered: