Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Dec 10, 2024
1 parent 9723c80 commit 97d679e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions pkg/document/change/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ func (id ID) SyncClocks(other ID) ID {
lamport = other.lamport + 1
}

newID := NewID(id.clientSeq, InitialServerSeq, lamport, id.actorID, id.versionVector.Max(other.versionVector))
newID.versionVector.Set(id.actorID, lamport)
if len(other.versionVector) == 0 {
newID.versionVector.Set(other.actorID, other.lamport)
// NOTE(chacha912): Handle changes from legacy SDK (v0.5.2 or below) which have empty version vectors.
// Add lamport to version vector to include this change's information.
otherVV := other.versionVector
if len(otherVV) == 0 {
otherVV = otherVV.DeepCopy()
otherVV.Set(other.actorID, other.lamport)
}

newID := NewID(id.clientSeq, InitialServerSeq, lamport, id.actorID, id.versionVector.Max(otherVV))
newID.versionVector.Set(id.actorID, lamport)
return newID
}

Expand All @@ -120,9 +125,12 @@ func (id ID) SetClocks(otherLamport int64, vector time.VersionVector) ID {
lamport = otherLamport + 1
}

// NOTE(chacha912): Snapshot's version vector from server contains initialActorID.
// Remove it as it's not an actual participating client.
vector.Unset(time.InitialActorID)

newID := NewID(id.clientSeq, id.serverSeq, lamport, id.actorID, id.versionVector.Max(vector))
newID.versionVector.Set(id.actorID, lamport)
newID.versionVector.Unset(time.InitialActorID)

return newID
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ func TestGarbageCollection(t *testing.T) {

// 01. Update changes over snapshot threshold.
for i := 0; i <= int(helper.SnapshotThreshold)/2; i++ {
err := d1.Update(func(root *json.Object, p *presence.Presence) error {
err = d1.Update(func(root *json.Object, p *presence.Presence) error {
root.GetText("text").Edit(0, 0, strconv.Itoa(i))
return nil
})
Expand Down

0 comments on commit 97d679e

Please sign in to comment.