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

Handling errors in concurrent editing and styling #795

Closed
wants to merge 3 commits into from

Conversation

raararaara
Copy link
Contributor

@raararaara raararaara commented Feb 14, 2024

What this PR does / why we need it:
Refer to #780 , there is an error occurring in the concurrent editing and styling (Edit+Style) handling.
In a concurrent editing and styling situation, I've concerned the difference between the creation time of nodes included in the style operation range and the time ticket for concurrent editing.

Which issue(s) this PR fixes:

Fixes #788
Related #780

Special notes for your reviewer:
For handle this error, I added logic to ignore style operation(+ removeStyle) for nodes created before concurrency edit writed below. A list of tests resolved with this change can be found in #788 (All test cases related to Style).

  • AS-IS:
err = t.traverseInPosRange(fromParent, fromLeft, toParent, toLeft,
func(token index.TreeToken[*TreeNode], _ bool) {
	node := token.Node
	if !node.IsRemoved() && !node.IsText() && len(attributes) > 0 {
		if node.Attrs == nil {
			node.Attrs = NewRHT()
		}

		for key, value := range attributes {
			node.Attrs.Set(key, value, editedAt)
		}
	}
})
  • TO-BE:
err = t.traverseInPosRange(fromParent, fromLeft, toParent, toLeft,
func(token index.TreeToken[*TreeNode], _ bool) {
	node := token.Node
	if !node.IsRemoved() && !node.IsText() && len(attributes) > 0 {
		// Added here
		if editedAt.After(node.ID.CreatedAt) {
			return
		}
		if node.Attrs == nil {
			node.Attrs = NewRHT()
		}

		for key, value := range attributes {
			node.Attrs.Set(key, value, editedAt)
		}
	}
})

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

@raararaara
Copy link
Contributor Author

The current implementation of the Tree module relies on Lamport Clock, which is not sufficient to resolve concurrent causality in certain scenarios, such as the issue encountered with Text.Style (#639).

However, Hybrid vector clock, mentioned in PR #786, provides a solution to identify concurrent-causal relationships. By implementing this feature, we can effectively handle concurrency issues in the Tree module.

Implementation of a hybrid vector clock could potentially solve this problem as well, so I'll temporarily suspend my current work on handling concurrency in the Tree's editing style.

@hackerwins
Copy link
Member

Fixed by #854

@hackerwins hackerwins closed this May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in concurrent editing and styling (Edit+Style) handling
2 participants