Skip to content

Commit

Permalink
Erase duplicate vv update
Browse files Browse the repository at this point in the history
  • Loading branch information
raararaara committed Nov 19, 2024
1 parent 719022d commit e18af1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
12 changes: 0 additions & 12 deletions server/rpc/cluster_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,5 @@ func (s *clusterServer) DetachDocument(
return nil, err
}

if err = s.backend.DB.UpdateVersionVector(
ctx,
clientInfo,
types.DocRefKey{
ProjectID: project.ID,
DocID: summary.ID,
},
nil,
); err != nil {
return nil, err
}

return connect.NewResponse(&api.ClusterServiceDetachDocumentResponse{}), nil
}
22 changes: 11 additions & 11 deletions test/integration/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,43 +1142,43 @@ func TestGarbageCollection(t *testing.T) {
d1 := document.New(helper.TestDocKey(t))
assert.NoError(t, c1.Attach(ctx, d1))
// d2.vv =[c1:1], minvv =[c1:1], db.vv {c1: [c1:1]}
assert.Equal(t, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 1)), true)
assert.Equal(t, true, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 1)))

d2 := document.New(helper.TestDocKey(t))
assert.NoError(t, c2.Attach(ctx, d2))
// d2.vv =[c1:1, c2:1], minvv =[c1:0, c2:0], db.vv {c1: [c1:1], c2: [c2:1]}
assert.Equal(t, checkVV(d2.VersionVector(), versionOf(d1.ActorID(), 1), versionOf(d2.ActorID(), 2)), true)
assert.Equal(t, true, checkVV(d2.VersionVector(), versionOf(d1.ActorID(), 1), versionOf(d2.ActorID(), 2)))

err := d1.Update(func(root *json.Object, p *presence.Presence) error {
root.SetNewText("text").Edit(0, 0, "a").Edit(1, 1, "b").Edit(2, 2, "c")
return nil
}, "sets text")
//d1.vv = [c1:2]
assert.Equal(t, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 2)), true)
assert.Equal(t, true, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 2)))
assert.NoError(t, err)

assert.NoError(t, c1.Sync(ctx))
// d1.vv =[c1:3, c2:1], minvv =[c1:0, c2:0], db.vv {c1: [c1:2], c2: [c2:1]}
assert.Equal(t, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 3), versionOf(d2.ActorID(), 1)), true)
assert.Equal(t, true, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 3), versionOf(d2.ActorID(), 1)))

assert.NoError(t, c2.Sync(ctx))
// d2.vv =[c1:2, c2:3], minvv =[c1:0, c2:0], db.vv {c1: [c1:2], c2: [c1:1, c2:2]}
assert.Equal(t, checkVV(d2.VersionVector(), versionOf(d1.ActorID(), 2), versionOf(d2.ActorID(), 3)), true)
assert.Equal(t, true, checkVV(d2.VersionVector(), versionOf(d1.ActorID(), 2), versionOf(d2.ActorID(), 3)))

err = d2.Update(func(root *json.Object, p *presence.Presence) error {
root.GetText("text").Edit(2, 2, "c")
return nil
}, "insert c")
//d2.vv =[c1:2, c2:4]
assert.Equal(t, checkVV(d2.VersionVector(), versionOf(d1.ActorID(), 2), versionOf(d2.ActorID(), 4)), true)
assert.Equal(t, true, checkVV(d2.VersionVector(), versionOf(d1.ActorID(), 2), versionOf(d2.ActorID(), 4)))
assert.NoError(t, err)

err = d1.Update(func(root *json.Object, p *presence.Presence) error {
root.GetText("text").Edit(1, 3, "")
return nil
}, "delete bd")
//d1.vv = [c1:4, c2:1]
assert.Equal(t, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 4), versionOf(d2.ActorID(), 1)), true)
assert.Equal(t, true, checkVV(d1.VersionVector(), versionOf(d1.ActorID(), 4), versionOf(d2.ActorID(), 1)))
assert.NoError(t, err)
assert.Equal(t, 2, d1.GarbageLen())
assert.Equal(t, 0, d2.GarbageLen())
Expand All @@ -1187,11 +1187,11 @@ func TestGarbageCollection(t *testing.T) {
assert.NoError(t, c2.Sync(ctx))
assert.NoError(t, c1.Deactivate(ctx))

assert.Equal(t, d2.GarbageLen(), 2)
assert.Equal(t, len(d2.VersionVector()), 2)
assert.Equal(t, 2, d2.GarbageLen())
assert.Equal(t, 2, len(d2.VersionVector()))

assert.NoError(t, c2.Sync(ctx))
assert.Equal(t, d2.GarbageLen(), 0)
assert.Equal(t, len(d2.VersionVector()), 1)
assert.Equal(t, 0, d2.GarbageLen())
assert.Equal(t, 1, len(d2.VersionVector()))
})
}

0 comments on commit e18af1e

Please sign in to comment.