-
Notifications
You must be signed in to change notification settings - Fork 85
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
Feat movable tree #120
Merged
Merged
Feat movable tree #120
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
we can now reuse the repr in state and op
# Conflicts: # .vscode/settings.json # crates/loro-common/src/error.rs # crates/loro-common/src/lib.rs # crates/loro-internal/src/arena.rs # crates/loro-internal/src/container.rs # crates/loro-internal/src/delta.rs # crates/loro-internal/src/diff_calc.rs # crates/loro-internal/src/encoding/encode_enhanced.rs # crates/loro-internal/src/event.rs # crates/loro-internal/src/fuzz/recursive_refactored.rs # crates/loro-internal/src/handler.rs # crates/loro-internal/src/loro.rs # crates/loro-internal/src/snapshot_encode.rs # crates/loro-internal/src/state.rs # crates/loro-internal/src/state/list_state.rs # crates/loro-internal/src/state/map_state.rs # crates/loro-internal/src/state/text_state.rs # crates/loro-internal/src/txn.rs # crates/loro-internal/src/value.rs # crates/loro-internal/tests/test.rs # crates/loro-preload/src/encode.rs # crates/loro-wasm/src/lib.rs
# Conflicts: # .vscode/settings.json # Cargo.lock # crates/loro-common/src/error.rs # crates/loro-common/src/lib.rs # crates/loro-internal/Cargo.toml # crates/loro-internal/examples/many_actors.rs # crates/loro-internal/examples/obs.rs # crates/loro-internal/fuzz/Cargo.lock # crates/loro-internal/src/arena.rs # crates/loro-internal/src/arena/str_arena.rs # crates/loro-internal/src/container.rs # crates/loro-internal/src/container/list/list_op.rs # crates/loro-internal/src/container/richtext.rs # crates/loro-internal/src/container/richtext/fugue_span.rs # crates/loro-internal/src/container/richtext/query_by_len.rs # crates/loro-internal/src/container/richtext/richtext_state.rs # crates/loro-internal/src/container/richtext/style_range_map.rs # crates/loro-internal/src/container/richtext/tracker.rs # crates/loro-internal/src/container/richtext/tracker/crdt_rope.rs # crates/loro-internal/src/container/richtext/tracker/id_to_cursor.rs # crates/loro-internal/src/container/text/mod.rs # crates/loro-internal/src/delta.rs # crates/loro-internal/src/delta/text.rs # crates/loro-internal/src/diff_calc.rs # crates/loro-internal/src/encoding/encode_changes.rs # crates/loro-internal/src/encoding/encode_enhanced.rs # crates/loro-internal/src/event.rs # crates/loro-internal/src/fuzz/recursive_refactored.rs # crates/loro-internal/src/handler.rs # crates/loro-internal/src/loro.rs # crates/loro-internal/src/oplog.rs # crates/loro-internal/src/snapshot_encode.rs # crates/loro-internal/src/state.rs # crates/loro-internal/src/state/list_state.rs # crates/loro-internal/src/state/map_state.rs # crates/loro-internal/src/state/richtext_state.rs # crates/loro-internal/src/txn.rs # crates/loro-internal/src/utils/bitmap.rs # crates/loro-internal/src/utils/string_slice.rs # crates/loro-internal/src/value.rs # crates/loro-internal/tests/test.rs # crates/loro-preload/src/encode.rs # crates/loro-wasm/src/lib.rs
Leeeon233
force-pushed
the
feat-movable-tree
branch
from
October 29, 2023 07:59
7651d31
to
d6f3270
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Movable Tree
I implemented the highly-available movable tree crdt made by M. Kleppmann, et al [paper], to support the tree-structure data model. This tree structure supports the following operations:
Concept
I model the tree using a flat structure (
HashMap<TreeID, Option<TreeID>>
) and two additional defined specific root nodes,DELETED_TREE_ROOT
andUNEXIST_TREE_ROOT
so that all operations of the movable tree can be modeled by amove
action.TreeID
: the unique id of a tree node, its fields are the same asID
so we can get the associated metadata container byTreeID
andMap
ContainerType.DELETED_TREE_ROOT
: The root of all deleted nodes. Thedelete
action can be modeled asmove the node to DELETED_TREE_ROOT
.UNEXIST_TREE_ROOT
: The root of all non-existent nodes. When we create a node and then check out the previous vision, we need to delete it from the state instead of moving it toDELETED_TREE_ROOT
.None
parent id: The parent of a root node isNone
.Conflicts
Conflicts may occur when we receive updates from other peers, such as
Peer A
moving nodea
as the successor of nodeb
, butPeer B
does the opposite.Generally speaking, our method of resolving conflicts is to arrange all operations in a unique order(
Lamport
andPeerID
) and apply them one by one. If the operation causes a circular reference, mark the operation asuneffected
(do not apply this operation and ignore its impact). After all operations are applied, it is the final state.Specifically, when a new update is received, we will retreat the operation from back to front until the version is the
LCA
version. Then arrange these operations and new operations and apply them by the method mentioned above.Performance
Profile by M2 Max.
Note:
When making changes to a movable tree, we need to check whether the new operation will cause a cycle, so the deeper the tree, the more time-consuming it is to traverse it.
Demo
An online movable-tree-based todo app can be found here.
TODO
deleted
field fromget_value()
oftree state
DELETE_ROOT
Breaking Change
TreeID
s