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

Fix miscalculation of tree size in concurrent editing #202

Merged
merged 2 commits into from
Jun 7, 2024
Merged

Conversation

7hong13
Copy link
Contributor

@7hong13 7hong13 commented Jun 7, 2024

What this PR does / why we need it?

Any background context you want to provide?

What are the relevant tickets?

Fixes #

Checklist

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

Summary by CodeRabbit

  • Version Update

    • Updated application version from 0.4.21-rc to 0.4.23.
  • Tests

    • Added new tests for calculating index tree size during concurrent editing.
    • Added tests for verifying index tree consistency from a snapshot.
  • Performance Improvements

    • Simplified logic for updating ancestor size in the document structure.
    • Enhanced efficiency in updating descendant sizes by skipping removed nodes.

@7hong13 7hong13 added the bug 🐞 Something isn't working label Jun 7, 2024
@7hong13 7hong13 requested review from hackerwins and skhugh June 7, 2024 04:48
@7hong13 7hong13 self-assigned this Jun 7, 2024
Copy link

coderabbitai bot commented Jun 7, 2024

Walkthrough

The recent updates include a version bump in the gradle.properties file, new test methods in JsonTreeTest.kt, and logic simplifications in CrdtTree.kt and IndexTree.kt. The changes enhance the functionality of the JsonTree and IndexTree components by adding new tests and optimizing size calculations and updates.

Changes

File Change Summary
gradle.properties Updated VERSION_NAME from 0.4.21-rc to 0.4.23.
.../JsonTreeTest.kt Added imports for toByteString, toCrdtTree, and toXml. Introduced new test methods for index tree size calculation during concurrent editing and consistency checks from snapshots.
.../CrdtTree.kt Simplified logic for updating ancestor size by removing a conditional check.
.../IndexTree.kt Added a conditional break in a while loop based on the isRemoved property. Modified updateDescendantSize to skip size updates if a node is removed.

Poem

Amidst the code, a version's rise,
From 0.4.21-rc to 0.4.23 it flies.
Tests now bloom in JsonTree's land,
Ensuring size and snapshots stand.
CrdtTree and IndexTree, refined with care,
Logic simplified, updates rare.
In the realm of code, progress we see,
A better future for you and me.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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. I left a comment.

}

size += children.sumOf { it.updateDescendantSize() }
size += children.sumOf { if (it.isRemoved) 0 else it.updateDescendantSize() }
Copy link
Member

Choose a reason for hiding this comment

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

Even if a node is removed, the sizes of the subtree should be updated. So, it would be good to update them by calling updateDescedantSize().

https://github.com/yorkie-team/yorkie-js-sdk/pull/846/files#diff-375b895a8730db047e6747becbb33f2486aa6e6de544f98b8f170ab7c6cb37f4R161

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it to call updateDescendantSize() even when a node is removed: c4d7b25

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b3ebce3 and c4d7b25.

Files selected for processing (4)
  • gradle.properties (1 hunks)
  • yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeTest.kt (3 hunks)
  • yorkie/src/main/kotlin/dev/yorkie/document/crdt/CrdtTree.kt (1 hunks)
  • yorkie/src/main/kotlin/dev/yorkie/util/IndexTree.kt (2 hunks)
Files skipped from review due to trivial changes (2)
  • gradle.properties
  • yorkie/src/main/kotlin/dev/yorkie/document/crdt/CrdtTree.kt
Additional comments not posted (3)
yorkie/src/main/kotlin/dev/yorkie/util/IndexTree.kt (1)

447-449: Clarify the early loop exit when the parent is removed.

The addition of a break condition when the parent node is removed is a sensible optimization. However, adding a comment explaining why this early exit is necessary could help maintain the code's readability and intent for future maintainers.

yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeTest.kt (2)

2306-2341: The test method test_calculating_index_tree_size_during_concurrent_editing correctly simulates concurrent editing scenarios and validates the tree size effectively.


2344-2394: The test method test_index_tree_consistency_from_snapshot effectively ensures the consistency of the index tree from a snapshot after concurrent edits.

@hackerwins hackerwins self-requested a review June 7, 2024 06:18
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.

@7hong13 7hong13 merged commit f0163c7 into main Jun 7, 2024
4 of 6 checks passed
@7hong13 7hong13 deleted the tree-size branch June 7, 2024 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants