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

Modify ShardTableEntry to differentiate between local shard and remot… #3935

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

kamalesh0406
Copy link
Contributor

@kamalesh0406 kamalesh0406 commented Oct 10, 2023

…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.

@kamalesh0406 kamalesh0406 requested a review from guilload October 10, 2023 23:32
Copy link
Member

@guilload guilload left a comment

Choose a reason for hiding this comment

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

Looking good overall.

quickwit/quickwit-ingest/src/ingest_v2/router.rs Outdated Show resolved Hide resolved
quickwit/quickwit-ingest/src/ingest_v2/shard_table.rs Outdated Show resolved Hide resolved
quickwit/quickwit-ingest/src/ingest_v2/shard_table.rs Outdated Show resolved Hide resolved
quickwit/quickwit-ingest/src/ingest_v2/shard_table.rs Outdated Show resolved Hide resolved
@guilload
Copy link
Member

You can run make fmt to fix the formatting issues.
You can run make fix to fix some of the linting issues.

@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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()));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.table.insert(key, ShardTableEntry::new(shards, self.self_node_id.to_string()));
self.table.insert(key, ShardTableEntry::new(shards, &self.self_node_id));

@@ -171,6 +171,12 @@ impl Borrow<NodeIdRef> for NodeId {
}
}

impl Default for NodeId {
Copy link
Member

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.

Copy link
Contributor Author

@kamalesh0406 kamalesh0406 Oct 12, 2023

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Sorry.

@guilload guilload merged commit 429e618 into quickwit-oss:main Oct 12, 2023
3 checks passed
@guilload
Copy link
Member

Thanks @kamalesh0406!

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.

2 participants