Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuration/node-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A commented example is available here: [quickwit.yaml](https://github.com/quickw
| --- | --- | --- | --- |
| `version` | Config file version. `0.7` is the only available value with a retro compatibility on `0.5` and `0.4`. | | |
| `cluster_id` | Unique identifier of the cluster the node will be joining. Clusters sharing the same network should use distinct cluster IDs.| `QW_CLUSTER_ID` | `quickwit-default-cluster` |
| `extra_cluster_ids` | Additional cluster IDs accepted during a rolling rename: first accept the new ID, then switch `cluster_id` while accepting the old ID, then clear this list. Complete each rollout on all nodes before starting the next. The environment variable accepts a comma-separated list of IDs. | `QW_EXTRA_CLUSTER_IDS` | `[]` |
| `node_id` | Unique identifier of the node. It must be distinct from the node IDs of its cluster peers. Searchers hash this ID for split affinity, so keep it stable across restarts (for example a StatefulSet pod name) if the same splits should keep landing on the same node. Defaults to the instance's short hostname if not set. | `QW_NODE_ID` | short hostname |
| `enabled_services` | Enabled services (control_plane, indexer, janitor, metastore, metastore_read_replica, searcher) | `QW_ENABLED_SERVICES` | all services except metastore_read_replica |
| `listen_address` | The IP address or hostname that Quickwit service binds to for starting REST and GRPC server and connecting this node to other nodes. By default, Quickwit binds itself to 127.0.0.1 (localhost). This default is not valid when trying to form a cluster. | `QW_LISTEN_ADDRESS` | `127.0.0.1` |
Expand Down
3 changes: 1 addition & 2 deletions quickwit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion quickwit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bitpacking = "0.9"
bytes = { version = "1", features = ["serde"] }
bytesize = { version = "2.4", features = ["serde"] }
bytestring = "1.5"
chitchat = "0.13.0"
chitchat = { git = "https://github.com/quickwit-oss/chitchat.git", rev = "eaa921d3d4fc344b811c3a73eebd6371cbaff0b8" }
chrono = { version = "0.4", default-features = false, features = [
"clock",
"std",
Expand Down
1 change: 1 addition & 0 deletions quickwit/quickwit-cli/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ async fn create_empty_cluster(config: &NodeConfig) -> anyhow::Result<Cluster> {
let channel_factory = ChannelFactory::for_grpc(&config.grpc_config)?;
let cluster = Cluster::join(
config.cluster_id.clone(),
config.extra_cluster_ids.iter().cloned().collect(),
self_node,
config.gossip_advertise_addr,
Vec::new(),
Expand Down
162 changes: 131 additions & 31 deletions quickwit/quickwit-cluster/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const INDEXING_TASK_PREFIX: &str = "indexer.task:";
#[derive(Clone)]
pub struct Cluster {
cluster_id: String,
extra_cluster_ids: HashSet<String>,
self_chitchat_id: ChitchatId,
/// Socket address (UDP) the node listens on for receiving gossip messages.
pub gossip_listen_addr: SocketAddr,
Expand Down Expand Up @@ -147,6 +148,10 @@ impl Cluster {
&self.cluster_id
}

pub(crate) fn rejects_cluster_id(&self, cluster_id: &str) -> bool {
self.cluster_id != cluster_id && !self.extra_cluster_ids.contains(cluster_id)
}

pub fn self_chitchat_id(&self) -> &ChitchatId {
&self.self_chitchat_id
}
Expand All @@ -166,6 +171,7 @@ impl Cluster {
#[allow(clippy::too_many_arguments)]
pub async fn join(
cluster_id: String,
extra_cluster_ids: HashSet<String>,
self_node: ClusterMember,
gossip_listen_addr: SocketAddr,
peer_seed_addrs: Vec<String>,
Expand Down Expand Up @@ -202,6 +208,7 @@ impl Cluster {
})?;
let chitchat_config = ChitchatConfig {
cluster_id: cluster_id.clone(),
extra_cluster_ids: extra_cluster_ids.clone(),
chitchat_id: self_node.chitchat_id(),
listen_addr: gossip_listen_addr,
seed_nodes: peer_seed_addrs,
Expand Down Expand Up @@ -264,6 +271,7 @@ impl Cluster {
};
let cluster = Cluster {
cluster_id,
extra_cluster_ids,
self_chitchat_id: self_node.chitchat_id(),
gossip_listen_addr,
gossip_interval,
Expand Down Expand Up @@ -727,37 +735,100 @@ pub async fn create_cluster_for_test_with_id(
transport: &dyn Transport,
self_node_readiness: bool,
) -> anyhow::Result<Cluster> {
use quickwit_proto::indexing::PIPELINE_FULL_CAPACITY;
use quickwit_proto::ingest::ingester::IngesterStatus;
let gossip_advertise_addr: SocketAddr = ([127, 0, 0, 1], gossip_advertise_port).into();
let self_node = ClusterMember {
node_id,
generation_id: crate::GenerationId(1),
is_ready: self_node_readiness,
enabled_services: enabled_services.clone(),
gossip_advertise_addr,
grpc_advertise_addr: grpc_addr_from_listen_addr_for_test(gossip_advertise_addr),
indexing_tasks: Vec::new(),
indexing_cpu_capacity: PIPELINE_FULL_CAPACITY,
ingester_status: IngesterStatus::default(),
availability_zone: None,
enable_standalone_compactors: false,
};
let failure_detector_config = create_failure_detector_config_for_test();
let cluster = Cluster::join(
cluster_id,
self_node,
gossip_advertise_addr,
peer_seed_addrs,
Duration::from_millis(25),
ProtocolVersion::V0.to_code(),
failure_detector_config,
transport,
crate::change::for_test::channel_factory_for_test(),
)
.await?;
cluster.set_self_node_readiness(self_node_readiness).await;
Ok(cluster)
TestClusterBuilder::new(node_id, gossip_advertise_port, transport)
.with_cluster_id(cluster_id)
.with_peer_seeds(peer_seed_addrs)
.with_services(enabled_services.clone())
.with_readiness(self_node_readiness)
.build()
.await
}

/// Builds a test cluster node with optional cluster and membership settings.
#[cfg(any(test, feature = "testsuite"))]
pub struct TestClusterBuilder<'a> {
cluster_id: String,
extra_cluster_ids: HashSet<String>,
self_node: ClusterMember,
peer_seed_addrs: Vec<String>,
transport: &'a dyn Transport,
}

#[cfg(any(test, feature = "testsuite"))]
impl<'a> TestClusterBuilder<'a> {
pub fn new(node_id: NodeId, gossip_advertise_port: u16, transport: &'a dyn Transport) -> Self {
use quickwit_proto::indexing::PIPELINE_FULL_CAPACITY;
use quickwit_proto::ingest::ingester::IngesterStatus;

let gossip_advertise_addr: SocketAddr = ([127, 0, 0, 1], gossip_advertise_port).into();
Self {
cluster_id: "test-cluster".to_string(),
extra_cluster_ids: HashSet::new(),
self_node: ClusterMember {
node_id,
generation_id: crate::GenerationId(1),
is_ready: false,
enabled_services: HashSet::new(),
gossip_advertise_addr,
grpc_advertise_addr: grpc_addr_from_listen_addr_for_test(gossip_advertise_addr),
indexing_tasks: Vec::new(),
indexing_cpu_capacity: PIPELINE_FULL_CAPACITY,
ingester_status: IngesterStatus::default(),
availability_zone: None,
enable_standalone_compactors: false,
},
peer_seed_addrs: Vec::new(),
transport,
}
}

pub fn with_cluster_id(mut self, cluster_id: impl Into<String>) -> Self {
self.cluster_id = cluster_id.into();
self
}

pub fn with_extra_cluster_ids(mut self, cluster_ids: impl IntoIterator<Item = String>) -> Self {
self.extra_cluster_ids = cluster_ids.into_iter().collect();
self
}

pub fn with_peer_seeds(mut self, peer_seed_addrs: Vec<String>) -> Self {
self.peer_seed_addrs = peer_seed_addrs;
self
}

pub fn with_services(
mut self,
services: HashSet<quickwit_config::service::QuickwitService>,
) -> Self {
self.self_node.enabled_services = services;
self
}

pub fn with_readiness(mut self, is_ready: bool) -> Self {
self.self_node.is_ready = is_ready;
self
}

pub async fn build(self) -> anyhow::Result<Cluster> {
let gossip_advertise_addr = self.self_node.gossip_advertise_addr;
let is_ready = self.self_node.is_ready;
let cluster = Cluster::join(
self.cluster_id,
self.extra_cluster_ids,
self.self_node,
gossip_advertise_addr,
self.peer_seed_addrs,
Duration::from_millis(25),
ProtocolVersion::V0.to_code(),
create_failure_detector_config_for_test(),
self.transport,
crate::change::for_test::channel_factory_for_test(),
)
.await?;
cluster.set_self_node_readiness(is_ready).await;
Ok(cluster)
}
}

/// Creates a failure detector config for tests.
Expand Down Expand Up @@ -820,6 +891,35 @@ mod tests {
use super::*;
use crate::ChitchatTransport;

#[tokio::test]
async fn test_extra_cluster_ids_keep_old_and_new_nodes_in_one_cluster() -> anyhow::Result<()> {
let transport = ChitchatTransport::default();
let old_cluster = TestClusterBuilder::new(NodeId::from_str("old-node"), 31_001, &transport)
.with_cluster_id("old-cluster")
.with_extra_cluster_ids(["new-cluster".to_string()])
.with_readiness(true)
.build()
.await?;
let new_cluster = TestClusterBuilder::new(NodeId::from_str("new-node"), 31_003, &transport)
.with_cluster_id("new-cluster")
.with_extra_cluster_ids(["old-cluster".to_string()])
.with_peer_seeds(vec![old_cluster.gossip_listen_addr.to_string()])
.with_readiness(true)
.build()
.await?;

let wait_duration = Duration::from_secs(10);
old_cluster
.wait_for_ready_members(|members| members.len() == 2, wait_duration)
.await?;
new_cluster
.wait_for_ready_members(|members| members.len() == 2, wait_duration)
.await?;
assert_eq!(old_cluster.cluster_id(), "old-cluster");
assert_eq!(new_cluster.cluster_id(), "new-cluster");
Ok(())
}

#[test]
fn test_max_gossip_protocol_version_matches_chitchat() {
// Keep this match exhaustive: when Chitchat adds a protocol version, compilation should
Expand Down
75 changes: 73 additions & 2 deletions quickwit/quickwit-cluster/src/grpc_gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ async fn perform_grpc_gossip_rounds<ClusterServiceClientFactory, Fut>(
warn!("failed to fetch cluster state from node `{node_id}`");
continue;
};
if response.cluster_id != cluster_id {
warn!(
expected_cluster_id=%cluster_id,
response_cluster_id=%response.cluster_id,
"received cluster state for an unexpected cluster"
);
continue;
}
GRPC_GOSSIP_ROUNDS_TOTAL.inc();

let mut chitchat_guard = chitchat.lock().await;
Expand Down Expand Up @@ -273,8 +281,9 @@ mod tests {
let mut mock_cluster_service = MockClusterService::new();
mock_cluster_service
.expect_fetch_cluster_state()
.returning(|_request| {
.returning(|request| {
let response = FetchClusterStateResponse {
cluster_id: request.cluster_id,
node_states: vec![ProtoNodeState {
chitchat_id: Some(ProtoChitchatId {
node_id: "node-4".to_string(),
Expand All @@ -291,7 +300,6 @@ mod tests {
max_version: 2,
last_gc_version: 1,
}],
..Default::default()
};
Ok(response)
});
Expand Down Expand Up @@ -347,4 +355,67 @@ mod tests {
assert_eq!(node_state.max_version(), 2);
assert_eq!(node_state.last_gc_version(), 1);
}

#[tokio::test]
async fn test_perform_grpc_gossip_rounds_rejects_wrong_cluster_response() {
let transport = ChitchatTransport::default();
let cluster = create_cluster_for_test(Vec::new(), &["indexer"], &transport, true)
.await
.unwrap();
let cluster_id = cluster.cluster_id().to_string();
let self_chitchat_id = cluster.self_chitchat_id();
let chitchat = cluster.chitchat().await;

let grpc_client_factory = |_: SocketAddr| {
Box::pin(async {
let mut mock_cluster_service = MockClusterService::new();
mock_cluster_service
.expect_fetch_cluster_state()
.returning(|_request| {
Ok(FetchClusterStateResponse {
cluster_id: "wrong-cluster".to_string(),
node_states: vec![ProtoNodeState {
chitchat_id: Some(ProtoChitchatId {
node_id: "foreign-node".to_string(),
generation_id: 0,
gossip_advertise_addr: "127.0.0.1:14000".to_string(),
}),
key_values: vec![VersionedKeyValue {
key: "foo".to_string(),
value: "bar".to_string(),
version: 1,
status: DeletionStatus::Set as i32,
}],
max_version: 1,
last_gc_version: 0,
}],
})
});
ClusterServiceClient::from_mock(mock_cluster_service)
})
};
let candidate_id = ChitchatId::for_local_test(11_000);
let mut candidate_state = NodeState::for_test();
candidate_state.set(GRPC_ADVERTISE_ADDR_KEY, "127.0.0.1:11001");
candidate_state.set(READINESS_KEY, READINESS_VALUE_READY);
let (_live_nodes_tx, live_nodes_rx) =
watch::channel(BTreeMap::from_iter([(candidate_id, candidate_state)]));

perform_grpc_gossip_rounds(
cluster_id,
self_chitchat_id,
chitchat.clone(),
live_nodes_rx,
grpc_client_factory,
)
.await;

let chitchat_guard = chitchat.lock().await;
let foreign_id = ChitchatId {
node_id: Arc::from("foreign-node"),
generation_id: 0,
gossip_advertise_addr: "127.0.0.1:14000".parse().unwrap(),
};
assert!(chitchat_guard.node_state(&foreign_id).is_none());
}
}
Loading
Loading