Skip to content
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

Fix invalid version vector check logic for backward compatibility #1105

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/document/crdt/rga_tree_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ func (s *RGATreeSplit[V]) deleteNodes(
) (map[string]*time.Ticket, map[string]*RGATreeSplitNode[V]) {
createdAtMapByActor := make(map[string]*time.Ticket)
removedNodeMap := make(map[string]*RGATreeSplitNode[V])
isVersionVectorEmpty := len(versionVector) == 0
isMaxCreatedAtMapByActorEmpty := len(maxCreatedAtMapByActor) == 0

if len(candidates) == 0 {
return createdAtMapByActor, removedNodeMap
Expand All @@ -545,10 +547,10 @@ func (s *RGATreeSplit[V]) deleteNodes(

var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if versionVector == nil && maxCreatedAtMapByActor == nil {
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
clientLamportAtChange = time.MaxLamport
} else if len(versionVector) > 0 {
} else if !isVersionVectorEmpty {
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
Expand Down
7 changes: 5 additions & 2 deletions pkg/document/crdt/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ func (t *Text) Style(
// 02. style nodes between from and to
nodes := t.rgaTreeSplit.findBetween(fromRight, toRight)
createdAtMapByActor := make(map[string]*time.Ticket)
isVersionVectorEmpty := len(versionVector) == 0
isMaxCreatedAtMapByActorEmpty := len(maxCreatedAtMapByActor) == 0

var toBeStyled []*RGATreeSplitNode[*TextValue]

for _, node := range nodes {
Expand All @@ -320,10 +323,10 @@ func (t *Text) Style(

var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if versionVector == nil && maxCreatedAtMapByActor == nil {
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
clientLamportAtChange = time.MaxLamport
} else if versionVector != nil {
} else if !isVersionVectorEmpty {
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
Expand Down
21 changes: 15 additions & 6 deletions pkg/document/crdt/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ func (t *Tree) collectBetween(
var toBeRemoveds []*TreeNode
var toBeMovedToFromParents []*TreeNode
createdAtMapByActor := make(map[string]*time.Ticket)
isVersionVectorEmpty := len(versionVector) == 0
isMaxCreatedAtMapByActorEmpty := len(maxCreatedAtMapByActor) == 0

if err := t.traverseInPosRange(
fromParent, fromLeft,
toParent, toLeft,
Expand Down Expand Up @@ -869,10 +872,10 @@ func (t *Tree) collectBetween(

var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if versionVector == nil && maxCreatedAtMapByActor == nil {
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
clientLamportAtChange = time.MaxLamport
} else if versionVector != nil {
} else if !isVersionVectorEmpty {
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
Expand Down Expand Up @@ -1000,6 +1003,9 @@ func (t *Tree) Style(
return nil, nil, err
}

isVersionVectorEmpty := len(versionVector) == 0
isMaxCreatedAtMapByActorEmpty := len(maxCreatedAtMapByActor) == 0

var pairs []GCPair
createdAtMapByActor := make(map[string]*time.Ticket)
if err = t.traverseInPosRange(fromParent, fromLeft, toParent, toLeft, func(token index.TreeToken[*TreeNode], _ bool) {
Expand All @@ -1009,10 +1015,10 @@ func (t *Tree) Style(

var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if versionVector == nil && maxCreatedAtMapByActor == nil {
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
clientLamportAtChange = time.MaxLamport
} else if versionVector != nil {
} else if !isVersionVectorEmpty {
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
Expand Down Expand Up @@ -1069,6 +1075,9 @@ func (t *Tree) RemoveStyle(
return nil, nil, err
}

isVersionVectorEmpty := len(versionVector) == 0
isMaxCreatedAtMapByActorEmpty := len(maxCreatedAtMapByActor) == 0

var pairs []GCPair
createdAtMapByActor := make(map[string]*time.Ticket)
if err = t.traverseInPosRange(fromParent, fromLeft, toParent, toLeft, func(token index.TreeToken[*TreeNode], _ bool) {
Expand All @@ -1078,10 +1087,10 @@ func (t *Tree) RemoveStyle(

var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if versionVector == nil && maxCreatedAtMapByActor == nil {
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
clientLamportAtChange = time.MaxLamport
} else if versionVector != nil {
} else if !isVersionVectorEmpty {
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
Expand Down
Loading