-
Notifications
You must be signed in to change notification settings - Fork 352
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
Modify ShardTableEntry to differentiate between local shard and remot… #3935
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good overall.
You can run |
@@ -37,40 +39,55 @@ impl ShardTableEntry { | |||
/// # Panics | |||
/// | |||
/// Panics if `shards` is empty after filtering out closed shards and deduplicating by shard ID. | |||
pub fn new(mut shards: Vec<Shard>) -> Self { | |||
pub fn new(mut shards: Vec<Shard>, node_id: String) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn new(mut shards: Vec<Shard>, node_id: String) -> Self { | |
pub fn new(mut shards: Vec<Shard>, node_id: &NodeId) -> Self { |
} | ||
} | ||
|
||
/// Returns the next shard in round-robin order. | ||
pub fn next_shard_round_robin(&self) -> &Shard { | ||
let shard_idx = self.round_robin_idx.fetch_add(1, Ordering::Relaxed); | ||
&self.shards[shard_idx % self.shards.len()] | ||
if self.local_shards.len() > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.local_shards.len() > 0 { | |
if !self.local_shards.is_empty() { |
@@ -99,7 +116,7 @@ impl ShardTable { | |||
shards: Vec<Shard>, | |||
) { | |||
let key = (index_id.into(), source_id.into()); | |||
self.table.insert(key, ShardTableEntry::new(shards)); | |||
self.table.insert(key, ShardTableEntry::new(shards, self.self_node_id.to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.table.insert(key, ShardTableEntry::new(shards, self.self_node_id.to_string())); | |
self.table.insert(key, ShardTableEntry::new(shards, &self.self_node_id)); |
quickwit/quickwit-proto/src/types.rs
Outdated
@@ -171,6 +171,12 @@ impl Borrow<NodeIdRef> for NodeId { | |||
} | |||
} | |||
|
|||
impl Default for NodeId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove Default
on ShardTableEntry
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the default on NodeID because of the default trait used for ShardTable
. Is that what you want to remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Sorry.
Thanks @kamalesh0406! |
…e shards
Description
This change adds the ability for the ShardTableEntry to pick local shards (shards that share the same leader id) when available. If local shards are unavailable, we pick remote shards. This PR was made for issue #3922.
How was this PR tested?
Add unit tests for shard-table. The unit tests for router.rs are failing, I want to confirm if the logic I have written is correct to fix them.