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

Rework CommitHashRing consensus message into CommitRead/CommitWrite/Finish #4417

Merged
merged 9 commits into from
Jun 19, 2024

Conversation

ffuugoo
Copy link
Contributor

@ffuugoo ffuugoo commented Jun 7, 2024

Tracked in #4213.

This PR reworks CommitHashRing into three separate operations: CommitRead, CommitWrite and Finish.
We need all three to make resharding process seem "transparent" to the user.

We don't (yet) properly track resharding state, so this PR adds some "stubs" and TODOs in places where we will introduce state later.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@ffuugoo ffuugoo requested review from timvisee and generall June 7, 2024 16:12
@ffuugoo
Copy link
Contributor Author

ffuugoo commented Jun 7, 2024

I've got somewhat stuck with an alternative idea (to filter incoming updates), and I had this PR half-implemented already, so I've decided to push this to a working prototype.

In my simple tests - it works:

  • run a cluster (or just a single node in a cluster mode)
  • populate collection with bfb
  • POST collections/benchmark/cluster
    {
      "start_resharding": {}
    }
    
  • POST collections/benchmark/cluster
    {
      "commit_read": {}
    }
    
    • added this operation temporarily, strictly for debug/testing purposes
    • also disabled Tim's code that start resharding driver, so that it won't interfere with testing
  • POST collections/benchmark/points/count
    • should return less points than expected, cause they are considered to be moved to the new shard, and so filtered from the result

I suggest we take a look at the PR and consider, once again, which of the two approaches to implement.

@ffuugoo ffuugoo mentioned this pull request Jun 7, 2024
56 tasks
lib/segment/src/index/struct_payload_index.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/resharding/mod.rs Show resolved Hide resolved
lib/collection/src/shards/shard_holder.rs Outdated Show resolved Hide resolved
lib/collection/src/collection/resharding.rs Outdated Show resolved Hide resolved
@ffuugoo ffuugoo force-pushed the commit-read-write-consensus-message branch from 7b5bc6d to 2cfc12a Compare June 17, 2024 12:55
lib/collection/src/hash_ring.rs Show resolved Hide resolved
lib/segment/src/problems/unindexed_field.rs Outdated Show resolved Hide resolved
Comment on lines 375 to 388
let Some(ring) = self.rings.get(&state.shard_key) else {
return None; // TODO(resharding)!?
};

let HashRing::Resharding { new, .. } = ring else {
return None; // TODO(resharding)!?
};
Copy link
Member

Choose a reason for hiding this comment

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

I would say, error, as we don't expect this.

@ffuugoo ffuugoo force-pushed the commit-read-write-consensus-message branch from 60533e1 to 8739505 Compare June 18, 2024 09:41
@ffuugoo ffuugoo marked this pull request as ready for review June 18, 2024 09:58
Comment on lines 942 to 969
conditions
.into_iter()
.filter(|c| !matches!(c, segment::types::Condition::Resharding(_))) // TODO(resharding)!?
.map(|c| c.into())
.collect()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bit hacky, but this was much easier, than refactoring all read operations, so that we only propagate Condition::Resharding to local read operations, but not to remote read operations.

Copy link
Member

Choose a reason for hiding this comment

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

Would a condition.is_local_only() make sense here?

Comment on lines +296 to +305
fn eq(&self, other: &dyn ReshardingCondition) -> bool {
match other.as_any().downcast_ref::<Self>() {
Some(other) => self == other,
None => false,
}
}

fn as_any(&self) -> &dyn any::Any {
self
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be a bit of an overkill, but this is required to implement PartialEq on Condition.

(Self::HasId(this), Self::HasId(other)) => this == other,
(Self::Nested(this), Self::Nested(other)) => this == other,
(Self::Filter(this), Self::Filter(other)) => this == other,
(Self::Resharding(this), Self::Resharding(other)) => this.eq(other.deref()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without ReshardingCondition::eq and ReshardingCondition::as_any, we can always return false here, but this will kinda break equality for Condition.

Copy link
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

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

Though I don't see any pressing issues, I do see a lot of TODO's. What do we do about those?

If we merge all of the we get a growing number of TODOs which we'll never resolve. I'd suggest as many as possible right away, or remove them if it's something not strictly necessary.

lib/collection/src/collection/point_ops.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/shard_holder.rs Show resolved Hide resolved
@ffuugoo
Copy link
Contributor Author

ffuugoo commented Jun 18, 2024

If we merge all of the we get a growing number of TODOs which we'll never resolve. I'd suggest as many as possible right away, or remove them if it's something not strictly necessary.

All marked with TODO(resharding), we can remove them later, when finalizing resharding.

@ffuugoo ffuugoo force-pushed the commit-read-write-consensus-message branch from 813f124 to 3494359 Compare June 19, 2024 09:03
@ffuugoo ffuugoo force-pushed the commit-read-write-consensus-message branch from 3494359 to 4ef0c7d Compare June 19, 2024 09:09
@timvisee timvisee merged commit d4b3201 into dev Jun 19, 2024
17 checks passed
@timvisee timvisee deleted the commit-read-write-consensus-message branch June 19, 2024 10:14
generall pushed a commit that referenced this pull request Jun 21, 2024
…ite`/`Finish` (#4417)

* Refactor `CommitHashRing` into `CommitRead`/`CommitWrite`/`Finish`

* Add `Resharding` filter condition

* Filter "resharded" points from search, scroll by, count and retrieve request results

* fixup! Refactor `CommitHashRing` into `CommitRead`/`CommitWrite`/`Finish`

`cargo clippy --fix`

* Apply suggestions from code review

* fixup! Filter "resharded" points from search, scroll by, count and retrieve request results

Add `Condition::is_local_only` method

* fixup! Add `Resharding` filter condition

* fixup! Filter "resharded" points from search, scroll by, count and retrieve request results

Clarified a few `TODO`s

* Fix clippy suggestions

---------

Co-authored-by: Tim Visée <tim+github@visee.me>
Co-authored-by: timvisee <tim@visee.me>
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