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

Add RHTNode removal to converter for consistency #842

Merged
merged 3 commits into from
Jun 4, 2024
Merged

Conversation

raararaara
Copy link
Contributor

@raararaara raararaara commented Jun 4, 2024

What this PR does / why we need it?

Add RHTNode removal to converter for consistency

This commit addresses the missing isRemoved encoding in the RHT.
Similar to other CRDTs like ElementRHT, including tombstone nodes like
isRemoved during encoding is crucial. However, the RHT did not
include tombstone nodes in its encoding, leading to inconsistencies in
snapshots.

Any background context you want to provide?

What are the relevant tickets?

Checklist

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

Summary by CodeRabbit

  • New Features

    • Introduced new methods to manage key-value pairs internally within the class.
    • Added a boolean field is_removed to enhance data structure functionality.
  • Tests

    • Updated test cases for tree node styling and attribute management.
    • Added a new test case to verify the deepcopy method functionality.

Copy link

coderabbitai bot commented Jun 4, 2024

Warning

Rate limit exceeded

@hackerwins has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 33 minutes and 22 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

Files that changed from the base of the PR and between 85473c8 and fe95b11.

Walkthrough

The recent changes introduce significant enhancements to the conversion functionalities between internal models and Protobuf formats. Key updates include the addition of toRHT and fromRHT functions, modifications to the toTreeNodes and fromTreeNode functions, and new methods in the RHT class for managing key-value pairs. The Protobuf schema is updated with a new is_removed field, and corresponding changes are reflected in the Protobuf TypeScript definitions and JavaScript implementations. Tests are updated to validate these changes.

Changes

File(s) Summary
src/api/converter.ts Added functions toRHT and fromRHT for Protobuf conversions; modified toTreeNodes and fromTreeNode to use these new functions.
src/api/yorkie/v1/resources.proto Added is_removed field to NodeAttr message.
src/api/yorkie/v1/resources_pb.d.ts Added isRemoved property to NodeAttr class.
src/api/yorkie/v1/resources_pb.js Added is_removed field to NodeAttr message.
src/document/crdt/rht.ts Introduced new public methods getNodeMapByKey and setInternal in RHT class.
test/unit/api/converter_test.ts Updated tests to include styling and removal of attributes in tree nodes.
test/unit/document/crdt/rht_test.ts Added test case for deepcopy method in RHT class.

Poem

In the land of code where bytes do flow,
New functions rise, conversions grow.
Protobuf fields now speak of change,
With is_removed, they rearrange.
Trees with style, tests that gleam,
A coder's dream, a rabbit's theme.
🐇✨


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

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.68%. Comparing base (42a88e5) to head (fe95b11).
Report is 1 commits behind head on main.

Files Patch % Lines
src/document/crdt/rht.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #842      +/-   ##
==========================================
+ Coverage   80.66%   80.68%   +0.01%     
==========================================
  Files          59       59              
  Lines        4577     4586       +9     
  Branches      931      932       +1     
==========================================
+ Hits         3692     3700       +8     
- Misses        616      617       +1     
  Partials      269      269              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hackerwins hackerwins marked this pull request as ready for review June 4, 2024 05:27
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: 2

Outside diff range and nitpick comments (4)
src/api/yorkie/v1/resources_pb.js (1)

Line range hint 20-21: Remove redundant 'use strict' directive.

- "use strict";
src/api/converter.ts (3)

Line range hint 142-142: Replace unnecessary template literals with string literals for better performance and clarity.

- throw new YorkieError(Code.Unsupported, `unsupported type: ${valueType}`);
+ throw new YorkieError(Code.Unsupported, 'unsupported type: ' + valueType);

Also applies to: 267-267, 763-763


Line range hint 376-376: Consider replacing non-null assertions with explicit null checks to prevent potential runtime errors.

- pbOperation.body.value = pbSetOperation;
+ if (pbSetOperation) {
+   pbOperation.body.value = pbSetOperation;
+ } else {
+   throw new Error('Expected pbSetOperation to be non-null');
+ }

Also applies to: 396-396, 422-422, 430-430, 449-449, 497-497, 832-832, 911-911, 916-916, 922-922, 925-925, 939-939, 949-949, 960-960


Line range hint 817-819: Consider replacing forEach with for...of for better performance and clarity in loops.

- pbTreeNodes.forEach((node) => {
+ for (const node of pbTreeNodes) {

Also applies to: 854-856

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 42a88e5 and 85473c8.

Files selected for processing (7)
  • src/api/converter.ts (4 hunks)
  • src/api/yorkie/v1/resources.proto (1 hunks)
  • src/api/yorkie/v1/resources_pb.d.ts (1 hunks)
  • src/api/yorkie/v1/resources_pb.js (1 hunks)
  • src/document/crdt/rht.ts (3 hunks)
  • test/unit/api/converter_test.ts (2 hunks)
  • test/unit/document/crdt/rht_test.ts (1 hunks)
Additional context used
Biome
test/unit/api/converter_test.ts

[error] 27-27: The computed expression can be simplified without the use of a string literal.

Unsafe fix: Use a literal key instead.


[error] 28-28: The computed expression can be simplified without the use of a string literal.

Unsafe fix: Use a literal key instead.


[error] 29-29: The computed expression can be simplified without the use of a string literal.

Unsafe fix: Use a literal key instead.


[error] 24-84: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 84-91: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 91-133: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 23-133: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.

src/document/crdt/rht.ts

[error] 138-138: Change to an optional chain.

Unsafe fix: Change to an optional chain.


[error] 146-146: Change to an optional chain.

Unsafe fix: Change to an optional chain.


[error] 231-231: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 300-300: Use === instead of ==.
== is only allowed when comparing against null

== is only allowed when comparing against null

Using == may be unsafe if you are relying on type coercion
Unsafe fix: Use ===


[error] 300-300: Use !== instead of !=.
!= is only allowed when comparing against null

!= is only allowed when comparing against null

Using != may be unsafe if you are relying on type coercion
Unsafe fix: Use !==

test/unit/document/crdt/rht_test.ts

[error] 24-41: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 43-59: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 61-71: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 73-86: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 88-105: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 107-123: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 125-133: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 23-134: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.


[error] 137-137: This enum declaration contains members that are implicitly initialized.

This enum member should be explicitly initialized.

This enum member should be explicitly initialized.

This enum member should be explicitly initialized.

Allowing implicit initializations for enum members can cause bugs if enum declarations are modified over time.
Safe fix: Initialize all enum members.


[error] 192-192: Useless rename.

Safe fix: Remove the renaming.

src/api/yorkie/v1/resources_pb.js

[error] 20-21: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

src/api/converter.ts

[error] 142-142: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal


[error] 267-267: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal


[error] 376-376: Forbidden non-null assertion.


[error] 396-396: Forbidden non-null assertion.


[error] 422-422: Forbidden non-null assertion.


[error] 430-430: Forbidden non-null assertion.


[error] 449-449: Forbidden non-null assertion.


[error] 497-497: Forbidden non-null assertion.


[error] 697-697: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.


[error] 763-763: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal


[error] 817-819: Prefer for...of instead of forEach.

forEach may lead to performance issues when working with large arrays. When combined with functions like filter or map, this causes multiple iterations over the same type.


[error] 832-832: Forbidden non-null assertion.


[error] 854-856: Prefer for...of instead of forEach.

forEach may lead to performance issues when working with large arrays. When combined with functions like filter or map, this causes multiple iterations over the same type.


[error] 911-911: Forbidden non-null assertion.


[error] 916-916: Forbidden non-null assertion.


[error] 922-922: Forbidden non-null assertion.


[error] 925-925: Forbidden non-null assertion.


[error] 939-939: Forbidden non-null assertion.


[error] 949-949: Forbidden non-null assertion.


[error] 960-960: Forbidden non-null assertion.

Additional comments not posted (9)
test/unit/api/converter_test.ts (1)

107-112: Changes to the tree styling and removal are correctly implemented and tested.

src/document/crdt/rht.ts (1)

124-126: The addition of getNodeMapByKey provides a clear way to access the internal node map.

src/api/yorkie/v1/resources.proto (1)

229-229: The addition of the is_removed field to NodeAttr is crucial for accurately tracking the removal state of node attributes.

test/unit/document/crdt/rht_test.ts (1)

125-133: The new test case for deep copying an RHT instance is well-implemented and ensures the correctness of the deepcopy method.

Tools
Biome

[error] 125-133: This function expression can be turned into an arrow function.

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.

src/api/yorkie/v1/resources_pb.js (1)

439-439: Field addition looks correct.

Please verify that existing serialized data handles the new is_removed field gracefully during deserialization.

src/api/converter.ts (3)

595-609: The implementation of toRHT correctly handles the new isRemoved attribute. Well done on maintaining clarity and consistency in the conversion logic.


1068-1082: The implementation of fromRHT correctly handles the new isRemoved attribute, ensuring that the attribute is properly converted from the Protobuf format to the model.


Line range hint 697-697: Specify a more appropriate type instead of using any to enhance type safety and code maintainability.
[ISS

UE]

- function toText(text: CRDTText<Record<string, any>>): PbJSONElement {
+ function toText(text: CRDTText<Record<string, string>>): PbJSONElement {
src/api/yorkie/v1/resources_pb.d.ts (1)

1231-1235: Addition of is_removed field to NodeAttr class aligns with the updated Protobuf definition.

test/unit/api/converter_test.ts Show resolved Hide resolved
src/document/crdt/rht.ts Show resolved Hide resolved
@hackerwins hackerwins changed the title Add RHTNode removal to converter Add RHTNode removal to converter for consistency Jun 4, 2024
@hackerwins hackerwins self-requested a review June 4, 2024 05:49
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.

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.

None yet

2 participants