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

Refactor keyrange #939

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

lxl66566
Copy link
Collaborator

@lxl66566 lxl66566 commented Aug 7, 2024

close #743

Please briefly answer these questions:

  • what problem are you trying to solve? (or if there's no problem, what's the motivation for this change?)

    • Previously we always transformed between KeyRange and Interval<BytesAffine>, transform through &[u8]. This may make unnecessary Vec clone and memory allocation.
    • And the conflict check in KeyRange is too confusing and troubling due to Bounds.
  • what changes does this pull request make?

    • now KeyRange is refactored:
      pub enum KeyRange {
          OneKey(Vec<u8>),
          Range(Interval<BytesAffine>),
      }
      and it can convert between EtcdKeyRange and Interval<BytesAffine> without cloning.
    • The conflict check is also convenient by using Interval::overlap.
    • The reason spliting KeyRange to OneKey and Range is to distinguish prefix and onekey, which may has same form in [a, a+1).
    • refactored some KeyRange usage in crates/xline/src/storage/index.rs and crates/xline/src/storage/kv_store.rs. By using KeyRange directly instead of start: &[u8], end: &[u8] maybe better to construct from one key or all keys, and reduce the clone times.
  • are there any non-obvious implications of these changes? (does it break compatibility with previous versions, etc)

@mergify mergify bot requested a review from a team August 7, 2024 12:39
Copy link

mergify bot commented Aug 7, 2024

@lxl66566 Convert your pr to draft since CI failed

@mergify mergify bot marked this pull request as draft August 7, 2024 12:48
@mergify mergify bot added the CI:fail CI has failed label Aug 7, 2024
@lxl66566 lxl66566 force-pushed the refactor-keyrange branch 2 times, most recently from 3ee8802 to 60f7fee Compare August 9, 2024 01:51
@mergify mergify bot marked this pull request as ready for review August 9, 2024 02:01
@mergify mergify bot removed the CI:fail CI has failed label Aug 9, 2024
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 78.69955% with 95 lines in your changes missing coverage. Please review.

Project coverage is 75.20%. Comparing base (e35b35a) to head (75cda98).
Report is 332 commits behind head on master.

Files with missing lines Patch % Lines
crates/xlineapi/src/keyrange.rs 75.72% 66 Missing and 9 partials ⚠️
crates/xline/src/storage/index.rs 75.51% 12 Missing ⚠️
crates/xlineapi/src/lib.rs 63.63% 4 Missing ⚠️
crates/xline/src/storage/kv_store.rs 96.29% 1 Missing and 1 partial ⚠️
crates/xline/src/storage/auth_store/perms.rs 80.00% 1 Missing ⚠️
crates/xline/src/storage/lease_store/mod.rs 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #939      +/-   ##
==========================================
- Coverage   75.55%   75.20%   -0.36%     
==========================================
  Files         180      190      +10     
  Lines       26938    28625    +1687     
  Branches    26938    28625    +1687     
==========================================
+ Hits        20353    21526    +1173     
- Misses       5366     5791     +425     
- Partials     1219     1308      +89     

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

Copy link

mergify bot commented Aug 15, 2024

@lxl66566 Your PR is in conflict and cannot be merged.

Copy link

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 14 days

Copy link

mergify bot commented Oct 13, 2024

@lxl66566 Convert your pr to draft since CI failed

@mergify mergify bot marked this pull request as draft October 13, 2024 15:30
@mergify mergify bot added the CI:fail CI has failed label Oct 13, 2024
@mergify mergify bot marked this pull request as ready for review October 27, 2024 15:32
@mergify mergify bot removed the CI:fail CI has failed label Oct 27, 2024
Comment on lines +417 to +400
/// OneKey, to distinguish from `Prefix` because they all have [a, a+1) form
OneKey(&'a [u8]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

A single key is ["a", "a\x00") while a prefix should be ["a", "b"). Why do we need a separate OneKey variant?

/// Range end to get one key
pub const ONE_KEY: &[u8] = &[];

pub trait Add1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be more appropriate to name it Successor?

crates/xlineapi/src/keyrange.rs Outdated Show resolved Hide resolved
crates/xlineapi/src/keyrange.rs Outdated Show resolved Hide resolved
@mergify mergify bot requested a review from a team November 1, 2024 01:08
Signed-off-by: lxl66566 <[email protected]>

refactor(xlineapi): KeyRange refactor

Signed-off-by: lxl66566 <[email protected]>

refactor(xlineapi): refactor success, test pass

Signed-off-by: lxl66566 <[email protected]>

refactor(xlineapi): use KeyRange instead of directly pass &[u8] to avoid clone

Signed-off-by: lxl66566 <[email protected]>

refactor(xlineapi): simplify all keys judgement

Signed-off-by: lxl66566 <[email protected]>
Copy link

github-actions bot commented Dec 5, 2024

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 14 days

@github-actions github-actions bot added the Stale label Dec 5, 2024
Copy link

mergify bot commented Dec 5, 2024

@lxl66566 Your PR is in conflict and cannot be merged.

@github-actions github-actions bot removed the Stale label Dec 6, 2024
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.

[Refactor]: Remove KeyRange
2 participants