-
-
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
Update design for garbage collection and version vector #1019
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 (
|
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.
What a great document! it's good to understand about VV and GC👍👍👍
|
||
A Version Vector is a mechanism used in distributed systems to track the causal relationships between different replicas or nodes. Each node maintains a vector, where each element corresponds to a version counter for every other node in the system, including itself. Whenever a node updates its state, it increments its own counter. When nodes exchange information, they merge their vectors by taking the maximum value for each element, ensuring that the system knows which updates happened concurrently or which one came first. Version Vectors are particularly useful for detecting conflicts and maintaining consistency in distributed databases by providing a more detailed view of the system's state than a single logical clock. | ||
|
||
![version-vector-example](media/version-vector-example.jpg) |
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.
I cannot understand about this traditional version vector image version-vector-example.jpg
. From A@2 to B@3, why the B@3 value is [2, 2, 0]
not [2, 1, 0]
? I understood version vector From A@2 to B@3 is work like [max(2, 0), max(0, 0)+1, max(0, 0)]
.
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.
Whenever a node updates its state, it increments its own counter. When nodes exchange information, they merge their vectors by taking the maximum value for each element,
This part can be confusing because the case that you've mentioned is Vector Clock
.
Also, implementation can be diverged but the important part is maintaining the concept of Version Vector.
version at B@3 is always identical at any time.
For your information, here is a specific explanation. A's lamport increases at A@2, and when B gets A@2, it'll be max([2, 0, 0], [0, 0, 0]) => [2, 0, 0], then we need to compute B's new lamport which is max(2, 1).
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.
thx! understand it!
design/garbage-collection.md
Outdated
### How It Works | ||
|
||
Garbage collection checks that deleted nodes are no longer referenced remotely and purges them completely. | ||
|
||
Server records the logical timestamp of the last change pulled by the client whenever the client requests PushPull. And Server returns the smallest logical timestamp, `min_synced_seq` of all clients in response PushPull to the client. `min_synced_seq` is used to check whether deleted nodes are no longer to be referenced remotely or not. | ||
Server records the version vector of the last change pulled by the client whenever the client requests PushPull. And Server returns the vin version vector, `minVersionVector` of all clients in response PushPull to the client. `minVersionVector` is used to check whether deleted nodes are no longer to be referenced remotely or not. |
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.
Is 'vin' a typo for 'min'?
And Server returns the vin version vector, `minVersionVector` of all clients in response PushPull to the client.
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.
Oh my bad. I'll fix it
|
||
After client receive this minVersionVector, it will filter its version vector to remove detached client's lamport. | ||
The next pushpull request will contains filtered version vector so that eventually db.version vector will store attached client's version vector only. | ||
![filter-version-vector](media/filter-version-vector.jpg) |
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.
I think the image is different from the code above. If the image sync with the code above, It would be easier to understand!
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.
This code filtered c1
's vv. i think this code will be filterd c3
's vv
minVersionVector = {c1:3, c2:3, c3:5}.Filter([c1]) = {c1:3, c2:3}
design/garbage-collection.md
Outdated
|
||
Meanwhile, client `c2` inserts `"c"` after textnode `"b"`. | ||
Meanwhile, `client b` inserts `"c"` after textnode `"b"`. |
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.
client b
's change is local change, so there are not send change 2b
to server and it changes only in local. Am I understanding this correctly?
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.
You're right. client b's change has not been sent in that moment(so it stays as local change).
Only client a's change has been sent.
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.
How about explaining local change for unfamiliar member to yorkie?
=> [c1:2, c2:1, c3:4, c4:0] | ||
|
||
``` | ||
### An example of garbage collection: | ||
#### State 1 | ||
|
||
![garbage-collection-1](media/garbage-collection-1.png) |
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.
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.
A updates and sends changes to the server, and at the same time, B does the same thing. This situation could happen.
design/garbage-collection.md
Outdated
|
||
#### State 4 | ||
|
||
![garbage-collection-4](media/garbage-collection-4.png) | ||
|
||
Finally, after client `c1` receives change `4` from server, purges textnode `"b"` because it is no longer referenced remotely. | ||
`Client a` pushpull but nothing to push or pull. `minVersionVector` is still `{a:1, b:1}`, so no GC happens. |
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.
client a
is pull change 3b
in this image. is it correct?
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.
Yep you're right. Thanks
![garbage-collection-4](media/garbage-collection-5.png) | ||
|
||
`Client b` pushpull but nothing to push or pull. `minVersionVector` is now `{a:3, b:1}`, node "b" removedAt is `3@a`, and `minVersionVector[a] = 3 >= 3`, thus `client b` meets GC condition |
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.
why client b
pull minVersionVector{a:3, b:1}
? Above image garbage-collection-4.png
, client a
pull minVersionVector{a:1, b:1}
.
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.
Ah my bad, I'll fix it
Thanks for your correction
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.
LGTM!😄
What this PR does / why we need it:
Since we're gonna use
version vector
to runGC
after this.I just updated design document for garbage collection and version vector.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist: