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

Generate correct TreeChange in concurrent edits #712

Merged
merged 5 commits into from
Jan 5, 2024

Conversation

sejongk
Copy link
Contributor

@sejongk sejongk commented Dec 22, 2023

What this PR does / why we need it?

This PR introduces the logic for generating correct TreeChange in concurrent edits.
The main functionalities are collecting nodes to be deleted and creating ranges by accumulating successive nodes in pre-order.

Any background context you want to provide?

Unlike the Text CRDT, Tree has levels and an element node has tags (Opening/Closing).
For multi-level Tree operations (e.g. merge), the determination of which tag is included is currently important. However, using the existing post-order traversal, it is hard to determine if two nodes are successive and if which tags of the node are included in the range.
As a result, This PR introduces a new traversal method that visits all kinds of tag, which include Opening, Closing, and Text.

Alternatives for optimization
Optimizing by using the linked list (prev and next pointers) may be possible, but how to manage the links from the Closing tag and to the Closing tag should be considered.
Like the Text CRDT, generating ranges using undeleted nodes for optimization may be also feasible, but this is likely to require to traverse tombstones.

  • Restore the previous linked list (prev, next link)
  • Renew the traverseInTreePos logic to traverse tombstones as well, and generate ranges using undeleted nodes

What are the relevant tickets?

Fixes yorkie-team/yorkie#732

Checklist

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

@sejongk sejongk marked this pull request as draft December 22, 2023 09:51
Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (5ef1e8f) 81.75% compared to head (7738777) 81.99%.
Report is 4 commits behind head on main.

Files Patch % Lines
src/document/crdt/tree.ts 98.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #712      +/-   ##
==========================================
+ Coverage   81.75%   81.99%   +0.23%     
==========================================
  Files          57       57              
  Lines        4161     4231      +70     
  Branches      805      828      +23     
==========================================
+ Hits         3402     3469      +67     
- Misses        502      503       +1     
- Partials      257      259       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sejongk sejongk marked this pull request as ready for review December 29, 2023 03:39
src/document/crdt/tree.ts Outdated Show resolved Hide resolved
@sejongk sejongk force-pushed the generate-correct-tree-change branch from ef3d6e2 to 452924e Compare January 4, 2024 13:47
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

@hackerwins hackerwins merged commit 207b65e into main Jan 5, 2024
2 checks passed
@hackerwins hackerwins deleted the generate-correct-tree-change branch January 5, 2024 00:52
hackerwins added a commit to yorkie-team/yorkie that referenced this pull request Jan 5, 2024
Unlike JS SDK, this PR doesn't create TreeChanges, but it changes the
traversal logic to be token-based to keep consistency.

Changes:
- Implements token traversal method.
- Ensures accurate inclusion of tokens (Start/End/Text) in ranges.

Related to yorkie-team/yorkie-js-sdk#712

---------

Co-authored-by: Youngteac Hong <susukang98@gmail.com>
@sejongk
Copy link
Contributor Author

sejongk commented Jan 5, 2024

To be specific, compared to the implementation of the previous linked list, the traversal method is now token-based.
Making the most of the linked list for token-based traversal might cause the increased complexity of the logic for managing links.
Therefore, I think using links partially can be beneficial like the following.
스크린샷 2024-01-05 오후 3 34 29

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.

Incorrect TreeChange Generation in Concurrent Editing
2 participants