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

Replace maxCreatedAtMap with version vector for causal-concurrent operations #932

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

chacha912
Copy link
Contributor

@chacha912 chacha912 commented Dec 9, 2024

What this PR does / why we need it?

This PR replaces the usage of MaxCreatedAtMapByActor with version vector for operations that handle causal and concurrent relationships. (Text.Edit, Text.Style, Tree.Edit, and Tree.Style)

Any background context you want to provide?

What are the relevant tickets?

Related yorkie-team/yorkie#1088

Checklist

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

Summary by CodeRabbit

  • New Features

    • Enhanced operation execution with version vector support across various document operations.
    • Improved node management in CRDT structures, allowing for more precise control over edits and styles.
  • Bug Fixes

    • Adjusted logic for node existence checks and style applications to incorporate new parameters.
  • Documentation

    • Updated method signatures to reflect new parameters related to versioning.
  • Chores

    • Refactored imports and constants for consistency in versioning across the SDK.

@chacha912 chacha912 requested a review from hackerwins December 9, 2024 01:07
Copy link

coderabbitai bot commented Dec 9, 2024

Warning

Rate limit exceeded

@chacha912 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 36b4a38 and 0d714bd.

📒 Files selected for processing (9)
  • packages/sdk/src/document/change/change.ts (1 hunks)
  • packages/sdk/src/document/crdt/rga_tree_split.ts (9 hunks)
  • packages/sdk/src/document/crdt/text.ts (5 hunks)
  • packages/sdk/src/document/crdt/tree.ts (9 hunks)
  • packages/sdk/src/document/operation/edit_operation.ts (3 hunks)
  • packages/sdk/src/document/operation/operation.ts (2 hunks)
  • packages/sdk/src/document/operation/style_operation.ts (3 hunks)
  • packages/sdk/src/document/operation/tree_edit_operation.ts (4 hunks)
  • packages/sdk/src/document/operation/tree_style_operation.ts (6 hunks)

Walkthrough

This pull request introduces modifications across several files to enhance the handling of versioning in operations. Key changes include the addition of a versionVector parameter in various execute methods and updates to existing methods to incorporate this parameter, allowing for more nuanced control over operations based on versioning. The changes primarily affect classes related to document operations, including Change, EditOperation, and various CRDT structures, ensuring that operations can now consider versioning information during execution.

Changes

File Path Change Summary
packages/sdk/src/document/change/change.ts Updated execute method to include this.id.getVersionVector() as a third argument. Method signature modified to return { opInfos: Array<OperationInfo>; reverseOps: Array<HistoryOperation<P>> }.
packages/sdk/src/document/crdt/rga_tree_split.ts Replaced MaxTimeTicket with MaxLamport. Updated canDelete and canStyle methods to include clientLamportAtChange. Modified edit, deleteNodes, and filterNodes methods to accept versionVector and incorporate it in logic.
packages/sdk/src/document/crdt/text.ts Added MaxLamport and VersionVector imports. Updated edit and setStyle methods to include an optional versionVector parameter, altering logic to utilize it for determining clientLamportAtChange.
packages/sdk/src/document/crdt/tree.ts Replaced MaxTimeTicket with MaxLamport. Updated canDelete and canStyle methods to accept clientLamportAtChange. Modified style, removeStyle, and edit methods to include versionVector and adjust their logic accordingly.
packages/sdk/src/document/operation/edit_operation.ts Updated execute method signature to include versionVector. Logic remains largely intact, but now supports versioning information.
packages/sdk/src/document/operation/operation.ts Updated execute method signature in the Operation abstract class to include an optional versionVector.
packages/sdk/src/document/operation/style_operation.ts Updated execute method signature to include versionVector. Logic adjusted to incorporate versioning during execution.
packages/sdk/src/document/operation/tree_edit_operation.ts Updated execute method signature to include versionVector. Logic remains largely intact but accommodates versioning information.
packages/sdk/src/document/operation/tree_style_operation.ts Updated execute method signature to include versionVector. Adjusted logic to incorporate versioning in style operations.

Possibly related PRs

Suggested reviewers

  • hackerwins

🐰 In the land of code, where changes bloom,
A version vector brings life to the room.
With each operation, a dance we embrace,
Enhancing our edits, we quicken the pace.
So hop along, dear friends, let’s celebrate,
For every new feature, we elevate! 🌼


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.

@chacha912 chacha912 requested a review from JOOHOJANG December 9, 2024 01:07
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: 5

🧹 Outside diff range and nitpick comments (5)
packages/sdk/src/document/operation/tree_style_operation.ts (1)

79-79: Consider making attributesToRemove an optional parameter with a default value

In the create method, attributesToRemove is being passed as an empty array []. To enhance code readability and simplify method calls, consider making attributesToRemove optional in the constructor and assigning a default value of an empty array. This way, you can avoid passing empty arrays explicitly when there are no attributes to remove.

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

79-83: Consider removing unused parameter

The _: OpSource parameter is not used in the method implementation. Consider removing it if it's not required by the interface.

 public execute<A extends Indexable>(
   root: CRDTRoot,
-  _: OpSource,
   versionVector: VersionVector,
 ): ExecutionResult {
packages/sdk/src/document/operation/edit_operation.ts (1)

85-89: Consider removing unused parameter

The _: OpSource parameter is not used in the method implementation. Consider removing it if it's not required by the interface.

 public execute<A extends Indexable>(
   root: CRDTRoot,
-  _: OpSource,
   versionVector: VersionVector,
 ): ExecutionResult {
packages/sdk/src/document/change/change.ts (2)

165-169: Fix indentation in execute method call

While the implementation is correct, the indentation appears inconsistent with the codebase style.

Apply this diff to fix the indentation:

-      const executionResult = operation.execute(
-        root,
-        source,
-        this.id.getVersionVector(),
-      );
+      const executionResult = operation.execute(root, source, this.id.getVersionVector());

165-169: Consider documenting version vector implementation details

The shift from MaxCreatedAtMap to version vector is a significant architectural change. Consider:

  1. Adding documentation about version vector's role in causality tracking
  2. Documenting any performance implications
  3. Updating relevant API documentation

This will help maintainers understand the reasoning behind this architectural change and its implications.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 98fe2a3 and 36b4a38.

📒 Files selected for processing (9)
  • packages/sdk/src/document/change/change.ts (1 hunks)
  • packages/sdk/src/document/crdt/rga_tree_split.ts (9 hunks)
  • packages/sdk/src/document/crdt/text.ts (5 hunks)
  • packages/sdk/src/document/crdt/tree.ts (9 hunks)
  • packages/sdk/src/document/operation/edit_operation.ts (3 hunks)
  • packages/sdk/src/document/operation/operation.ts (2 hunks)
  • packages/sdk/src/document/operation/style_operation.ts (3 hunks)
  • packages/sdk/src/document/operation/tree_edit_operation.ts (4 hunks)
  • packages/sdk/src/document/operation/tree_style_operation.ts (6 hunks)
🔇 Additional comments (8)
packages/sdk/src/document/crdt/text.ts (1)

Line range hint 952-963: Duplicate potential null reference error with versionVector in filterNodes method

The same issue exists in the filterNodes method. Please ensure that versionVector is checked for undefined before accessing its properties to prevent runtime errors.

packages/sdk/src/document/crdt/tree.ts (2)

1009-1023: Duplicate potential null reference error with versionVector in removeStyle method

The same issue exists in the removeStyle method. Please ensure that versionVector is checked for undefined before accessing its properties.


1117-1131: Duplicate potential null reference error with versionVector in edit method

The same issue exists in the edit method. Please ensure that versionVector is checked for undefined before accessing its properties.

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

103-103: LGTM: Version vector integration

The version vector is correctly propagated to the underlying setStyle method, which aligns with the PR's objective of replacing maxCreatedAtMap with version vector for causal-concurrent operations.

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

111-111: LGTM: Version vector integration

The version vector is correctly propagated to the underlying edit method, which aligns with the PR's objective of replacing maxCreatedAtMap with version vector for causal-concurrent operations.

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

133-133: LGTM: Version vector integration

The version vector is correctly propagated to the underlying edit method, which aligns with the PR's objective of replacing maxCreatedAtMap with version vector for causal-concurrent operations.

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

19-19: LGTM: Import statement correctly placed with time-related imports

The new import for VersionVector is appropriately grouped with other time-related imports.

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

165-169: Verify version vector propagation in concurrent scenarios

The implementation correctly passes the version vector from the change ID to each operation. However, we should verify the behavior in concurrent editing scenarios.

✅ Verification successful

Based on the search results, I can see extensive testing of version vector propagation in concurrent scenarios, particularly in:

  1. test/integration/tree_concurrency_test.ts - Contains numerous test cases for concurrent operations including edit-edit, style-style, edit-style, and split operations
  2. test/integration/text_test.ts - Tests concurrent edit operations, insertions, deletions
  3. test/integration/gc_test.ts - Verifies version vector behavior during garbage collection in concurrent scenarios

The implementation is well-tested for concurrent editing scenarios, with proper version vector propagation verified through comprehensive test cases. The version vector is correctly used to track causality between operations from different clients.

Version vector propagation is properly implemented and tested for concurrent scenarios

  • The version vector is correctly passed from change ID to operations
  • Extensive test coverage exists for concurrent operations
  • Version vector maintains proper causality tracking between concurrent changes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for test cases that verify concurrent operations
# with version vectors to ensure proper causality handling

# Search for test files containing concurrent operation scenarios
rg -l "concurrent|simultaneous|parallel" --type ts "test"

# Search for version vector usage in test files
rg "getVersionVector|versionVector" --type ts "test"

Length of output: 200


Script:

#!/bin/bash
# Let's first find test files in the repository
fd "\.test\.(ts|js)$"

# Then search for concurrent operations and version vectors in the entire codebase
rg -A 5 "concurrent|simultaneous|parallel" --type ts
rg -A 5 "getVersionVector|versionVector" --type ts

Length of output: 112008

@chacha912 chacha912 force-pushed the replace-maxcreatedat branch from 36b4a38 to 0d714bd Compare December 9, 2024 01:16
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 db02eb9 into main Dec 9, 2024
2 checks passed
@hackerwins hackerwins deleted the replace-maxcreatedat branch December 9, 2024 04:58
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.

2 participants