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

Update removedAt for already deleted nodes during range deletions #909

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

minai621
Copy link

@minai621 minai621 commented Oct 12, 2024

What this PR does / why we need it:

This PR addresses the issue where removedAt timestamps were not being updated for nodes that had already been deleted during range deletion operations. The changes ensure that the removedAt field reflects the most recent deletion time, which is crucial for maintaining operational consistency across remote clients, particularly in scenarios that may involve future undo/redo functionalities.

Any background context you want to provide?

Previously, nodes that were already marked as removed did not have their removedAt timestamp updated during subsequent deletion operations.
This led to inconsistencies when undoing or redoing changes, especially in cases where multiple clients performed overlapping deletion operations.
This PR ensures that the removedAt field is always reflective of the most recent deletion, thereby maintaining the integrity of the document's operational history and facilitating accurate undo/redo operations.

What are the relevant tickets?

Fixes #821

Checklist

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

Summary by CodeRabbit

  • New Features

    • Enhanced methods for managing tree positions in the CRDT structure.
    • Added a new method for creating a CRDT tree with a root and time ticket.
    • Introduced a comparator for comparing node IDs based on creation time.
    • New function to retrieve the last time ticket for testing purposes.
  • Improvements

    • Streamlined import statements for better organization.
    • Refined methods for handling node edits, styling, and removals, improving concurrent edit management.
  • Bug Fixes

    • Adjusted comparison methods to ensure accurate evaluations of tree positions and IDs.
    • Added test case to verify correct updates of removed nodes during deletions.

- Add logic to update `removedAt` for nodes with outdated deletion times
- Ensure that garbage collection accounts for the latest `removedAt` updates
- Maintain existing behavior for local operations while enhancing remote operation consistency
@minai621 minai621 self-assigned this Oct 12, 2024
@CLAassistant
Copy link

CLAassistant commented Oct 12, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

coderabbitai bot commented Oct 12, 2024

Walkthrough

The changes in the tree.ts file involve a reorganization of import statements and enhancements to several classes related to CRDT (Conflict-free Replicated Data Type) operations. Key modifications include updates to the CRDTTreePos, CRDTTreeNodeID, and CRDTTree classes, with new methods added and existing methods refined for improved functionality. The alterations aim to enhance the management of tree positions, node comparisons, and editing operations within the CRDT structure. Additionally, a new helper function was introduced in the testing utilities, and a test case was added to validate the behavior of node deletions.

Changes

File Path Change Summary
packages/sdk/src/document/crdt/tree.ts Reorganized import statements; updated CRDTTreePos, CRDTTreeNodeID, and CRDTTree classes with new and modified methods for enhanced functionality.
packages/sdk/test/helper/helper.ts Added getLTT function to retrieve the last time ticket; minor formatting change in assertThrowsAsync.
packages/sdk/test/unit/document/crdt/tree_test.ts Added a test case to the CRDTTree.Edit suite to verify updates to removedAt for already deleted nodes during range deletions.

Assessment against linked issues

Objective Addressed Explanation
Update removedAt for already deleted tree and text nodes when performing range deletion operation (#821) The new test case verifies the correct update of removedAt for deleted nodes during range deletions.

Possibly related PRs

  • Improve performance for creating crdt.TreeNode #875: The changes in this PR optimize the fromTreeNodes function, which is related to the management of tree nodes, similar to the updates made to the CRDTTree class in the main PR. Both PRs focus on enhancing the functionality and efficiency of tree structures within the CRDT framework.

🐰 In the forest where the trees sway,
New methods sprout, brightening the day.
With CRDT magic, they dance and play,
Enhancing the nodes in a clever way!
Hopping along, we celebrate this way! 🎉


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
Contributor

@sejongk sejongk left a comment

Choose a reason for hiding this comment

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

I think it would be great to add a test case that checks if the logic satisfies the requirement stated in the issue.
That is, let's extend our current spec by adding a test case for this.

@minai621
Copy link
Author

@sejongk

I think it would be great to add a test case that checks if the logic satisfies the requirement stated in the issue. That is, let's extend our current spec by adding a test case for this.

Is there a way to check the removedAt field in the e2e tests when a remote operation try in?

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/helper/helper.ts (1)

289-294: LGTM: New helper function added.

The getLTT function provides a convenient way to access the last time ticket from the dummyContext, which can be useful in testing scenarios. It's consistent with other helper functions in the file.

Consider whether this function is necessary, as dummyContext.getLastTimeTicket() could be called directly where needed. If it's used frequently in tests, it might be worth keeping for consistency and ease of use.

packages/sdk/test/unit/document/crdt/tree_test.ts (1)

235-235: Consider updating the test name for consistency

For consistency with other test cases in the CRDTTree.Edit suite, consider starting the test name with "Can", for example:

-it('Update removedAt for already deleted nodes during range deletions', function () {
+it('Can update removedAt for already deleted nodes during range deletions', function () {

This aligns with the naming convention used in other test cases.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b51f82d and ff644b0.

📒 Files selected for processing (2)
  • packages/sdk/test/helper/helper.ts (2 hunks)
  • packages/sdk/test/unit/document/crdt/tree_test.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
packages/sdk/test/helper/helper.ts (2)

190-190: LGTM: Minor formatting improvement.

The addition of a space after the arrow function declaration enhances code readability by following a consistent style.


Line range hint 1-294: Overall assessment: Minor improvements to testing utilities.

The changes in this file are minor and focused on improving the testing utilities. They don't introduce any new risks or complexities. The new getLTT function and the formatting improvement in assertThrowsAsync are both acceptable changes that maintain the file's purpose and structure.

packages/sdk/test/unit/document/crdt/tree_test.ts (1)

235-263: Test case accurately verifies 'removedAt' updates

The test is well-structured and effectively verifies that removedAt timestamps are updated correctly for already deleted nodes during range deletions. The assertions confirm that both the parent node (p) and the text node (txt) have their removedAt fields properly set.

@sejongk
Copy link
Contributor

sejongk commented Oct 13, 2024

I've added a test case for quick progress. Please review the test code.
To the best of my knowledge, this issue requires to devise a new approach for tree traversal due to the current weight calculation mechanism.
If anyone thinks my understanding is incorrect, please let me know.

@minai621
Copy link
Author

@sejongk

I've added a test case for quick progress. Please review the test code.
To the best of my knowledge, this issue requires to devise a new approach for tree traversal due to the current weight calculation mechanism.
If anyone thinks my understanding is incorrect, please let me know.

It seems that the txt node has already been deleted from the t tree in the previous edit step. Is it intentional that in assert.isTrue(txt.getRemovedAt()?.equals(getLTT())), the delimiter values are expected to be the same? Given that the txt node is already deleted, should its removedAt timestamp still match the getLTT() value in this context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Update removedAt for already deleted tree and text nodes when performing range deletion operation
3 participants