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

Preserve Detached Client's Lamport in Version Vector #931

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

JOOHOJANG
Copy link
Contributor

@JOOHOJANG JOOHOJANG commented Dec 6, 2024

What this PR does / why we need it?

Since we found GC error in yorkie-team/yorkie#1089.
We decided to leave detached client's lamport in version vector for now and look for a solution later.

I modified following items

  • Local document version vector filtering
  • Using minLamport when run GC

Any background context you want to provide?

What are the relevant tickets?

Fixes yorkie-team/yorkie#1089

Checklist

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

Summary by CodeRabbit

  • New Features

    • Simplified document status update logic after applying change packs.
    • Enhanced garbage collection handling for detached documents in multi-client scenarios.
  • Bug Fixes

    • Improved accuracy of version vector handling during garbage collection.
  • Tests

    • Added new test cases for garbage collection with detached documents and multiple clients.
    • Updated existing tests to ensure comprehensive coverage of version vector states.

Since min version vector contains every client's lamport, we don't need to consider detached client's lamport has been removed from min version vector
@JOOHOJANG JOOHOJANG self-assigned this Dec 6, 2024
Copy link

coderabbitai bot commented Dec 6, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/sdk/src/document/document.ts

Oops! Something went wrong! :(

ESLint: 8.19.0

ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".

(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/packages/sdk".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install @typescript-eslint/eslint-plugin@latest --save-dev

The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "packages/sdk/.eslintrc.js » ../../.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

The pull request modifies the Document and VersionVector classes within the Yorkie SDK. Key changes include the removal of a filtering step for detached clients' Lamport timestamps in the applyChangePack method of the Document class, simplifying the control flow. Additionally, the minLamport method in the VersionVector class has been removed, and the afterOrEqual method has been updated to eliminate reliance on this method. New test cases for garbage collection involving detached documents have also been added to ensure proper functionality.

Changes

File Path Change Summary
packages/sdk/src/document/document.ts Removed filtering of detached clients' Lamport timestamps in applyChangePack; adjusted status update logic.
packages/sdk/src/document/time/version_vector.ts Removed minLamport method; simplified afterOrEqual method logic.
packages/sdk/test/integration/gc_test.ts Added new test cases for garbage collection with detached documents; updated existing tests for version vector state.

Assessment against linked issues

Objective Addressed Explanation
GC error when referencing nodes deleted by detached client (#1089)
Ensure correct behavior of version vectors with detached clients (#1089)

Possibly related PRs

Suggested reviewers

  • hackerwins
  • cloneot
  • chacha912

🐇 In the land of code where the rabbits play,
Changes were made to simplify the way.
Detached clients now find their way clear,
With garbage collection, there's nothing to fear!
Version vectors dance, no longer in fright,
A hop and a skip, everything's right! 🐰✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/sdk/test/integration/gc_test.ts (1)

604-608: Reminder: Address the TODO comment regarding version vector for detached clients

There's a TODO comment at lines 604-608 indicating the need to consider removing detached clients' lamport from the version vector. It's important to resolve or track this before merging to maintain code quality and prevent potential issues related to garbage collection and synchronization.

Would you like assistance in addressing this TODO? I can help implement the necessary changes or open a new GitHub issue to track this task.

packages/sdk/src/document/document.ts (1)

Line range hint 1251-1257: Remove unused filterVersionVector method

With the removal of its usage in applyChangePack, the filterVersionVector method defined at lines 1251-1257 appears to be unused. It's a good practice to remove such unused code to improve maintainability and reduce potential confusion.

Consider removing the unused method:

-  private filterVersionVector(minSyncedVersionVector: VersionVector) {
-    const versionVector = this.changeID.getVersionVector();
-    const filteredVersionVector = versionVector.filter(minSyncedVersionVector);
-
-    this.changeID = this.changeID.setVersionVector(filteredVersionVector);
-  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ea20ed9 and 98472e5.

📒 Files selected for processing (3)
  • packages/sdk/src/document/document.ts (1 hunks)
  • packages/sdk/src/document/time/version_vector.ts (1 hunks)
  • packages/sdk/test/integration/gc_test.ts (9 hunks)
🔇 Additional comments (6)
packages/sdk/test/integration/gc_test.ts (4)

1696-1697: Duplicate TODO comment identified

The same TODO comment about considering the removal of detached clients' lamport from the version vector is present at lines 1696-1697. Ensure that you address this to maintain consistency and prevent potential synchronization issues.

Would you like assistance in resolving this TODO?


2004-2006: Duplicate TODO comment identified

A similar TODO comment is found at lines 2004-2006 regarding the consideration of removing detached clients' lamport from the version vector. Addressing this will help maintain code consistency and functionality.

Would you like assistance in addressing this TODO?


2193-2194: Duplicate TODO comment identified

The TODO comment about removing detached clients' lamport from the version vector appears again at lines 2193-2194. It's crucial to handle this to ensure accurate version vector management.

Would you like assistance in resolving this TODO?


2041-2228: New test case effectively covers garbage collection with detached clients

The newly added test case detach gc test from lines 2041-2228 thoroughly tests the garbage collection process involving detached clients. It simulates interactions among multiple clients, updates, detaches one client, and checks the integrity of version vectors and garbage collection lengths. The assertions appear correct and the test enhances coverage of edge cases related to detached clients.

packages/sdk/src/document/time/version_vector.ts (1)

99-99: Simplification of afterOrEqual logic appears correct

The adjustment in the afterOrEqual method at line 99 directly returns false when lamport is undefined, which simplifies the method and removes unnecessary dependency on the removed minLamport function. This change aligns with the intended logic where an undefined lamport indicates that the version vector does not have an entry for the actor.

packages/sdk/src/document/document.ts (1)

1236-1239: Ensure removal of version vector filtering does not introduce side effects

The filtering step for detached clients' lamport timestamps from the version vector in applyChangePack has been removed at lines 1236-1239. While this simplifies the control flow, it's important to verify that this change does not cause unintended side effects, especially in garbage collection and version synchronization.

Please run the following script to check for any remaining references to the removed filtering logic and confirm that no other parts of the codebase rely on it:

This will help ensure that the removal doesn't affect other functionalities inadvertently.

✅ Verification successful

Let me gather more context about the usage and dependencies of this method.


Let me gather one more piece of information about the change pack handling to understand the complete context.


Based on the gathered evidence, I can now provide the final response:

Removal of version vector filtering is safe and correct

The version vector filtering was redundant as garbage collection already handles the necessary version vector synchronization. The garbageCollect method is properly called with the change pack's version vector during applyChangePack, making the separate filtering step unnecessary. The removal simplifies the code without introducing side effects.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of 'filterVersionVector' method in the codebase

# Find all occurrences of 'filterVersionVector'
rg 'filterVersionVector' -A 3 -B 3

Length of output: 687


Script:

#!/bin/bash
# Search for references to filterVersionVector method calls
ast-grep --pattern 'filterVersionVector($_)'

# Search for any version vector filtering related code
rg -B 3 -A 3 'filter.*VersionVector|VersionVector.*filter'

# Look for any garbage collection related code that might be affected
rg -B 3 -A 3 'garbageCollect|GarbageCollect'

Length of output: 19111


Script:

#!/bin/bash
# Search for applyChangePack implementation and its related code
ast-grep --pattern 'applyChangePack($_) {
  $$$
}'

# Look for version vector usage in change pack handling
rg -B 3 -A 3 'pack.*VersionVector|VersionVector.*pack'

Length of output: 2008

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 changed the title Modifications related to filtering version vectors Preserve Detached Client's Lamport in Version Vector Dec 6, 2024
@hackerwins hackerwins merged commit 98fe2a3 into main Dec 6, 2024
2 checks passed
@hackerwins hackerwins deleted the remove-filtering-version-vector branch December 6, 2024 08:43
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.

GC error when referencing nodes deleted by detached client
3 participants