-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
Implementing GC Using Version Vector #981
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
If there's no pushing changes, the version vector in the local differs from the version vector in the db, and updates only happens when pushing. Thus, update in pulling is needed.
…tep and add version vector assertion
There was a problem hiding this 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. I hope the GC issue will be resolved by this.
It would be good to update design document after merging this. https://github.com/yorkie-team/yorkie/blob/main/design/garbage-collection.md
And I left a few comments.
…lamport from other's version vector
3aee87b
to
a00128d
Compare
…ake version vector comments to a single line
There was a problem hiding this 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.
What this PR does / why we need it:
The purpose of this PR is to address a defect found in the existing GC that used syncedSeq, by introducing VersionVector to resolve the issue.
The diagram of the structure can be found at this link.
Here are the four key points to focus on:
1. What is Lamport Synced Version Vector
Definition of Version Vector
Since we're using lamport timestamp to handle CRDT, we implement Lamport Synced Version Vector which is quite different from original Version Vector.
Lamport Synced Version Vector allows us to continue using the existing method that relied on Lamport.
It is key:value map consist of actorID and lamport.
At the above image, you can see that the client’s Lamport is always the largest, which is consistent with how we used to update and utilize lamport in the past.As you can see from the image above, which is typical version vector example, client's value(lamport in our case) is not the largest at every moment.
For convenience, I will refer to Lamport Synced Version Vector as the version vector from now on.
When creating a new change, we increment both the lamport and the lamport in the version vector to use as the ID. Thus, we don't need to use version vector as ID, but use as a part of ID. You can see how it is used in the modified code (see changeID parts).
When receiving a new change, compute max version vector by using version vector from change and document's version vector.
2. How to store version vector into database and update it when receives change
updateVersionVector
,updateAndFindMinSyncedVersionVectorAfterPushPull
)3. What is min version vector and how to solve GC problem
Min version vector is the vector which consists of minimum value of every version vector stored in version vector table in database.
Conceptually, min version vector is version vector that is uniformly applied to all users. It ensures that all users have at least this version applied. Which means that it is safe to perform GC.
You can see detailed logic from
UpdateAndFindMinVersionVectorAfterPushPull
in modified codes.Suppose clientA is performing pushpull
GC algorithm
If node.removedAt.lamport is smaller or equal to every value in min version vector, then run GC.
It's okay to run GC when its equal, because the meaning of min version vector is that every client's version vector is at least larger then min version vector.
4. How to handle detached client's version vector
If detached client's version vector remains in database and local document, its memory wasting and also GC will not performed.
So it's necessary to remove detached client's version vector and its lamport from other's version vector.
By the way, the code is a bit messy, so any reviews are always welcome. If you have any ideas for improvements, feel free to share them.
Which issue(s) this PR fixes:
Address #723
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist: