You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by hg...@apache.org on 2025/11/24 10:51:25 UTC
(iggy) branch master updated: feat(cluster): add full transport endpoints to cluster configuration (#2393)
This is an automated email from the ASF dual-hosted git repository.
hgruszecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git
The following commit(s) were added to refs/heads/master by this push:
new 573e4f106 feat(cluster): add full transport endpoints to cluster configuration (#2393)
573e4f106 is described below
commit 573e4f106e0208d9d5d74a619f0759c1eb1ddb8c
Author: Hubert Gruszecki <h....@gmail.com>
AuthorDate: Mon Nov 24 11:51:22 2025 +0100
feat(cluster): add full transport endpoints to cluster configuration (#2393)
BREAKING CHANGE: ClusterNode now uses TransportEndpoints instead of
single address
- Add TransportEndpoints struct with TCP, QUIC, HTTP, WebSocket
addresses
- Restructure cluster config: current node (name only) + other nodes
(full details)
- Current node derives ports from main transport configs to avoid
duplication
- Update SDK leader detection to use appropriate transport endpoint
- Fix integration tests for new configuration structure
This enables cluster nodes to have complete information about all
transport endpoints of other nodes, supporting multi-protocol cluster
communication.
---
Cargo.lock | 18 +-
Cargo.toml | 8 +-
DEPENDENCIES.md | 18 +-
bdd/docker-compose.yml | 44 +-
bdd/rust/tests/helpers/cluster.rs | 10 +-
bdd/rust/tests/steps/leader_redirection.rs | 24 +-
core/ai/mcp/Cargo.toml | 2 +-
core/bench/Cargo.toml | 2 +-
core/bench/dashboard/server/Cargo.toml | 2 +-
core/binary_protocol/Cargo.toml | 2 +-
core/cli/Cargo.toml | 2 +-
core/common/Cargo.toml | 2 +-
core/common/src/types/cluster/metadata.rs | 59 +-
core/common/src/types/cluster/mod.rs | 2 +
core/common/src/types/cluster/node.rs | 54 +-
.../src/types/cluster/transport_endpoints.rs | 118 ++++
core/common/src/utils/byte_size.rs | 45 +-
core/configs/server.toml | 43 +-
core/connectors/runtime/Cargo.toml | 2 +-
core/integration/tests/config_provider/mod.rs | 617 ++++++++++++++-------
core/integration/tests/mcp/mod.rs | 15 +-
core/sdk/Cargo.toml | 2 +-
core/sdk/src/leader_aware.rs | 45 +-
core/sdk/src/prelude.rs | 6 +-
core/sdk/src/quic/quic_client.rs | 28 +-
core/sdk/src/tcp/tcp_client.rs | 14 +-
core/sdk/src/websocket/websocket_client.rs | 7 +-
core/server/Cargo.toml | 2 +-
core/server/src/configs/cluster.rs | 27 +-
core/server/src/configs/config_provider.rs | 34 +-
core/server/src/configs/defaults.rs | 38 +-
core/server/src/configs/validators.rs | 101 ++--
core/server/src/shard/system/cluster.rs | 163 ++++--
core/server/src/streaming/systems/cluster/mod.rs | 73 ---
core/server/src/streaming/utils/address.rs | 76 +++
core/server/src/streaming/utils/mod.rs | 1 +
.../csharp/Iggy_SDK/Contracts/ClusterMetadata.cs | 12 -
foreign/csharp/Iggy_SDK/Contracts/ClusterNode.cs | 16 +-
.../{ClusterMetadata.cs => TransportEndpoints.cs} | 22 +-
.../IggyClient/Implementations/TcpMessageStream.cs | 15 +-
foreign/csharp/Iggy_SDK/Iggy_SDK.csproj | 2 +-
foreign/csharp/Iggy_SDK/Mappers/BinaryMapper.cs | 40 +-
foreign/java/gradle.properties | 2 +-
foreign/node/package-lock.json | 2 +-
foreign/node/package.json | 2 +-
foreign/node/src/e2e/tcp.cluster.e2e.ts | 20 +-
foreign/node/src/wire/cluster/cluster.type.ts | 3 +-
foreign/node/src/wire/cluster/cluster.utils.ts | 79 +--
foreign/python/Cargo.toml | 4 +-
foreign/python/pyproject.toml | 2 +-
web/package.json | 2 +-
51 files changed, 1187 insertions(+), 742 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 59d631860..76612eb86 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4607,7 +4607,7 @@ dependencies = [
[[package]]
name = "iggy"
-version = "0.8.0"
+version = "0.8.0-edge.6"
dependencies = [
"async-broadcast",
"async-dropper",
@@ -4639,7 +4639,7 @@ dependencies = [
[[package]]
name = "iggy-bench"
-version = "0.3.0"
+version = "0.3.0-edge.4"
dependencies = [
"async-trait",
"bench-report",
@@ -4669,7 +4669,7 @@ dependencies = [
[[package]]
name = "iggy-bench-dashboard-server"
-version = "0.5.0"
+version = "0.5.0-edge.5"
dependencies = [
"actix-cors",
"actix-files",
@@ -4696,7 +4696,7 @@ dependencies = [
[[package]]
name = "iggy-cli"
-version = "0.10.0"
+version = "0.10.0-edge.4"
dependencies = [
"ahash 0.8.12",
"anyhow",
@@ -4716,7 +4716,7 @@ dependencies = [
[[package]]
name = "iggy-connectors"
-version = "0.2.0"
+version = "0.2.0-edge.4"
dependencies = [
"async-trait",
"axum",
@@ -4749,7 +4749,7 @@ dependencies = [
[[package]]
name = "iggy-mcp"
-version = "0.2.0"
+version = "0.2.0-edge.4"
dependencies = [
"axum",
"axum-server",
@@ -4771,7 +4771,7 @@ dependencies = [
[[package]]
name = "iggy_binary_protocol"
-version = "0.8.0"
+version = "0.8.0-edge.6"
dependencies = [
"anyhow",
"async-broadcast",
@@ -4792,7 +4792,7 @@ dependencies = [
[[package]]
name = "iggy_common"
-version = "0.8.0"
+version = "0.8.0-edge.6"
dependencies = [
"aes-gcm",
"ahash 0.8.12",
@@ -8349,7 +8349,7 @@ dependencies = [
[[package]]
name = "server"
-version = "0.6.0"
+version = "0.6.0-edge.6"
dependencies = [
"ahash 0.8.12",
"anyhow",
diff --git a/Cargo.toml b/Cargo.toml
index f598515fd..ddf1057c4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -128,10 +128,10 @@ human-repr = "1.1.0"
humantime = "2.3.0"
iceberg = "=0.6.0"
iceberg-catalog-rest = "=0.6.0"
-iggy = { path = "core/sdk", version = "0.8.0" }
-iggy_binary_protocol = { path = "core/binary_protocol", version = "0.8.0" }
-iggy_common = { path = "core/common", version = "0.8.0" }
-iggy_connector_sdk = { path = "core/connectors/sdk", version = "0.1.0" }
+iggy = { path = "core/sdk", version = "0.8.0-edge.6" }
+iggy_binary_protocol = { path = "core/binary_protocol", version = "0.8.0-edge.6" }
+iggy_common = { path = "core/common", version = "0.8.0-edge.6" }
+iggy_connector_sdk = { path = "core/connectors/sdk", version = "0.1.0-edge.4" }
integration = { path = "core/integration" }
keyring = { version = "3.6.3", features = ["sync-secret-service", "vendored"] }
lazy_static = "1.5.0"
diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md
index 4314f3ed2..ac6e79033 100644
--- a/DEPENDENCIES.md
+++ b/DEPENDENCIES.md
@@ -403,14 +403,14 @@ icu_provider: 2.1.1, "Unicode-3.0",
ident_case: 1.0.1, "Apache-2.0 OR MIT",
idna: 1.1.0, "Apache-2.0 OR MIT",
idna_adapter: 1.2.1, "Apache-2.0 OR MIT",
-iggy: 0.8.0, "Apache-2.0",
-iggy-bench: 0.3.0, "Apache-2.0",
-iggy-bench-dashboard-server: 0.5.0, "Apache-2.0",
-iggy-cli: 0.10.0, "Apache-2.0",
-iggy-connectors: 0.2.0, "Apache-2.0",
-iggy-mcp: 0.2.0, "Apache-2.0",
-iggy_binary_protocol: 0.8.0, "Apache-2.0",
-iggy_common: 0.8.0, "Apache-2.0",
+iggy: 0.8.0-edge.6, "Apache-2.0",
+iggy-bench: 0.3.0-edge.4, "Apache-2.0",
+iggy-bench-dashboard-server: 0.5.0-edge.5, "Apache-2.0",
+iggy-cli: 0.10.0-edge.4, "Apache-2.0",
+iggy-connectors: 0.2.0-edge.4, "Apache-2.0",
+iggy-mcp: 0.2.0-edge.4, "Apache-2.0",
+iggy_binary_protocol: 0.8.0-edge.6, "Apache-2.0",
+iggy_common: 0.8.0-edge.6, "Apache-2.0",
iggy_connector_elasticsearch_sink: 0.1.0, "Apache-2.0",
iggy_connector_elasticsearch_source: 0.1.0, "Apache-2.0",
iggy_connector_iceberg_sink: 0.1.0, "Apache-2.0",
@@ -733,7 +733,7 @@ serde_with_macros: 3.16.0, "Apache-2.0 OR MIT",
serde_yaml_ng: 0.10.0, "MIT",
serial_test: 3.2.0, "MIT",
serial_test_derive: 3.2.0, "MIT",
-server: 0.6.0, "Apache-2.0",
+server: 0.6.0-edge.6, "Apache-2.0",
sha1: 0.10.6, "Apache-2.0 OR MIT",
sha2: 0.10.9, "Apache-2.0 OR MIT",
sharded-slab: 0.1.7, "MIT",
diff --git a/bdd/docker-compose.yml b/bdd/docker-compose.yml
index b9469dd31..fd52d5867 100644
--- a/bdd/docker-compose.yml
+++ b/bdd/docker-compose.yml
@@ -95,18 +95,16 @@ services:
- IGGY_CLUSTER_ENABLED=true
- IGGY_CLUSTER_NAME=test-cluster
- IGGY_CLUSTER_ID=1
- - IGGY_CLUSTER_TRANSPORT=tcp
- # This node's identity
- - IGGY_CLUSTER_NODE_ID=0
- - IGGY_CLUSTER_NODE_NAME=leader-node
- - IGGY_CLUSTER_NODE_ADDRESS=iggy-leader:8091
- # Cluster nodes configuration (indexed format for array)
- - IGGY_CLUSTER_NODES_0_ID=0
- - IGGY_CLUSTER_NODES_0_NAME=leader-node
- - IGGY_CLUSTER_NODES_0_ADDRESS=iggy-leader:8091
- - IGGY_CLUSTER_NODES_1_ID=1
- - IGGY_CLUSTER_NODES_1_NAME=follower-node
- - IGGY_CLUSTER_NODES_1_ADDRESS=iggy-follower:8092
+ # Current node identity
+ - IGGY_CLUSTER_NODE_CURRENT_NAME=leader-node
+ - IGGY_CLUSTER_NODE_CURRENT_IP=iggy-leader
+ # Other nodes configuration
+ - IGGY_CLUSTER_NODE_OTHERS_0_NAME=follower-node
+ - IGGY_CLUSTER_NODE_OTHERS_0_IP=iggy-follower
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_TCP=8092
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_QUIC=8082
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_HTTP=3002
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_WEBSOCKET=8072
volumes:
- iggy_leader_data:/app/local_data_leader
networks:
@@ -152,18 +150,16 @@ services:
- IGGY_CLUSTER_ENABLED=true
- IGGY_CLUSTER_NAME=test-cluster
- IGGY_CLUSTER_ID=1
- - IGGY_CLUSTER_TRANSPORT=tcp
- # This node's identity (different from leader)
- - IGGY_CLUSTER_NODE_ID=1
- - IGGY_CLUSTER_NODE_NAME=follower-node
- - IGGY_CLUSTER_NODE_ADDRESS=iggy-follower:8092
- # Cluster nodes configuration (indexed format for array)
- - IGGY_CLUSTER_NODES_0_ID=0
- - IGGY_CLUSTER_NODES_0_NAME=leader-node
- - IGGY_CLUSTER_NODES_0_ADDRESS=iggy-leader:8091
- - IGGY_CLUSTER_NODES_1_ID=1
- - IGGY_CLUSTER_NODES_1_NAME=follower-node
- - IGGY_CLUSTER_NODES_1_ADDRESS=iggy-follower:8092
+ # Current node identity (different from leader)
+ - IGGY_CLUSTER_NODE_CURRENT_NAME=follower-node
+ - IGGY_CLUSTER_NODE_CURRENT_IP=iggy-follower
+ # Other nodes configuration
+ - IGGY_CLUSTER_NODE_OTHERS_0_NAME=leader-node
+ - IGGY_CLUSTER_NODE_OTHERS_0_IP=iggy-leader
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_TCP=8091
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_QUIC=8081
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_HTTP=3001
+ - IGGY_CLUSTER_NODE_OTHERS_0_PORTS_WEBSOCKET=8071
volumes:
- iggy_follower_data:/app/local_data_follower
networks:
diff --git a/bdd/rust/tests/helpers/cluster.rs b/bdd/rust/tests/helpers/cluster.rs
index 71ef991af..b58c05be9 100644
--- a/bdd/rust/tests/helpers/cluster.rs
+++ b/bdd/rust/tests/helpers/cluster.rs
@@ -112,7 +112,7 @@ pub fn update_node_role(
) -> bool {
if let Some(node) = nodes
.iter_mut()
- .find(|n| n.id == node_id && n.address.ends_with(&format!(":{}", port)))
+ .find(|n| n.name == format!("node-{}", node_id) && n.endpoints.tcp == port)
{
node.role = role;
node.status = ClusterNodeStatus::Healthy;
@@ -122,14 +122,6 @@ pub fn update_node_role(
}
}
-/// Extracts port number from an address string
-pub fn extract_port_from_address(address: &str) -> Option<u16> {
- address
- .rsplit(':')
- .next()
- .and_then(|port_str| port_str.parse().ok())
-}
-
/// Determines server type from port number
pub fn server_type_from_port(port: u16) -> &'static str {
match port {
diff --git a/bdd/rust/tests/steps/leader_redirection.rs b/bdd/rust/tests/steps/leader_redirection.rs
index 7d484ff3d..20c36af7e 100644
--- a/bdd/rust/tests/steps/leader_redirection.rs
+++ b/bdd/rust/tests/steps/leader_redirection.rs
@@ -36,10 +36,21 @@ async fn given_cluster_config(world: &mut LeaderContext, node_count: usize) {
#[given(regex = r"^node (\d+) is configured on port (\d+)$")]
async fn given_node_configured(world: &mut LeaderContext, node_id: u32, port: u16) {
+ let (quic_port, http_port, ws_port) = match port {
+ 8091 => (8081, 3001, 8071), // Leader ports
+ 8092 => (8082, 3002, 8072), // Follower ports
+ _ => (port - 10, port - 5090, port - 20), // Default mapping
+ };
+
let node = ClusterNode {
- id: node_id,
name: format!("node-{}", node_id),
- address: format!("iggy-server:{}", port),
+ ip: "iggy-server".to_string(),
+ endpoints: TransportEndpoints::new(
+ port, // TCP port
+ quic_port, // QUIC port
+ http_port, // HTTP port
+ ws_port, // WebSocket port
+ ),
role: ClusterNodeRole::Follower,
status: ClusterNodeStatus::Healthy,
};
@@ -196,7 +207,7 @@ async fn then_verify_client_port(world: &mut LeaderContext, expected_port: u16)
// Check cluster metadata if available
if let Ok(Some(leader)) = cluster::verify_leader_in_metadata(client).await {
// If we found a leader and we're connected to the leader port, mark redirection
- if cluster::extract_port_from_address(&leader.address) == Some(expected_port) {
+ if leader.endpoints.tcp == expected_port {
world.test_state.redirection_occurred = true;
}
}
@@ -223,8 +234,8 @@ async fn then_verify_named_client_port(
if let Ok(Some(leader)) = cluster::verify_leader_in_metadata(client).await {
assert!(
- cluster::extract_port_from_address(&leader.address).is_some(),
- "Client {} should find valid leader in cluster metadata",
+ leader.endpoints.tcp > 0,
+ "Client {} should find valid leader TCP port in cluster metadata",
client_name
);
}
@@ -298,7 +309,8 @@ async fn then_both_use_same_server(world: &mut LeaderContext) {
cluster::verify_leader_in_metadata(client_b).await,
) {
assert_eq!(
- leader_a.address, leader_b.address,
+ format!("{}:{}", leader_a.ip, leader_a.endpoints.tcp),
+ format!("{}:{}", leader_b.ip, leader_b.endpoints.tcp),
"Both clients should see the same leader"
);
}
diff --git a/core/ai/mcp/Cargo.toml b/core/ai/mcp/Cargo.toml
index b6432de4e..6fd58436c 100644
--- a/core/ai/mcp/Cargo.toml
+++ b/core/ai/mcp/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "iggy-mcp"
-version = "0.2.0"
+version = "0.2.0-edge.4"
description = "MCP Server for Iggy message streaming platform"
edition = "2024"
license = "Apache-2.0"
diff --git a/core/bench/Cargo.toml b/core/bench/Cargo.toml
index 2557e0b47..e2c2a46d1 100644
--- a/core/bench/Cargo.toml
+++ b/core/bench/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "iggy-bench"
-version = "0.3.0"
+version = "0.3.0-edge.4"
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/apache/iggy"
diff --git a/core/bench/dashboard/server/Cargo.toml b/core/bench/dashboard/server/Cargo.toml
index 8d7ca08db..2e34186de 100644
--- a/core/bench/dashboard/server/Cargo.toml
+++ b/core/bench/dashboard/server/Cargo.toml
@@ -18,7 +18,7 @@
[package]
name = "iggy-bench-dashboard-server"
license = "Apache-2.0"
-version = "0.5.0"
+version = "0.5.0-edge.5"
edition = "2024"
[dependencies]
diff --git a/core/binary_protocol/Cargo.toml b/core/binary_protocol/Cargo.toml
index c8fd2c7cd..3cabe2625 100644
--- a/core/binary_protocol/Cargo.toml
+++ b/core/binary_protocol/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "iggy_binary_protocol"
-version = "0.8.0"
+version = "0.8.0-edge.6"
description = "Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second."
edition = "2024"
license = "Apache-2.0"
diff --git a/core/cli/Cargo.toml b/core/cli/Cargo.toml
index 4d8b74248..2c3c64dc9 100644
--- a/core/cli/Cargo.toml
+++ b/core/cli/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "iggy-cli"
-version = "0.10.0"
+version = "0.10.0-edge.4"
edition = "2024"
authors = ["bartosz.ciesla@gmail.com"]
repository = "https://github.com/apache/iggy"
diff --git a/core/common/Cargo.toml b/core/common/Cargo.toml
index 78ab51e6c..0ccc279bf 100644
--- a/core/common/Cargo.toml
+++ b/core/common/Cargo.toml
@@ -16,7 +16,7 @@
# under the License.
[package]
name = "iggy_common"
-version = "0.8.0"
+version = "0.8.0-edge.6"
description = "Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second."
edition = "2024"
license = "Apache-2.0"
diff --git a/core/common/src/types/cluster/metadata.rs b/core/common/src/types/cluster/metadata.rs
index c89e94084..f00f6b7e5 100644
--- a/core/common/src/types/cluster/metadata.rs
+++ b/core/common/src/types/cluster/metadata.rs
@@ -16,7 +16,7 @@
* under the License.
*/
-use crate::{BytesSerializable, IggyError, TransportProtocol, types::cluster::node::ClusterNode};
+use crate::{BytesSerializable, IggyError, types::cluster::node::ClusterNode};
use bytes::{BufMut, Bytes, BytesMut};
use serde::{Deserialize, Serialize};
use std::fmt::Display;
@@ -26,23 +26,17 @@ use std::fmt::Display;
pub struct ClusterMetadata {
/// Name of the cluster.
pub name: String,
- /// Unique identifier of the cluster.
- pub id: u32,
- /// Transport used for cluster communication (for binary protocol it's u8, 1=TCP, 2=QUIC, 3=HTTP).
- /// For HTTP it's a string "tcp", "quic", "http".
- pub transport: TransportProtocol,
- /// List of all nodes in the cluster.
+ /// List of all nodes in the cluster with their transport endpoints.
pub nodes: Vec<ClusterNode>,
}
impl BytesSerializable for ClusterMetadata {
fn to_bytes(&self) -> Bytes {
let name_bytes = self.name.as_bytes();
- let transport = self.transport as u8;
// Calculate size for each node
let nodes_size: usize = self.nodes.iter().map(|node| node.get_buffer_size()).sum();
- let size = 4 + name_bytes.len() + 4 + 1 + 4 + nodes_size; // name_len + name + id + transport + nodes_len + nodes
+ let size = 4 + name_bytes.len() + 4 + nodes_size; // name_len + name + nodes_len + nodes
let mut bytes = BytesMut::with_capacity(size);
@@ -50,12 +44,6 @@ impl BytesSerializable for ClusterMetadata {
bytes.put_u32_le(name_bytes.len() as u32);
bytes.put_slice(name_bytes);
- // Write cluster id
- bytes.put_u32_le(self.id);
-
- // Write transport
- bytes.put_u8(transport);
-
// Write nodes count
bytes.put_u32_le(self.nodes.len() as u32);
@@ -68,7 +56,7 @@ impl BytesSerializable for ClusterMetadata {
}
fn from_bytes(bytes: Bytes) -> Result<ClusterMetadata, IggyError> {
- if bytes.len() < 12 {
+ if bytes.len() < 8 {
return Err(IggyError::InvalidCommand);
}
@@ -90,25 +78,6 @@ impl BytesSerializable for ClusterMetadata {
.map_err(|_| IggyError::InvalidCommand)?;
position += name_len;
- // Read cluster id
- if bytes.len() < position + 4 {
- return Err(IggyError::InvalidCommand);
- }
- let id = u32::from_le_bytes(
- bytes[position..position + 4]
- .try_into()
- .map_err(|_| IggyError::InvalidNumberEncoding)?,
- );
- position += 4;
-
- // Read transport
- if bytes.len() < position + 1 {
- return Err(IggyError::InvalidCommand);
- }
- let transport_byte = bytes[position];
- let transport = TransportProtocol::try_from(transport_byte)?;
- position += 1;
-
// Read nodes count
if bytes.len() < position + 4 {
return Err(IggyError::InvalidCommand);
@@ -128,28 +97,16 @@ impl BytesSerializable for ClusterMetadata {
nodes.push(node);
}
- Ok(ClusterMetadata {
- name,
- id,
- transport,
- nodes,
- })
+ Ok(ClusterMetadata { name, nodes })
}
fn write_to_buffer(&self, buf: &mut BytesMut) {
let name_bytes = self.name.as_bytes();
- let transport = self.transport as u8;
// Write name length and name
buf.put_u32_le(name_bytes.len() as u32);
buf.put_slice(name_bytes);
- // Write cluster id
- buf.put_u32_le(self.id);
-
- // Write transport as u8
- buf.put_u8(transport);
-
// Write nodes count
buf.put_u32_le(self.nodes.len() as u32);
@@ -161,7 +118,7 @@ impl BytesSerializable for ClusterMetadata {
fn get_buffer_size(&self) -> usize {
let nodes_size: usize = self.nodes.iter().map(|node| node.get_buffer_size()).sum();
- 4 + self.name.len() + 4 + 1 + 4 + nodes_size // name_len + name + id + transport + nodes_len + nodes
+ 4 + self.name.len() + 4 + nodes_size // name_len + name + nodes_len + nodes
}
}
@@ -175,8 +132,8 @@ impl Display for ClusterMetadata {
write!(
f,
- "ClusterMetadata {{ name: {}, id: {}, transport: {}, nodes: {:?} }}",
- self.name, self.id, self.transport, nodes
+ "ClusterMetadata {{ name: {}, nodes: {:?} }}",
+ self.name, nodes
)
}
}
diff --git a/core/common/src/types/cluster/mod.rs b/core/common/src/types/cluster/mod.rs
index 7573d89be..3215bb9c5 100644
--- a/core/common/src/types/cluster/mod.rs
+++ b/core/common/src/types/cluster/mod.rs
@@ -20,8 +20,10 @@ mod metadata;
mod node;
mod role;
mod status;
+mod transport_endpoints;
pub use metadata::ClusterMetadata;
pub use node::ClusterNode;
pub use role::ClusterNodeRole;
pub use status::ClusterNodeStatus;
+pub use transport_endpoints::TransportEndpoints;
diff --git a/core/common/src/types/cluster/node.rs b/core/common/src/types/cluster/node.rs
index aa2308040..63c2dad1d 100644
--- a/core/common/src/types/cluster/node.rs
+++ b/core/common/src/types/cluster/node.rs
@@ -18,7 +18,9 @@
use crate::{
BytesSerializable, IggyError,
- types::cluster::{role::ClusterNodeRole, status::ClusterNodeStatus},
+ types::cluster::{
+ role::ClusterNodeRole, status::ClusterNodeStatus, transport_endpoints::TransportEndpoints,
+ },
};
use bytes::{BufMut, Bytes, BytesMut};
use serde::{Deserialize, Serialize};
@@ -26,9 +28,9 @@ use std::fmt::Display;
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ClusterNode {
- pub id: u32,
pub name: String,
- pub address: String,
+ pub ip: String,
+ pub endpoints: TransportEndpoints,
pub role: ClusterNodeRole,
pub status: ClusterNodeStatus,
}
@@ -43,20 +45,12 @@ impl BytesSerializable for ClusterNode {
fn from_bytes(bytes: Bytes) -> Result<Self, IggyError> {
if bytes.len() < 10 {
- // Minimum: 4 (id) + 4 (name_len) + 4 (address_len) + 1 (role) + 1 (status)
+ // Minimum: 4 (name_len) + 4 (ip_len) + 1 (role) + 1 (status)
return Err(IggyError::InvalidCommand);
}
let mut position = 0;
- // Read id
- let id = u32::from_le_bytes(
- bytes[position..position + 4]
- .try_into()
- .map_err(|_| IggyError::InvalidNumberEncoding)?,
- );
- position += 4;
-
// Read name length
let name_len = u32::from_le_bytes(
bytes[position..position + 4]
@@ -73,24 +67,26 @@ impl BytesSerializable for ClusterNode {
.map_err(|_| IggyError::InvalidCommand)?;
position += name_len;
- // Read address length
- if bytes.len() < position + 4 {
- return Err(IggyError::InvalidCommand);
- }
- let address_len = u32::from_le_bytes(
+ // Read IP length
+ let ip_len = u32::from_le_bytes(
bytes[position..position + 4]
.try_into()
.map_err(|_| IggyError::InvalidNumberEncoding)?,
) as usize;
position += 4;
- // Read address
- if bytes.len() < position + address_len {
+ // Read IP
+ if bytes.len() < position + ip_len {
return Err(IggyError::InvalidCommand);
}
- let address = String::from_utf8(bytes[position..position + address_len].to_vec())
+ let ip = String::from_utf8(bytes[position..position + ip_len].to_vec())
.map_err(|_| IggyError::InvalidCommand)?;
- position += address_len;
+ position += ip_len;
+
+ // Read transport endpoints
+ let endpoints_bytes = bytes.slice(position..);
+ let endpoints = TransportEndpoints::from_bytes(endpoints_bytes)?;
+ position += endpoints.get_buffer_size();
// Read role
if bytes.len() < position + 1 {
@@ -106,26 +102,26 @@ impl BytesSerializable for ClusterNode {
let status = ClusterNodeStatus::try_from(bytes[position])?;
Ok(ClusterNode {
- id,
name,
- address,
+ ip,
+ endpoints,
role,
status,
})
}
fn write_to_buffer(&self, buf: &mut BytesMut) {
- buf.put_u32_le(self.id);
buf.put_u32_le(self.name.len() as u32);
buf.put_slice(self.name.as_bytes());
- buf.put_u32_le(self.address.len() as u32);
- buf.put_slice(self.address.as_bytes());
+ buf.put_u32_le(self.ip.len() as u32);
+ buf.put_slice(self.ip.as_bytes());
+ self.endpoints.write_to_buffer(buf);
self.role.write_to_buffer(buf);
self.status.write_to_buffer(buf);
}
fn get_buffer_size(&self) -> usize {
- 4 + 4 + self.name.len() + 4 + self.address.len() + 1 + 1 // id + name_len + name + address_len + address + role + status
+ 4 + self.name.len() + 4 + self.ip.len() + self.endpoints.get_buffer_size() + 1 + 1 // name_len + name + ip_len + ip + endpoints + role + status
}
}
@@ -133,8 +129,8 @@ impl Display for ClusterNode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
- "ClusterNode {{ id: {}, name: {}, address: {}, role: {}, status: {} }}",
- self.id, self.name, self.address, self.role, self.status
+ "ClusterNode {{ name: {}, ip: {}, endpoints: {}, role: {}, status: {} }}",
+ self.name, self.ip, self.endpoints, self.role, self.status
)
}
}
diff --git a/core/common/src/types/cluster/transport_endpoints.rs b/core/common/src/types/cluster/transport_endpoints.rs
new file mode 100644
index 000000000..e398f2b04
--- /dev/null
+++ b/core/common/src/types/cluster/transport_endpoints.rs
@@ -0,0 +1,118 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use crate::{BytesSerializable, IggyError};
+use bytes::{BufMut, Bytes, BytesMut};
+use serde::{Deserialize, Serialize};
+use std::fmt::Display;
+
+#[derive(Debug, Deserialize, Serialize, Clone)]
+pub struct TransportEndpoints {
+ pub tcp: u16,
+ pub quic: u16,
+ pub http: u16,
+ pub websocket: u16,
+}
+
+impl TransportEndpoints {
+ pub fn new(tcp: u16, quic: u16, http: u16, websocket: u16) -> Self {
+ Self {
+ tcp,
+ quic,
+ http,
+ websocket,
+ }
+ }
+}
+
+impl BytesSerializable for TransportEndpoints {
+ fn to_bytes(&self) -> Bytes {
+ let size = self.get_buffer_size();
+ let mut bytes = BytesMut::with_capacity(size);
+ self.write_to_buffer(&mut bytes);
+ bytes.freeze()
+ }
+
+ fn from_bytes(bytes: Bytes) -> Result<Self, IggyError> {
+ if bytes.len() < 8 {
+ // Minimum: 4 ports * 2 bytes each
+ return Err(IggyError::InvalidCommand);
+ }
+
+ let mut position = 0;
+
+ // Read TCP port
+ let tcp = u16::from_le_bytes(
+ bytes[position..position + 2]
+ .try_into()
+ .map_err(|_| IggyError::InvalidNumberEncoding)?,
+ );
+ position += 2;
+
+ // Read QUIC port
+ let quic = u16::from_le_bytes(
+ bytes[position..position + 2]
+ .try_into()
+ .map_err(|_| IggyError::InvalidNumberEncoding)?,
+ );
+ position += 2;
+
+ // Read HTTP port
+ let http = u16::from_le_bytes(
+ bytes[position..position + 2]
+ .try_into()
+ .map_err(|_| IggyError::InvalidNumberEncoding)?,
+ );
+ position += 2;
+
+ // Read WebSocket port
+ let websocket = u16::from_le_bytes(
+ bytes[position..position + 2]
+ .try_into()
+ .map_err(|_| IggyError::InvalidNumberEncoding)?,
+ );
+
+ Ok(TransportEndpoints {
+ tcp,
+ quic,
+ http,
+ websocket,
+ })
+ }
+
+ fn write_to_buffer(&self, buf: &mut BytesMut) {
+ buf.put_u16_le(self.tcp);
+ buf.put_u16_le(self.quic);
+ buf.put_u16_le(self.http);
+ buf.put_u16_le(self.websocket);
+ }
+
+ fn get_buffer_size(&self) -> usize {
+ 8 // 4 ports * 2 bytes each
+ }
+}
+
+impl Display for TransportEndpoints {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(
+ f,
+ "tcp: {}, quic: {}, http: {}, websocket: {}",
+ self.tcp, self.quic, self.http, self.websocket
+ )
+ }
+}
diff --git a/core/common/src/utils/byte_size.rs b/core/common/src/utils/byte_size.rs
index 13bb70098..2ccf58bee 100644
--- a/core/common/src/utils/byte_size.rs
+++ b/core/common/src/utils/byte_size.rs
@@ -20,7 +20,7 @@ use super::duration::IggyDuration;
use crate::IggyError;
use byte_unit::{Byte, UnitType};
use core::fmt;
-use serde::{Deserialize, Serialize};
+use serde::{Deserialize, Deserializer, Serialize};
use std::{
iter::Sum,
ops::{Add, AddAssign, Sub, SubAssign},
@@ -53,9 +53,50 @@ use std::{
/// assert_eq!("1.00 GB", size.as_human_string());
/// assert_eq!("1.00 GB", format!("{}", size));
/// ```
-#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, PartialEq, Serialize)]
pub struct IggyByteSize(Byte);
+impl<'de> Deserialize<'de> for IggyByteSize {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ use serde::de::{self, Visitor};
+
+ struct IggyByteSizeVisitor;
+
+ impl<'de> Visitor<'de> for IggyByteSizeVisitor {
+ type Value = IggyByteSize;
+
+ fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter
+ .write_str("a string like \"123KB\" or an unsigned integer representing bytes")
+ }
+
+ fn visit_u64<E>(self, value: u64) -> Result<IggyByteSize, E>
+ where
+ E: de::Error,
+ {
+ Ok(IggyByteSize::from(value))
+ }
+
+ fn visit_str<E>(self, value: &str) -> Result<IggyByteSize, E>
+ where
+ E: de::Error,
+ {
+ if let Ok(bytes) = value.parse::<u64>() {
+ return Ok(IggyByteSize::from(bytes));
+ }
+ Byte::from_str(value)
+ .map(IggyByteSize)
+ .map_err(|e| E::custom(format!("Failed to parse byte size: {}", e)))
+ }
+ }
+
+ deserializer.deserialize_any(IggyByteSizeVisitor)
+ }
+}
+
impl Default for IggyByteSize {
fn default() -> Self {
Self(Byte::from_u64(0))
diff --git a/core/configs/server.toml b/core/configs/server.toml
index 892c8cdbf..84c78aa22 100644
--- a/core/configs/server.toml
+++ b/core/configs/server.toml
@@ -509,35 +509,38 @@ bucket_capacity = 8192
# When enabled, this node will participate in the cluster and coordinate with other nodes.
enabled = false
-# Unique cluster identifier (u32).
-# All nodes in the same cluster must share the same cluster id.
-id = 0
-
# Unique cluster name (string).
# All nodes in the same cluster must share the same name.
# This prevents accidental cross-cluster communication.
name = "iggy-cluster"
-# Transport protocol used for communication between nodes in the cluster (string).
-# Supported values: "tcp", "quic", "ws"
-transport = "tcp"
-
# Current node configuration
-[cluster.node]
-# This node unique identifier within the cluster (u32).
-# Must be unique across all nodes and match one of the ids in the nodes list.
-id = 0
-
-# All nodes in the cluster.
-[[cluster.nodes]]
-id = 0
+[cluster.node.current]
+# Name of this node - must be unique across all nodes in the cluster
+# The node will use its configured transport addresses (tcp.address, quic.address, etc.)
name = "iggy-node-1"
-address = "127.0.0.1:8090"
+# IP address that other nodes should use to connect to this node
+ip = "127.0.0.1"
-[[cluster.nodes]]
-id = 1
+# Other nodes in the cluster
+# Each field in 'ports' is optional. If omitted, the current node's configured port will be used.
+# This is useful when all nodes use the same ports but different IPs, or when only some ports differ.
+[[cluster.node.others]]
name = "iggy-node-2"
-address = "127.0.0.1:8091"
+ip = "127.0.0.1"
+ports = { tcp = 8091, quic = 8081, http = 3001, websocket = 8093 }
+
+# [[cluster.node.others]]
+# name = "iggy-node-3"
+# ip = "192.168.1.100"
+# # Only some ports specified, others will use defaults from current node
+# ports = { tcp = 8092, http = 3002 }
+
+# Example with all default ports (uses current node's configured ports):
+# [[cluster.node.others]]
+# name = "iggy-node-4"
+# ip = "192.168.1.101"
+# ports = {} # Empty ports - all will use current node's defaults
# Sharding configuration
[system.sharding]
diff --git a/core/connectors/runtime/Cargo.toml b/core/connectors/runtime/Cargo.toml
index ceee9bb6e..146543cce 100644
--- a/core/connectors/runtime/Cargo.toml
+++ b/core/connectors/runtime/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "iggy-connectors"
-version = "0.2.0"
+version = "0.2.0-edge.4"
description = "Connectors runtime for Iggy message streaming platform"
edition = "2024"
license = "Apache-2.0"
diff --git a/core/integration/tests/config_provider/mod.rs b/core/integration/tests/config_provider/mod.rs
index 8b41411bf..882431747 100644
--- a/core/integration/tests/config_provider/mod.rs
+++ b/core/integration/tests/config_provider/mod.rs
@@ -16,59 +16,31 @@
* under the License.
*/
-use integration::file::{file_exists, get_root_path};
use serial_test::serial;
use server::configs::config_provider::{ConfigProvider, FileConfigProvider};
use std::env;
-async fn scenario_parsing_from_file(extension: &str) {
- let mut config_path = get_root_path().join("../configs/server");
- assert!(config_path.set_extension(extension), "Cannot set extension");
- let config_path = config_path.as_path().display().to_string();
- let config_provider = FileConfigProvider::new(config_path.clone());
- assert!(
- file_exists(&config_path),
- "Config file not found: {config_path}"
- );
- assert!(
- config_provider.load_config().await.is_ok(),
- "ConfigProvider failed to parse config from {config_path}"
- );
-}
+use integration::file::get_root_path;
-#[compio::test]
-async fn validate_server_config_toml_from_repository() {
- scenario_parsing_from_file("toml").await;
-}
-
-// This test needs to be run in serial because it modifies the environment variables
-// which are shared, since all tests run in parallel by default.
#[serial]
-#[compio::test]
-async fn validate_custom_env_provider() {
- let expected_datagram_send_buffer_size = "1.00 KB";
- let expected_quic_certificate_self_signed = false;
- let expected_http_enabled = false;
- let expected_tcp_enabled = "false";
- let expected_message_saver_enabled = false;
- let expected_message_expiry = "10s";
+#[tokio::test]
+async fn validate_config_env_override() {
+ let expected_http = true;
+ let expected_tcp = true;
+ let expected_message_saver = true;
+ let expected_message_expiry = "1s";
unsafe {
+ env::set_var("IGGY_HTTP_ENABLED", expected_http.to_string());
+ env::set_var("IGGY_TCP_ENABLED", expected_tcp.to_string());
env::set_var(
- "IGGY_QUIC_DATAGRAM_SEND_BUFFER_SIZE",
- expected_datagram_send_buffer_size,
- );
- env::set_var(
- "IGGY_QUIC_CERTIFICATE_SELF_SIGNED",
- expected_quic_certificate_self_signed.to_string(),
+ "IGGY_MESSAGE_SAVER_ENABLED",
+ expected_message_saver.to_string(),
);
- env::set_var("IGGY_HTTP_ENABLED", expected_http_enabled.to_string());
- env::set_var("IGGY_TCP_ENABLED", expected_tcp_enabled);
env::set_var(
- "IGGY_MESSAGE_SAVER_ENABLED",
- expected_message_saver_enabled.to_string(),
+ "IGGY_SYSTEM_SEGMENT_MESSAGE_EXPIRY",
+ expected_message_expiry,
);
- env::set_var("IGGY_SYSTEM_SEGMENT_MESSAGE_EXPIRY", "10s");
}
let config_path = get_root_path().join("../configs/server.toml");
@@ -76,76 +48,153 @@ async fn validate_custom_env_provider() {
let config = file_config_provider
.load_config()
.await
- .expect("Failed to load default server.toml config");
+ .expect("Failed to load server.toml config");
- assert_eq!(
- config.quic.datagram_send_buffer_size.to_string(),
- expected_datagram_send_buffer_size
- );
- assert_eq!(
- config.quic.certificate.self_signed,
- expected_quic_certificate_self_signed
- );
- assert_eq!(config.http.enabled, expected_http_enabled);
- assert_eq!(config.tcp.enabled.to_string(), expected_tcp_enabled);
- assert_eq!(config.message_saver.enabled, expected_message_saver_enabled);
+ assert_eq!(config.http.enabled, expected_http);
+ assert_eq!(config.tcp.enabled, expected_tcp);
+ assert_eq!(config.message_saver.enabled, expected_message_saver);
assert_eq!(
config.system.segment.message_expiry.to_string(),
expected_message_expiry
);
unsafe {
- env::remove_var("IGGY_QUIC_DATAGRAM_SEND_BUFFER_SIZE");
- env::remove_var("IGGY_QUIC_CERTIFICATE_SELF_SIGNED");
env::remove_var("IGGY_HTTP_ENABLED");
env::remove_var("IGGY_TCP_ENABLED");
env::remove_var("IGGY_MESSAGE_SAVER_ENABLED");
- env::remove_var("IGGY_SYSTEM_RETENTION_POLICY_MESSAGE_EXPIRY");
+ env::remove_var("IGGY_SYSTEM_SEGMENT_MESSAGE_EXPIRY");
}
}
-// Test for cluster configuration with environment variable overrides
+#[serial]
+#[tokio::test]
+async fn validate_socket_override() {
+ // Environment variables are set as raw byte counts
+ let send_buffer_bytes = 666666_u64;
+ let recv_buffer_bytes = 777777_u64;
+ unsafe {
+ env::set_var("IGGY_TCP_SOCKET_OVERRIDE_DEFAULTS", "true");
+ env::set_var(
+ "IGGY_TCP_SOCKET_SEND_BUFFER_SIZE",
+ send_buffer_bytes.to_string(),
+ );
+ env::set_var(
+ "IGGY_TCP_SOCKET_RECV_BUFFER_SIZE",
+ recv_buffer_bytes.to_string(),
+ );
+ }
+
+ let config_path = get_root_path().join("../configs/server.toml");
+ let file_config_provider = FileConfigProvider::new(config_path.as_path().display().to_string());
+ let config = file_config_provider
+ .load_config()
+ .await
+ .expect("Failed to load server.toml config with socket override");
+
+ assert!(config.tcp.socket.override_defaults);
+ // Verify the buffer sizes match the expected byte counts
+ assert_eq!(
+ config.tcp.socket.send_buffer_size.as_bytes_u64(),
+ send_buffer_bytes
+ );
+ assert_eq!(
+ config.tcp.socket.recv_buffer_size.as_bytes_u64(),
+ recv_buffer_bytes
+ );
+
+ unsafe {
+ env::remove_var("IGGY_TCP_SOCKET_OVERRIDE_DEFAULTS");
+ env::remove_var("IGGY_TCP_SOCKET_SEND_BUFFER_SIZE");
+ env::remove_var("IGGY_TCP_SOCKET_RECV_BUFFER_SIZE");
+ }
+}
+
+#[serial]
+#[tokio::test]
+async fn validate_socket_no_override() {
+ let config_path = get_root_path().join("../configs/server.toml");
+ let file_config_provider = FileConfigProvider::new(config_path.as_path().display().to_string());
+ let config = file_config_provider
+ .load_config()
+ .await
+ .expect("Failed to load server.toml config without socket override");
+
+ assert!(!config.tcp.socket.override_defaults);
+}
+
#[serial]
#[tokio::test]
async fn validate_cluster_config_env_override() {
// Test data for cluster configuration
let expected_cluster_enabled = true;
- let expected_cluster_id = 0;
let expected_cluster_name = "test-cluster";
- let expected_node_id = 0;
-
- // Test data for cluster nodes array
- let expected_node_0_id = 0;
- let expected_node_0_name = "test-node-1";
- let expected_node_0_address = "192.168.1.100:9090";
-
- let expected_node_1_id = 1;
- let expected_node_1_name = "test-node-2";
- let expected_node_1_address = "192.168.1.101:9091";
-
- let expected_node_2_id = 2;
- let expected_node_2_name = "test-node-3";
- let expected_node_2_address = "192.168.1.102:9092";
+ let expected_current_node_name = "test-node-1";
+
+ // Test data for other nodes in cluster
+ let expected_other_node_0_name = "test-node-2";
+ let expected_other_node_0_ip = "192.168.1.101";
+ let expected_other_node_0_tcp = 9091_u16;
+ let expected_other_node_0_quic = 9081_u16;
+ let expected_other_node_0_http = 4001_u16;
+ let expected_other_node_0_websocket = 9093_u16;
+
+ let expected_other_node_1_name = "test-node-3";
+ let expected_other_node_1_ip = "192.168.1.102";
+ let expected_other_node_1_tcp = 9092_u16;
+ let expected_other_node_1_quic = 9082_u16;
+ let expected_other_node_1_http = 4002_u16;
+ let expected_other_node_1_websocket = 9094_u16;
unsafe {
// Set cluster configuration environment variables
env::set_var("IGGY_CLUSTER_ENABLED", expected_cluster_enabled.to_string());
- env::set_var("IGGY_CLUSTER_ID", expected_cluster_id.to_string());
env::set_var("IGGY_CLUSTER_NAME", expected_cluster_name);
- env::set_var("IGGY_CLUSTER_NODE_ID", expected_node_id.to_string());
+ env::set_var("IGGY_CLUSTER_NODE_CURRENT_NAME", expected_current_node_name);
- // Set cluster nodes array environment variables
- env::set_var("IGGY_CLUSTER_NODES_0_ID", expected_node_0_id.to_string());
- env::set_var("IGGY_CLUSTER_NODES_0_NAME", expected_node_0_name);
- env::set_var("IGGY_CLUSTER_NODES_0_ADDRESS", expected_node_0_address);
-
- env::set_var("IGGY_CLUSTER_NODES_1_ID", expected_node_1_id.to_string());
- env::set_var("IGGY_CLUSTER_NODES_1_NAME", expected_node_1_name);
- env::set_var("IGGY_CLUSTER_NODES_1_ADDRESS", expected_node_1_address);
+ // Set other nodes array environment variables
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_NAME",
+ expected_other_node_0_name,
+ );
+ env::set_var("IGGY_CLUSTER_NODE_OTHERS_0_IP", expected_other_node_0_ip);
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_TCP",
+ expected_other_node_0_tcp.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_QUIC",
+ expected_other_node_0_quic.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_HTTP",
+ expected_other_node_0_http.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_WEBSOCKET",
+ expected_other_node_0_websocket.to_string(),
+ );
- env::set_var("IGGY_CLUSTER_NODES_2_ID", expected_node_2_id.to_string());
- env::set_var("IGGY_CLUSTER_NODES_2_NAME", expected_node_2_name);
- env::set_var("IGGY_CLUSTER_NODES_2_ADDRESS", expected_node_2_address);
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_NAME",
+ expected_other_node_1_name,
+ );
+ env::set_var("IGGY_CLUSTER_NODE_OTHERS_1_IP", expected_other_node_1_ip);
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_TCP",
+ expected_other_node_1_tcp.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_QUIC",
+ expected_other_node_1_quic.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_HTTP",
+ expected_other_node_1_http.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_WEBSOCKET",
+ expected_other_node_1_websocket.to_string(),
+ );
}
let config_path = get_root_path().join("../configs/server.toml");
@@ -157,64 +206,185 @@ async fn validate_cluster_config_env_override() {
// Verify cluster configuration
assert_eq!(config.cluster.enabled, expected_cluster_enabled);
- assert_eq!(config.cluster.id, expected_cluster_id);
assert_eq!(config.cluster.name, expected_cluster_name);
- assert_eq!(config.cluster.node.id, expected_node_id);
+ assert_eq!(config.cluster.node.current.name, expected_current_node_name);
- // Verify cluster nodes array - should have 3 nodes instead of the default 2
+ // Verify other nodes array - should have 2 nodes from environment variables
assert_eq!(
- config.cluster.nodes.len(),
- 3,
- "Should have 3 nodes from environment variables"
+ config.cluster.node.others.len(),
+ 2,
+ "Should have 2 other nodes from environment variables"
);
- // Verify first node
- assert_eq!(config.cluster.nodes[0].id, expected_node_0_id);
- assert_eq!(config.cluster.nodes[0].name, expected_node_0_name);
- assert_eq!(config.cluster.nodes[0].address, expected_node_0_address);
-
- // Verify second node
- assert_eq!(config.cluster.nodes[1].id, expected_node_1_id);
- assert_eq!(config.cluster.nodes[1].name, expected_node_1_name);
- assert_eq!(config.cluster.nodes[1].address, expected_node_1_address);
+ // Verify first other node
+ assert_eq!(
+ config.cluster.node.others[0].name,
+ expected_other_node_0_name
+ );
+ assert_eq!(config.cluster.node.others[0].ip, expected_other_node_0_ip);
+ assert_eq!(
+ config.cluster.node.others[0].ports.tcp,
+ Some(expected_other_node_0_tcp)
+ );
+ assert_eq!(
+ config.cluster.node.others[0].ports.quic,
+ Some(expected_other_node_0_quic)
+ );
+ assert_eq!(
+ config.cluster.node.others[0].ports.http,
+ Some(expected_other_node_0_http)
+ );
+ assert_eq!(
+ config.cluster.node.others[0].ports.websocket,
+ Some(expected_other_node_0_websocket)
+ );
- // Verify third node (added via env vars)
- assert_eq!(config.cluster.nodes[2].id, expected_node_2_id);
- assert_eq!(config.cluster.nodes[2].name, expected_node_2_name);
- assert_eq!(config.cluster.nodes[2].address, expected_node_2_address);
+ // Verify second other node
+ assert_eq!(
+ config.cluster.node.others[1].name,
+ expected_other_node_1_name
+ );
+ assert_eq!(config.cluster.node.others[1].ip, expected_other_node_1_ip);
+ assert_eq!(
+ config.cluster.node.others[1].ports.tcp,
+ Some(expected_other_node_1_tcp)
+ );
+ assert_eq!(
+ config.cluster.node.others[1].ports.quic,
+ Some(expected_other_node_1_quic)
+ );
+ assert_eq!(
+ config.cluster.node.others[1].ports.http,
+ Some(expected_other_node_1_http)
+ );
+ assert_eq!(
+ config.cluster.node.others[1].ports.websocket,
+ Some(expected_other_node_1_websocket)
+ );
unsafe {
// Clean up environment variables
env::remove_var("IGGY_CLUSTER_ENABLED");
env::remove_var("IGGY_CLUSTER_ID");
env::remove_var("IGGY_CLUSTER_NAME");
- env::remove_var("IGGY_CLUSTER_NODE_ID");
-
- env::remove_var("IGGY_CLUSTER_NODES_0_ID");
- env::remove_var("IGGY_CLUSTER_NODES_0_NAME");
- env::remove_var("IGGY_CLUSTER_NODES_0_ADDRESS");
-
- env::remove_var("IGGY_CLUSTER_NODES_1_ID");
- env::remove_var("IGGY_CLUSTER_NODES_1_NAME");
- env::remove_var("IGGY_CLUSTER_NODES_1_ADDRESS");
-
- env::remove_var("IGGY_CLUSTER_NODES_2_ID");
- env::remove_var("IGGY_CLUSTER_NODES_2_NAME");
- env::remove_var("IGGY_CLUSTER_NODES_2_ADDRESS");
+ env::remove_var("IGGY_CLUSTER_NODE_CURRENT_NAME");
+
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_IP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_TCP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_QUIC");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_HTTP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_WEBSOCKET");
+
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_IP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_TCP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_QUIC");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_HTTP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_WEBSOCKET");
}
}
-// Test partial override - only override specific fields
#[serial]
#[tokio::test]
-async fn validate_cluster_partial_env_override() {
- // Only override the cluster ID and one node's address
- let expected_cluster_id = 99;
- let expected_node_1_address = "10.0.0.1:8888";
+async fn validate_four_node_cluster_config_env_override() {
+ // Test data for cluster configuration
+ let expected_cluster_enabled = true;
+ let expected_cluster_name = "test-4node-cluster";
+ let expected_current_node_name = "node-1";
+ let expected_current_node_ip = "10.0.0.1";
+
+ // Test data for other nodes in cluster (3 other nodes for a 4-node cluster)
+ let expected_other_node_0_name = "node-2";
+ let expected_other_node_0_ip = "10.0.0.2";
+ let expected_other_node_0_tcp = 8090_u16;
+ let expected_other_node_0_quic = 8080_u16;
+ let expected_other_node_0_http = 3000_u16;
+ let expected_other_node_0_websocket = 8092_u16;
+
+ let expected_other_node_1_name = "node-3";
+ let expected_other_node_1_ip = "10.0.0.3";
+ let expected_other_node_1_tcp = 8091_u16;
+ let expected_other_node_1_quic = 8081_u16;
+ let expected_other_node_1_http = 3001_u16;
+ let expected_other_node_1_websocket = 8093_u16;
+
+ let expected_other_node_2_name = "node-4";
+ let expected_other_node_2_ip = "10.0.0.4";
+ let expected_other_node_2_tcp = 8092_u16;
+ // QUIC and WebSocket ports will be None in config (defaults applied at runtime)
+ let expected_other_node_2_http = 3002_u16;
unsafe {
- env::set_var("IGGY_CLUSTER_ID", expected_cluster_id.to_string());
- env::set_var("IGGY_CLUSTER_NODES_1_ADDRESS", expected_node_1_address);
+ // Set cluster configuration environment variables
+ env::set_var("IGGY_CLUSTER_ENABLED", expected_cluster_enabled.to_string());
+ env::set_var("IGGY_CLUSTER_NAME", expected_cluster_name);
+ env::set_var("IGGY_CLUSTER_NODE_CURRENT_NAME", expected_current_node_name);
+ env::set_var("IGGY_CLUSTER_NODE_CURRENT_IP", expected_current_node_ip);
+
+ // Set other nodes array environment variables - Node 2
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_NAME",
+ expected_other_node_0_name,
+ );
+ env::set_var("IGGY_CLUSTER_NODE_OTHERS_0_IP", expected_other_node_0_ip);
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_TCP",
+ expected_other_node_0_tcp.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_QUIC",
+ expected_other_node_0_quic.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_HTTP",
+ expected_other_node_0_http.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_0_PORTS_WEBSOCKET",
+ expected_other_node_0_websocket.to_string(),
+ );
+
+ // Set other nodes array environment variables - Node 3
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_NAME",
+ expected_other_node_1_name,
+ );
+ env::set_var("IGGY_CLUSTER_NODE_OTHERS_1_IP", expected_other_node_1_ip);
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_TCP",
+ expected_other_node_1_tcp.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_QUIC",
+ expected_other_node_1_quic.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_HTTP",
+ expected_other_node_1_http.to_string(),
+ );
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_1_PORTS_WEBSOCKET",
+ expected_other_node_1_websocket.to_string(),
+ );
+
+ // Set other nodes array environment variables - Node 4
+ // Only set TCP and HTTP ports, leaving QUIC and WebSocket to use defaults
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_2_NAME",
+ expected_other_node_2_name,
+ );
+ env::set_var("IGGY_CLUSTER_NODE_OTHERS_2_IP", expected_other_node_2_ip);
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_2_PORTS_TCP",
+ expected_other_node_2_tcp.to_string(),
+ );
+ // IGGY_CLUSTER_NODE_OTHERS_2_PORTS_QUIC is NOT set - should use default (8080)
+ env::set_var(
+ "IGGY_CLUSTER_NODE_OTHERS_2_PORTS_HTTP",
+ expected_other_node_2_http.to_string(),
+ );
+ // IGGY_CLUSTER_NODE_OTHERS_2_PORTS_WEBSOCKET is NOT set - should use default (8092)
}
let config_path = get_root_path().join("../configs/server.toml");
@@ -222,104 +392,133 @@ async fn validate_cluster_partial_env_override() {
let config = file_config_provider
.load_config()
.await
- .expect("Failed to load server.toml config with partial cluster env overrides");
-
- // Verify overridden values
- assert_eq!(config.cluster.id, expected_cluster_id);
- assert_eq!(config.cluster.nodes[1].address, expected_node_1_address);
-
- // Verify non-overridden values remain default
- assert_eq!(config.cluster.name, "iggy-cluster"); // default from server.toml
- assert_eq!(config.cluster.nodes[0].id, 0); // default from server.toml
- assert_eq!(config.cluster.nodes[0].name, "iggy-node-1"); // default from server.toml
- assert_eq!(config.cluster.nodes[1].id, 1); // default from server.toml
- assert_eq!(config.cluster.nodes[1].name, "iggy-node-2"); // default from server.toml
-
- unsafe {
- env::remove_var("IGGY_CLUSTER_ID");
- env::remove_var("IGGY_CLUSTER_NODES_1_ADDRESS");
- }
-}
-
-// Test sparse array override - setting index 5 when only 2 nodes exist in TOML
-// This test verifies that sparse arrays will fail because intermediate elements
-// won't have required fields, which is the expected safety behavior
-#[serial]
-#[tokio::test]
-async fn validate_cluster_sparse_array_fails_with_missing_fields() {
- // Set node at index 5 (when TOML only has nodes 0 and 1)
- // This should fail because nodes 2-4 will be created as empty dicts
- // without required fields
- let expected_node_5_id = 100;
- let expected_node_5_name = "sparse-node";
- let expected_node_5_address = "10.0.0.100:9999";
+ .expect("Failed to load server.toml config with 4-node cluster env overrides");
- unsafe {
- env::set_var("IGGY_CLUSTER_NODES_5_ID", expected_node_5_id.to_string());
- env::set_var("IGGY_CLUSTER_NODES_5_NAME", expected_node_5_name);
- env::set_var("IGGY_CLUSTER_NODES_5_ADDRESS", expected_node_5_address);
- }
-
- let config_path = get_root_path().join("../configs/server.toml");
- let file_config_provider = FileConfigProvider::new(config_path.as_path().display().to_string());
+ // Verify cluster configuration
+ assert_eq!(config.cluster.enabled, expected_cluster_enabled);
+ assert_eq!(config.cluster.name, expected_cluster_name);
+ assert_eq!(config.cluster.node.current.name, expected_current_node_name);
+ assert_eq!(config.cluster.node.current.ip, expected_current_node_ip);
- // This should fail because nodes 2-4 will be missing required fields
- let result = file_config_provider.load_config().await;
- assert!(
- result.is_err(),
- "Should fail to load config with sparse array due to missing required fields in intermediate elements"
+ // Verify other nodes array - should have 3 nodes from environment variables
+ assert_eq!(
+ config.cluster.node.others.len(),
+ 3,
+ "Should have 3 other nodes from environment variables for a 4-node cluster"
);
- unsafe {
- env::remove_var("IGGY_CLUSTER_NODES_5_ID");
- env::remove_var("IGGY_CLUSTER_NODES_5_NAME");
- env::remove_var("IGGY_CLUSTER_NODES_5_ADDRESS");
- }
-}
+ // Verify first other node (Node 2)
+ assert_eq!(
+ config.cluster.node.others[0].name,
+ expected_other_node_0_name
+ );
+ assert_eq!(config.cluster.node.others[0].ip, expected_other_node_0_ip);
+ assert_eq!(
+ config.cluster.node.others[0].ports.tcp,
+ Some(expected_other_node_0_tcp)
+ );
+ assert_eq!(
+ config.cluster.node.others[0].ports.quic,
+ Some(expected_other_node_0_quic)
+ );
+ assert_eq!(
+ config.cluster.node.others[0].ports.http,
+ Some(expected_other_node_0_http)
+ );
+ assert_eq!(
+ config.cluster.node.others[0].ports.websocket,
+ Some(expected_other_node_0_websocket)
+ );
-// Test that we can add node 2 successfully (contiguous array)
-#[serial]
-#[tokio::test]
-async fn validate_cluster_contiguous_array_override() {
- // Add node at index 2 (TOML has nodes 0 and 1, so this is contiguous)
- let expected_node_2_id = 2;
- let expected_node_2_name = "iggy-node-3";
- let expected_node_2_address = "10.0.0.50:8092";
+ // Verify second other node (Node 3)
+ assert_eq!(
+ config.cluster.node.others[1].name,
+ expected_other_node_1_name
+ );
+ assert_eq!(config.cluster.node.others[1].ip, expected_other_node_1_ip);
+ assert_eq!(
+ config.cluster.node.others[1].ports.tcp,
+ Some(expected_other_node_1_tcp)
+ );
+ assert_eq!(
+ config.cluster.node.others[1].ports.quic,
+ Some(expected_other_node_1_quic)
+ );
+ assert_eq!(
+ config.cluster.node.others[1].ports.http,
+ Some(expected_other_node_1_http)
+ );
+ assert_eq!(
+ config.cluster.node.others[1].ports.websocket,
+ Some(expected_other_node_1_websocket)
+ );
- unsafe {
- env::set_var("IGGY_CLUSTER_NODES_2_ID", expected_node_2_id.to_string());
- env::set_var("IGGY_CLUSTER_NODES_2_NAME", expected_node_2_name);
- env::set_var("IGGY_CLUSTER_NODES_2_ADDRESS", expected_node_2_address);
- }
+ // Verify third other node (Node 4)
+ // This node has only TCP and HTTP explicitly set, QUIC and WebSocket should be None
+ // (defaults will be applied at runtime by the cluster system)
+ assert_eq!(
+ config.cluster.node.others[2].name,
+ expected_other_node_2_name
+ );
+ assert_eq!(config.cluster.node.others[2].ip, expected_other_node_2_ip);
- let config_path = get_root_path().join("../configs/server.toml");
- let file_config_provider = FileConfigProvider::new(config_path.as_path().display().to_string());
- let config = file_config_provider
- .load_config()
- .await
- .expect("Failed to load server.toml config with contiguous array override");
+ // TCP port was explicitly set via env var
+ assert_eq!(
+ config.cluster.node.others[2].ports.tcp,
+ Some(expected_other_node_2_tcp),
+ "TCP port should be the explicitly set value (8092)"
+ );
- // Should have 3 nodes total
+ // QUIC port was NOT set via env var - should be None in config
+ // Runtime will use default port 8080 from current node's QUIC config
assert_eq!(
- config.cluster.nodes.len(),
- 3,
- "Should have 3 nodes when adding index 2"
+ config.cluster.node.others[2].ports.quic, None,
+ "QUIC port should be None (default 8080 applied at runtime)"
);
- // Check original nodes are preserved
- assert_eq!(config.cluster.nodes[0].id, 0); // from TOML
- assert_eq!(config.cluster.nodes[0].name, "iggy-node-1"); // from TOML
- assert_eq!(config.cluster.nodes[1].id, 1); // from TOML
- assert_eq!(config.cluster.nodes[1].name, "iggy-node-2"); // from TOML
+ // HTTP port was explicitly set via env var
+ assert_eq!(
+ config.cluster.node.others[2].ports.http,
+ Some(expected_other_node_2_http),
+ "HTTP port should be the explicitly set value (3002)"
+ );
- // Check the node we added at index 2
- assert_eq!(config.cluster.nodes[2].id, expected_node_2_id);
- assert_eq!(config.cluster.nodes[2].name, expected_node_2_name);
- assert_eq!(config.cluster.nodes[2].address, expected_node_2_address);
+ // WebSocket port was NOT set via env var - should be None in config
+ // Runtime will use default port 8092 from current node's WebSocket config
+ assert_eq!(
+ config.cluster.node.others[2].ports.websocket, None,
+ "WebSocket port should be None (default 8092 applied at runtime)"
+ );
unsafe {
- env::remove_var("IGGY_CLUSTER_NODES_2_ID");
- env::remove_var("IGGY_CLUSTER_NODES_2_NAME");
- env::remove_var("IGGY_CLUSTER_NODES_2_ADDRESS");
+ // Clean up environment variables
+ env::remove_var("IGGY_CLUSTER_ENABLED");
+ env::remove_var("IGGY_CLUSTER_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_CURRENT_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_CURRENT_IP");
+
+ // Clean up Node 2 env vars
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_IP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_TCP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_QUIC");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_HTTP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_0_PORTS_WEBSOCKET");
+
+ // Clean up Node 3 env vars
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_IP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_TCP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_QUIC");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_HTTP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_1_PORTS_WEBSOCKET");
+
+ // Clean up Node 4 env vars (only TCP and HTTP were set)
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_2_NAME");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_2_IP");
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_2_PORTS_TCP");
+ // IGGY_CLUSTER_NODE_OTHERS_2_PORTS_QUIC was not set
+ env::remove_var("IGGY_CLUSTER_NODE_OTHERS_2_PORTS_HTTP");
+ // IGGY_CLUSTER_NODE_OTHERS_2_PORTS_WEBSOCKET was not set
}
}
diff --git a/core/integration/tests/mcp/mod.rs b/core/integration/tests/mcp/mod.rs
index 124522a3a..2793e00ec 100644
--- a/core/integration/tests/mcp/mod.rs
+++ b/core/integration/tests/mcp/mod.rs
@@ -67,9 +67,8 @@ async fn mcp_server_should_list_tools() {
let tools = client.list_tools().await.expect("Failed to list tools");
assert!(!tools.tools.is_empty());
- // TODO(hubcio): fix this once GetClusterMetadata is enabled for MCP tests
- let tools_count = tools.tools.len() - 1;
- assert_eq!(tools_count, 40);
+ let tools_count = tools.tools.len();
+ assert_eq!(tools_count, 41);
}
#[tokio::test]
@@ -78,17 +77,12 @@ async fn mcp_server_should_handle_ping() {
assert_empty_response("ping", None).await;
}
-// TODO(hubcio): not sure how to fix the cluster ports in CI
-#[ignore]
#[tokio::test]
#[parallel]
async fn mcp_server_should_return_cluster_metadata() {
assert_response::<ClusterMetadata>("get_cluster_metadata", None, |cluster| {
- assert_eq!(cluster.id, 0);
assert!(!cluster.name.is_empty());
- assert_eq!(cluster.nodes.len(), 1);
- let node = &cluster.nodes[0];
- assert_eq!(node.id, 0);
+ assert_eq!(cluster.nodes.len(), 2);
})
.await;
}
@@ -579,8 +573,7 @@ async fn invoke_request<T: DeserializeOwned>(
async fn setup() -> McpInfra {
let mut iggy_envs = HashMap::new();
- // TODO(hubcio): not sure how to fix the cluster ports in CI
- // iggy_envs.insert("IGGY_CLUSTER_ENABLED".to_owned(), "true".to_owned());
+ iggy_envs.insert("IGGY_CLUSTER_ENABLED".to_owned(), "true".to_owned());
iggy_envs.insert("IGGY_QUIC_ENABLED".to_owned(), "false".to_owned());
iggy_envs.insert("IGGY_WEBSOCKET_ENABLED".to_owned(), "false".to_owned());
let mut test_server = TestServer::new(Some(iggy_envs), true, None, IpAddrKind::V4);
diff --git a/core/sdk/Cargo.toml b/core/sdk/Cargo.toml
index 484162223..812f8f1d1 100644
--- a/core/sdk/Cargo.toml
+++ b/core/sdk/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "iggy"
-version = "0.8.0"
+version = "0.8.0-edge.6"
description = "Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second."
edition = "2024"
license = "Apache-2.0"
diff --git a/core/sdk/src/leader_aware.rs b/core/sdk/src/leader_aware.rs
index 9367a7b13..d09f31a0a 100644
--- a/core/sdk/src/leader_aware.rs
+++ b/core/sdk/src/leader_aware.rs
@@ -18,7 +18,7 @@
use iggy_binary_protocol::ClusterClient;
use iggy_common::{
- ClusterMetadata, ClusterNodeRole, ClusterNodeStatus, IggyError, IggyErrorDiscriminants,
+ ClusterMetadata, ClusterNodeRole, ClusterNodeStatus, IggyError, TransportProtocol,
};
use std::net::SocketAddr;
use std::str::FromStr;
@@ -31,6 +31,7 @@ const MAX_LEADER_REDIRECTS: u8 = 3;
pub async fn check_and_redirect_to_leader<C: ClusterClient>(
client: &C,
current_address: &str,
+ transport: TransportProtocol,
) -> Result<Option<String>, IggyError> {
debug!("Checking cluster metadata for leader detection");
@@ -41,11 +42,7 @@ pub async fn check_and_redirect_to_leader<C: ClusterClient>(
metadata.nodes.len(),
metadata.name
);
- process_cluster_metadata(&metadata, current_address)
- }
- Err(e) if is_feature_unavailable_error(&e) => {
- debug!("Cluster metadata feature unavailable - server doesn't support clustering");
- Ok(None)
+ process_cluster_metadata(&metadata, current_address, transport)
}
Err(e) => {
warn!(
@@ -61,7 +58,17 @@ pub async fn check_and_redirect_to_leader<C: ClusterClient>(
fn process_cluster_metadata(
metadata: &ClusterMetadata,
current_address: &str,
+ transport: TransportProtocol,
) -> Result<Option<String>, IggyError> {
+ // If there's only one node in the cluster, no redirection is needed
+ if metadata.nodes.len() == 1 {
+ debug!(
+ "Single-node cluster detected ({}), no leader redirection needed",
+ metadata.nodes[0].name
+ );
+ return Ok(None);
+ }
+
let leader = metadata
.nodes
.iter()
@@ -69,17 +76,25 @@ fn process_cluster_metadata(
match leader {
Some(leader_node) => {
+ let leader_port = match transport {
+ TransportProtocol::Tcp => leader_node.endpoints.tcp,
+ TransportProtocol::Quic => leader_node.endpoints.quic,
+ TransportProtocol::Http => leader_node.endpoints.http,
+ TransportProtocol::WebSocket => leader_node.endpoints.websocket,
+ };
+ let leader_address = format!("{}:{}", leader_node.ip, leader_port);
+
info!(
- "Found leader node: {} at {}",
- leader_node.name, leader_node.address
+ "Found leader node: {} at {} (using {} transport)",
+ leader_node.name, leader_address, transport
);
- if !is_same_address(current_address, &leader_node.address) {
+ if !is_same_address(current_address, &leader_address) {
info!(
"Current connection to {} is not the leader, will redirect to {}",
- current_address, leader_node.address
+ current_address, leader_address
);
- Ok(Some(leader_node.address.clone()))
+ Ok(Some(leader_address))
} else {
debug!("Already connected to leader at {}", current_address);
Ok(None)
@@ -124,14 +139,6 @@ fn normalize_address(addr: &str) -> String {
.replace("[::]", "[::1]")
}
-/// Check if the error indicates that the feature is unavailable
-fn is_feature_unavailable_error(error: &IggyError) -> bool {
- matches!(
- error,
- IggyError::FeatureUnavailable | IggyError::InvalidCommand
- ) || error.as_code() == IggyErrorDiscriminants::FeatureUnavailable as u32
-}
-
/// Struct to track leader redirection state
#[derive(Debug, Clone)]
pub struct LeaderRedirectionState {
diff --git a/core/sdk/src/prelude.rs b/core/sdk/src/prelude.rs
index 8780dd947..5459b3125 100644
--- a/core/sdk/src/prelude.rs
+++ b/core/sdk/src/prelude.rs
@@ -64,9 +64,9 @@ pub use iggy_common::{
PollingKind, PollingStrategy, QuicClientConfig, QuicClientConfigBuilder,
QuicClientReconnectionConfig, SendMessages, Sizeable, SnapshotCompression, Stats, Stream,
StreamDetails, StreamPermissions, SystemSnapshotType, TcpClientConfig, TcpClientConfigBuilder,
- TcpClientReconnectionConfig, Topic, TopicDetails, TopicPermissions, TransportProtocol, UserId,
- UserStatus, Validatable, WebSocketClientConfig, WebSocketClientConfigBuilder,
- WebSocketClientReconnectionConfig, defaults, locking,
+ TcpClientReconnectionConfig, Topic, TopicDetails, TopicPermissions, TransportEndpoints,
+ TransportProtocol, UserId, UserStatus, Validatable, WebSocketClientConfig,
+ WebSocketClientConfigBuilder, WebSocketClientReconnectionConfig, defaults, locking,
};
pub use iggy_common::{
IGGY_MESSAGE_CHECKSUM_OFFSET_RANGE, IGGY_MESSAGE_HEADER_SIZE,
diff --git a/core/sdk/src/quic/quic_client.rs b/core/sdk/src/quic/quic_client.rs
index ecf5bbf86..e55980d16 100644
--- a/core/sdk/src/quic/quic_client.rs
+++ b/core/sdk/src/quic/quic_client.rs
@@ -29,7 +29,7 @@ use async_trait::async_trait;
use bytes::Bytes;
use iggy_common::{
ClientState, Command, ConnectionString, ConnectionStringUtils, Credentials, DiagnosticEvent,
- IggyErrorDiscriminants, QuicConnectionStringOptions, TransportProtocol,
+ QuicConnectionStringOptions, TransportProtocol,
};
use quinn::crypto::rustls::QuicClientConfig as QuinnQuicClientConfig;
use quinn::{ClientConfig, Connection, Endpoint, IdleTimeout, RecvStream, VarInt};
@@ -239,20 +239,11 @@ impl QuicClient {
.map_err(|_| IggyError::InvalidNumberEncoding)?,
);
if status != 0 {
- // Log FeatureUnavailable as debug instead of error (e.g., when clustering is disabled)
- if status == IggyErrorDiscriminants::FeatureUnavailable as u32 {
- tracing::debug!(
- "Feature unavailable on server: {} ({})",
- status,
- IggyError::from_code_as_string(status)
- );
- } else {
- error!(
- "Received an invalid response with status: {} ({}).",
- status,
- IggyError::from_code_as_string(status)
- );
- }
+ error!(
+ "Received an invalid response with status: {} ({}).",
+ status,
+ IggyError::from_code_as_string(status)
+ );
return Err(IggyError::from_code(status));
}
@@ -424,7 +415,12 @@ impl QuicClient {
/// Returns true if redirection occurred and reconnection is needed.
pub(crate) async fn handle_leader_redirection(&self) -> Result<bool, IggyError> {
let current_address = self.current_server_address.lock().await.clone();
- let leader_address = check_and_redirect_to_leader(self, ¤t_address).await?;
+ let leader_address = check_and_redirect_to_leader(
+ self,
+ ¤t_address,
+ iggy_common::TransportProtocol::Quic,
+ )
+ .await?;
if let Some(new_leader_address) = leader_address {
let mut redirection_state = self.leader_redirection_state.lock().await;
diff --git a/core/sdk/src/tcp/tcp_client.rs b/core/sdk/src/tcp/tcp_client.rs
index 66017fad3..571f1b7cb 100644
--- a/core/sdk/src/tcp/tcp_client.rs
+++ b/core/sdk/src/tcp/tcp_client.rs
@@ -226,13 +226,6 @@ impl TcpClient {
status,
IggyError::from_code_as_string(status)
)
- } else if status == IggyErrorDiscriminants::FeatureUnavailable as u32 {
- // Feature unavailable - likely clustering is disabled on server
- tracing::debug!(
- "Feature unavailable on server: {} ({})",
- status,
- IggyError::from_code_as_string(status)
- )
} else {
error!(
"Received an invalid response with status: {} ({}).",
@@ -476,7 +469,12 @@ impl TcpClient {
/// Returns true if redirection occurred and reconnection is needed.
pub(crate) async fn handle_leader_redirection(&self) -> Result<bool, IggyError> {
let current_address = self.current_server_address.lock().await.clone();
- let leader_address = check_and_redirect_to_leader(self, ¤t_address).await?;
+ let leader_address = check_and_redirect_to_leader(
+ self,
+ ¤t_address,
+ iggy_common::TransportProtocol::Tcp,
+ )
+ .await?;
if let Some(new_leader_address) = leader_address {
let mut redirection_state = self.leader_redirection_state.lock().await;
diff --git a/core/sdk/src/websocket/websocket_client.rs b/core/sdk/src/websocket/websocket_client.rs
index 399df9ba7..ff89d2a30 100644
--- a/core/sdk/src/websocket/websocket_client.rs
+++ b/core/sdk/src/websocket/websocket_client.rs
@@ -437,7 +437,12 @@ impl WebSocketClient {
/// Returns true if redirection occurred and reconnection is needed.
pub(crate) async fn handle_leader_redirection(&self) -> Result<bool, IggyError> {
let current_address = self.current_server_address.lock().await.clone();
- let leader_address = check_and_redirect_to_leader(self, ¤t_address).await?;
+ let leader_address = check_and_redirect_to_leader(
+ self,
+ ¤t_address,
+ iggy_common::TransportProtocol::WebSocket,
+ )
+ .await?;
if let Some(new_leader_address) = leader_address {
let mut redirection_state = self.leader_redirection_state.lock().await;
diff --git a/core/server/Cargo.toml b/core/server/Cargo.toml
index 6fa817948..e851e3fca 100644
--- a/core/server/Cargo.toml
+++ b/core/server/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "server"
-version = "0.6.0"
+version = "0.6.0-edge.6"
edition = "2024"
license = "Apache-2.0"
diff --git a/core/server/src/configs/cluster.rs b/core/server/src/configs/cluster.rs
index 3a0d4506c..7e3893650 100644
--- a/core/server/src/configs/cluster.rs
+++ b/core/server/src/configs/cluster.rs
@@ -16,27 +16,38 @@
* under the License.
*/
-use iggy_common::TransportProtocol;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ClusterConfig {
pub enabled: bool,
pub name: String,
- pub id: u32,
- pub transport: TransportProtocol,
pub node: NodeConfig,
- pub nodes: Vec<ClusterNodeConfig>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct NodeConfig {
- pub id: u32,
+ pub current: CurrentNodeConfig,
+ pub others: Vec<OtherNodeConfig>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
-pub struct ClusterNodeConfig {
- pub id: u32,
+pub struct CurrentNodeConfig {
pub name: String,
- pub address: String,
+ pub ip: String,
+}
+
+#[derive(Debug, Deserialize, Serialize, Clone)]
+pub struct OtherNodeConfig {
+ pub name: String,
+ pub ip: String,
+ pub ports: TransportPorts,
+}
+
+#[derive(Debug, Deserialize, Serialize, Clone, Default)]
+pub struct TransportPorts {
+ pub tcp: Option<u16>,
+ pub quic: Option<u16>,
+ pub http: Option<u16>,
+ pub websocket: Option<u16>,
}
diff --git a/core/server/src/configs/config_provider.rs b/core/server/src/configs/config_provider.rs
index b77ec4bdf..3461d44ef 100644
--- a/core/server/src/configs/config_provider.rs
+++ b/core/server/src/configs/config_provider.rs
@@ -168,12 +168,29 @@ impl CustomEnvProvider {
if remaining_path.is_empty() {
arr[array_index] = value;
} else if let FigmentValue::Dict(_, elem_dict) = &mut arr[array_index] {
- Self::insert_overridden_values_from_env(
- &Dict::new(),
- elem_dict,
- remaining_path.to_vec(),
- value,
- );
+ // TODO(hubcio): this is workaround done by Claude because this code is overly
+ // complicated and I don't want to spend time on it.
+ // For nested structures in arrays, check if we need to create intermediate dicts
+ // Handle the "ports" case where it should be a nested structure
+ if remaining_path.len() >= 2 && remaining_path[0] == "ports" {
+ // Create the ports dict if it doesn't exist
+ elem_dict
+ .entry("ports".to_string())
+ .or_insert_with(|| FigmentValue::Dict(Tag::Default, Dict::new()));
+
+ if let Some(FigmentValue::Dict(_, ports_dict)) = elem_dict.get_mut("ports") {
+ // Insert the specific port value (tcp, quic, http, websocket)
+ ports_dict.insert(remaining_path[1].clone(), value);
+ }
+ } else {
+ // Default behavior for other fields
+ Self::insert_overridden_values_from_env(
+ &Dict::new(),
+ elem_dict,
+ remaining_path.to_vec(),
+ value,
+ );
+ }
}
}
}
@@ -306,6 +323,11 @@ impl CustomEnvProvider {
if value == "false" {
return FigmentValue::from(false);
}
+ // Try u64 first for most numeric values (ports, byte sizes, etc.)
+ if let Ok(uint_val) = value.parse::<u64>() {
+ return FigmentValue::from(uint_val);
+ }
+ // Fall back to i64 for signed integers
if let Ok(int_val) = value.parse::<i64>() {
return FigmentValue::from(int_val);
}
diff --git a/core/server/src/configs/defaults.rs b/core/server/src/configs/defaults.rs
index ce990815c..9849dc8fc 100644
--- a/core/server/src/configs/defaults.rs
+++ b/core/server/src/configs/defaults.rs
@@ -19,7 +19,8 @@
use super::sharding::ShardingConfig;
use super::system::MemoryPoolConfig;
use super::tcp::TcpSocketConfig;
-use crate::configs::cluster::{ClusterConfig, ClusterNodeConfig, NodeConfig};
+use crate::configs::cluster::CurrentNodeConfig;
+use crate::configs::cluster::{ClusterConfig, NodeConfig, OtherNodeConfig, TransportPorts};
use crate::configs::http::{
HttpConfig, HttpCorsConfig, HttpJwtConfig, HttpMetricsConfig, HttpTlsConfig,
};
@@ -544,22 +545,8 @@ impl Default for ClusterConfig {
fn default() -> ClusterConfig {
ClusterConfig {
enabled: SERVER_CONFIG.cluster.enabled,
- id: SERVER_CONFIG.cluster.id as u32,
name: SERVER_CONFIG.cluster.name.parse().unwrap(),
- transport: SERVER_CONFIG.cluster.transport.parse().unwrap(),
node: NodeConfig::default(),
- nodes: vec![
- ClusterNodeConfig {
- id: SERVER_CONFIG.cluster.nodes[0].id as u32,
- name: SERVER_CONFIG.cluster.nodes[0].name.parse().unwrap(),
- address: SERVER_CONFIG.cluster.nodes[0].address.parse().unwrap(),
- },
- ClusterNodeConfig {
- id: SERVER_CONFIG.cluster.nodes[1].id as u32,
- name: SERVER_CONFIG.cluster.nodes[1].name.parse().unwrap(),
- address: SERVER_CONFIG.cluster.nodes[1].address.parse().unwrap(),
- },
- ],
}
}
}
@@ -567,7 +554,26 @@ impl Default for ClusterConfig {
impl Default for NodeConfig {
fn default() -> NodeConfig {
NodeConfig {
- id: SERVER_CONFIG.cluster.node.id as u32,
+ current: CurrentNodeConfig {
+ name: SERVER_CONFIG.cluster.node.current.name.parse().unwrap(),
+ ip: SERVER_CONFIG.cluster.node.current.ip.parse().unwrap(),
+ },
+ others: SERVER_CONFIG
+ .cluster
+ .node
+ .others
+ .iter()
+ .map(|other| OtherNodeConfig {
+ name: other.name.parse().unwrap(),
+ ip: other.ip.parse().unwrap(),
+ ports: TransportPorts {
+ tcp: Some(other.ports.tcp as u16),
+ quic: Some(other.ports.quic as u16),
+ http: Some(other.ports.http as u16),
+ websocket: Some(other.ports.websocket as u16),
+ },
+ })
+ .collect(),
}
}
}
diff --git a/core/server/src/configs/validators.rs b/core/server/src/configs/validators.rs
index 792b8f434..83aff5858 100644
--- a/core/server/src/configs/validators.rs
+++ b/core/server/src/configs/validators.rs
@@ -337,77 +337,72 @@ impl Validatable<ConfigError> for ClusterConfig {
return Err(ConfigError::InvalidConfiguration);
}
- // Validate nodes list is not empty
- if self.nodes.is_empty() {
- eprintln!("Invalid cluster configuration: nodes list cannot be empty");
+ // Validate current node name is not empty
+ if self.node.current.name.trim().is_empty() {
+ eprintln!("Invalid cluster configuration: current node name cannot be empty");
return Err(ConfigError::InvalidConfiguration);
}
- // Check if nodes start from ID 0
- let has_node_zero = self.nodes.iter().any(|node| node.id == 0);
- if !has_node_zero {
- eprintln!("Invalid cluster configuration: nodes must start from ID 0");
- return Err(ConfigError::InvalidConfiguration);
- }
+ // Check for duplicate node names among other nodes
+ let mut node_names = std::collections::HashSet::new();
+ node_names.insert(self.node.current.name.clone());
- // Check if current node ID exists in nodes vector
- let current_node_exists = self.nodes.iter().any(|node| node.id == self.node.id);
- if !current_node_exists {
- eprintln!(
- "Invalid cluster configuration: current node ID {} not found in nodes list",
- self.node.id
- );
- return Err(ConfigError::InvalidConfiguration);
- }
-
- // Check for duplicate node IDs
- let mut node_ids = std::collections::HashSet::new();
- for node in &self.nodes {
- if !node_ids.insert(node.id) {
+ for node in &self.node.others {
+ if !node_names.insert(node.name.clone()) {
eprintln!(
- "Invalid cluster configuration: duplicate node ID {} found",
- node.id
+ "Invalid cluster configuration: duplicate node name '{}' found",
+ node.name
);
return Err(ConfigError::InvalidConfiguration);
}
}
- // Validate unique addresses (IP:port combinations)
- let mut addresses = std::collections::HashSet::new();
- for node in &self.nodes {
- // Validate address format (should contain IP:port or [IPv6]:port)
- let is_valid_address = if node.address.starts_with('[') {
- // IPv6 address format: [::1]:8090
- node.address.contains("]:") && node.address.matches(':').count() >= 2
- } else {
- // IPv4 address format: 127.0.0.1:8090
- node.address.matches(':').count() == 1
- };
-
- if !is_valid_address {
- eprintln!(
- "Invalid cluster configuration: malformed address '{}' for node ID {}",
- node.address, node.id
- );
+ // Validate each other node configuration
+ let mut used_endpoints = std::collections::HashSet::new();
+ for node in &self.node.others {
+ // Validate node name is not empty
+ if node.name.trim().is_empty() {
+ eprintln!("Invalid cluster configuration: node name cannot be empty");
return Err(ConfigError::InvalidConfiguration);
}
- // Check for duplicate full addresses
- if !addresses.insert(node.address.clone()) {
+ // Validate IP is not empty
+ if node.ip.trim().is_empty() {
eprintln!(
- "Invalid cluster configuration: duplicate address {} found (node ID: {})",
- node.address, node.id
+ "Invalid cluster configuration: IP cannot be empty for node '{}'",
+ node.name
);
return Err(ConfigError::InvalidConfiguration);
}
- // Validate node name is not empty
- if node.name.trim().is_empty() {
- eprintln!(
- "Invalid cluster configuration: node name cannot be empty for node ID {}",
- node.id
- );
- return Err(ConfigError::InvalidConfiguration);
+ // Validate transport ports if provided
+ let port_list = [
+ ("TCP", node.ports.tcp),
+ ("QUIC", node.ports.quic),
+ ("HTTP", node.ports.http),
+ ("WebSocket", node.ports.websocket),
+ ];
+
+ for (name, port_opt) in &port_list {
+ if let Some(port) = port_opt {
+ if *port == 0 {
+ eprintln!(
+ "Invalid cluster configuration: {} port cannot be 0 for node '{}'",
+ name, node.name
+ );
+ return Err(ConfigError::InvalidConfiguration);
+ }
+
+ // Check for port conflicts across nodes on the same IP
+ let endpoint = format!("{}:{}:{}", node.ip, name, port);
+ if !used_endpoints.insert(endpoint.clone()) {
+ eprintln!(
+ "Invalid cluster configuration: port conflict - {}:{} is already used",
+ node.ip, port
+ );
+ return Err(ConfigError::InvalidConfiguration);
+ }
+ }
}
}
diff --git a/core/server/src/shard/system/cluster.rs b/core/server/src/shard/system/cluster.rs
index e4af6d724..3ccb599b1 100644
--- a/core/server/src/shard/system/cluster.rs
+++ b/core/server/src/shard/system/cluster.rs
@@ -18,69 +18,136 @@
use crate::shard::IggyShard;
use crate::streaming::session::Session;
-use iggy_common::{ClusterMetadata, ClusterNode, ClusterNodeRole, ClusterNodeStatus, IggyError};
+use crate::streaming::utils::address::{extract_ip, extract_port};
+use iggy_common::{
+ ClusterMetadata, ClusterNode, ClusterNodeRole, ClusterNodeStatus, IggyError, TransportEndpoints,
+};
use tracing::trace;
impl IggyShard {
pub fn get_cluster_metadata(&self, session: &Session) -> Result<ClusterMetadata, IggyError> {
trace!("Getting cluster metadata for session: {session}");
- if !self.config.cluster.enabled {
- return Err(IggyError::FeatureUnavailable);
- }
-
- // TODO(hubcio): Clustering is not yet implemented
- // The leader/follower as well as node status are currently placeholder implementations.
+ let mut nodes = Vec::new();
- let cluster_name = self.config.cluster.name.clone();
- let cluster_id = self.config.cluster.id;
+ // Determine cluster name and current node name based on whether clustering is enabled
+ let (cluster_name, current_node_name, current_ip) = if self.config.cluster.enabled {
+ (
+ self.config.cluster.name.clone(),
+ self.config.cluster.node.current.name.clone(),
+ self.config.cluster.node.current.ip.clone(),
+ )
+ } else {
+ (
+ "single-node".to_string(),
+ "iggy-node".to_string(),
+ extract_ip(&self.config.tcp.address),
+ )
+ };
- // Cannot fail because we validated it in config
- let transport = self.config.cluster.transport;
+ // Get the actual bound ports from the shard's bound addresses
+ let current_endpoints = self.get_actual_bound_ports().unwrap_or_else(|| {
+ TransportEndpoints::new(
+ extract_port(&self.config.tcp.address),
+ extract_port(&self.config.quic.address),
+ extract_port(&self.config.http.address),
+ extract_port(&self.config.websocket.address),
+ )
+ });
- let own_node_id = self.config.cluster.node.id;
+ // Add current node with appropriate role
+ nodes.push(ClusterNode {
+ name: current_node_name.clone(),
+ ip: current_ip,
+ endpoints: current_endpoints,
+ role: if self.config.cluster.enabled && self.is_follower {
+ ClusterNodeRole::Follower
+ } else {
+ // Always leader when clustering is disabled or when not a follower
+ ClusterNodeRole::Leader
+ },
+ status: ClusterNodeStatus::Healthy,
+ });
- let nodes: Vec<ClusterNode> = self
- .config
- .cluster
- .nodes
- .iter()
- .map(|node_config| {
- let (role, status) = if node_config.id == own_node_id {
- (
- if self.is_follower {
- ClusterNodeRole::Follower
- } else {
- ClusterNodeRole::Leader
- },
- ClusterNodeStatus::Healthy,
- )
- } else {
- (
- if self.is_follower {
- ClusterNodeRole::Leader
- } else {
- ClusterNodeRole::Follower
- },
- ClusterNodeStatus::Healthy,
- )
- };
+ // Only add other nodes if clustering is enabled
+ if self.config.cluster.enabled {
+ for other_node in &self.config.cluster.node.others {
+ let endpoints = TransportEndpoints::new(
+ other_node
+ .ports
+ .tcp
+ .unwrap_or_else(|| extract_port(&self.config.tcp.address)),
+ other_node
+ .ports
+ .quic
+ .unwrap_or_else(|| extract_port(&self.config.quic.address)),
+ other_node
+ .ports
+ .http
+ .unwrap_or_else(|| extract_port(&self.config.http.address)),
+ other_node
+ .ports
+ .websocket
+ .unwrap_or_else(|| extract_port(&self.config.websocket.address)),
+ );
- ClusterNode {
- id: node_config.id,
- name: node_config.name.clone(),
- address: node_config.address.clone(),
- role,
- status,
- }
- })
- .collect();
+ nodes.push(ClusterNode {
+ name: other_node.name.clone(),
+ ip: other_node.ip.clone(),
+ endpoints,
+ role: if self.is_follower {
+ ClusterNodeRole::Leader
+ } else {
+ ClusterNodeRole::Follower
+ },
+ status: ClusterNodeStatus::Healthy,
+ });
+ }
+ }
Ok(ClusterMetadata {
name: cluster_name,
- id: cluster_id,
- transport,
nodes,
})
}
+
+ /// Get actual bound ports from the shard's bound addresses
+ /// This is needed when server binds to port 0 (OS-assigned port)
+ fn get_actual_bound_ports(&self) -> Option<TransportEndpoints> {
+ let tcp_port = self
+ .tcp_bound_address
+ .get()
+ .map(|addr| addr.port())
+ .unwrap_or_else(|| extract_port(&self.config.tcp.address));
+
+ let quic_port = self
+ .quic_bound_address
+ .get()
+ .map(|addr| addr.port())
+ .unwrap_or_else(|| extract_port(&self.config.quic.address));
+
+ let http_port = self
+ .http_bound_address
+ .get()
+ .map(|addr| addr.port())
+ .unwrap_or_else(|| extract_port(&self.config.http.address));
+
+ let websocket_port = self
+ .websocket_bound_address
+ .get()
+ .map(|addr| addr.port())
+ .unwrap_or_else(|| extract_port(&self.config.websocket.address));
+
+ trace!(
+ "Using actual bound ports - TCP: {}, QUIC: {}, HTTP: {}, WebSocket: {}",
+ tcp_port, quic_port, http_port, websocket_port
+ );
+
+ Some(TransportEndpoints::new(
+ tcp_port,
+ quic_port,
+ http_port,
+ websocket_port,
+ ))
+ }
}
diff --git a/core/server/src/streaming/systems/cluster/mod.rs b/core/server/src/streaming/systems/cluster/mod.rs
deleted file mode 100644
index 51161280f..000000000
--- a/core/server/src/streaming/systems/cluster/mod.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-use crate::streaming::session::Session;
-use crate::streaming::systems::system::System;
-use iggy_common::ClusterMetadata;
-use iggy_common::ClusterNode;
-use iggy_common::ClusterNodeRole;
-use iggy_common::ClusterNodeStatus;
-use iggy_common::IggyError;
-use tracing::trace;
-
-impl System {
- pub fn get_cluster_metadata(&self, session: &Session) -> Result<ClusterMetadata, IggyError> {
- trace!("Getting cluster metadata for session: {session}");
-
- if !self.cluster_config.enabled {
- return Err(IggyError::FeatureUnavailable);
- }
-
- // TODO(hubcio): Clustering is not yet implemented
- // The leader/follower as well as node status are currently placeholder implementations.
-
- let name = self.cluster_config.name.clone();
- let id = self.cluster_config.id;
- let transport = self.cluster_config.transport;
-
- let nodes: Vec<ClusterNode> = self
- .cluster_config
- .nodes
- .iter()
- .map(|node_config| {
- let role = if node_config.id == 1 {
- ClusterNodeRole::Leader
- } else {
- ClusterNodeRole::Follower
- };
-
- let status = ClusterNodeStatus::Healthy;
-
- ClusterNode {
- id: node_config.id,
- name: node_config.name.clone(),
- address: node_config.address.clone(),
- role,
- status,
- }
- })
- .collect();
-
- Ok(ClusterMetadata {
- name,
- id,
- transport,
- nodes,
- })
- }
-}
diff --git a/core/server/src/streaming/utils/address.rs b/core/server/src/streaming/utils/address.rs
new file mode 100644
index 000000000..3c51b8e7b
--- /dev/null
+++ b/core/server/src/streaming/utils/address.rs
@@ -0,0 +1,76 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/// Extracts IP from an address string like "127.0.0.1:8090" or "[::1]:8090"
+pub fn extract_ip(address: &str) -> String {
+ if let Some(colon_pos) = address.rfind(':') {
+ // Handle IPv6 addresses like [::1]:8090
+ if address.starts_with('[')
+ && let Some(bracket_pos) = address.rfind(']')
+ {
+ return address[1..bracket_pos].to_string();
+ }
+ // Handle IPv4 addresses like 127.0.0.1:8090
+ return address[..colon_pos].to_string();
+ }
+ address.to_string()
+}
+
+/// Extracts port from an address string like "127.0.0.1:8090"
+pub fn extract_port(address: &str) -> u16 {
+ if let Some(colon_pos) = address.rfind(':')
+ && let Ok(port) = address[colon_pos + 1..].parse::<u16>()
+ {
+ return port;
+ }
+ 0
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_extract_ip_ipv4() {
+ assert_eq!(extract_ip("127.0.0.1:8090"), "127.0.0.1");
+ assert_eq!(extract_ip("192.168.1.100:3000"), "192.168.1.100");
+ }
+
+ #[test]
+ fn test_extract_ip_ipv6() {
+ assert_eq!(extract_ip("[::1]:8090"), "::1");
+ assert_eq!(extract_ip("[2001:db8::1]:443"), "2001:db8::1");
+ }
+
+ #[test]
+ fn test_extract_ip_no_port() {
+ assert_eq!(extract_ip("127.0.0.1"), "127.0.0.1");
+ }
+
+ #[test]
+ fn test_extract_port() {
+ assert_eq!(extract_port("127.0.0.1:8090"), 8090);
+ assert_eq!(extract_port("192.168.1.100:3000"), 3000);
+ assert_eq!(extract_port("[::1]:8090"), 8090);
+ }
+
+ #[test]
+ fn test_extract_port_no_port() {
+ assert_eq!(extract_port("127.0.0.1"), 0);
+ }
+}
diff --git a/core/server/src/streaming/utils/mod.rs b/core/server/src/streaming/utils/mod.rs
index 74f5b7cf8..07896474c 100644
--- a/core/server/src/streaming/utils/mod.rs
+++ b/core/server/src/streaming/utils/mod.rs
@@ -16,6 +16,7 @@
* under the License.
*/
+pub mod address;
pub mod crypto;
pub mod file;
pub mod hash;
diff --git a/foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs b/foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs
index fb518c6ab..a1fc55a8f 100644
--- a/foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs
+++ b/foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs
@@ -15,8 +15,6 @@
// specific language governing permissions and limitations
// under the License.
-using Apache.Iggy.Enums;
-
namespace Apache.Iggy.Contracts;
/// <summary>
@@ -29,16 +27,6 @@ public class ClusterMetadata
/// </summary>
public required string Name { get; set; }
- /// <summary>
- /// Unique identifier of the cluster
- /// </summary>
- public required uint Id { get; set; }
-
- /// <summary>
- /// Transport used for cluster communication
- /// </summary>
- public required Protocol Transport { get; set; }
-
/// <summary>
/// List of all nodes in the cluster
/// </summary>
diff --git a/foreign/csharp/Iggy_SDK/Contracts/ClusterNode.cs b/foreign/csharp/Iggy_SDK/Contracts/ClusterNode.cs
index dfa342738..6a9ee0c8f 100644
--- a/foreign/csharp/Iggy_SDK/Contracts/ClusterNode.cs
+++ b/foreign/csharp/Iggy_SDK/Contracts/ClusterNode.cs
@@ -23,19 +23,19 @@ namespace Apache.Iggy.Contracts;
public class ClusterNode
{
/// <summary>
- /// Node identifier
+ /// Node name
/// </summary>
- public required uint Id { get; set; }
+ public required string Name { get; set; }
/// <summary>
- /// Node name
+ /// Node IP address
/// </summary>
- public required string Name { get; set; }
+ public required string Ip { get; set; }
/// <summary>
- /// Node address
+ /// Transport endpoints (ports) for different protocols
/// </summary>
- public required string Address { get; set; }
+ public required TransportEndpoints Endpoints { get; set; }
/// <summary>
/// Node role within the cluster
@@ -49,7 +49,7 @@ public class ClusterNode
internal int GetSize()
{
- // id, name length, name, address length, address, role, status
- return 4 + 4 + Name.Length + 4 + Address.Length + 1 + 1;
+ // name length, name, ip length, ip, endpoints (4 * 2 bytes), role, status
+ return 4 + Name.Length + 4 + Ip.Length + 8 + 1 + 1;
}
}
diff --git a/foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs b/foreign/csharp/Iggy_SDK/Contracts/TransportEndpoints.cs
similarity index 67%
copy from foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs
copy to foreign/csharp/Iggy_SDK/Contracts/TransportEndpoints.cs
index fb518c6ab..4e4796810 100644
--- a/foreign/csharp/Iggy_SDK/Contracts/ClusterMetadata.cs
+++ b/foreign/csharp/Iggy_SDK/Contracts/TransportEndpoints.cs
@@ -15,32 +15,30 @@
// specific language governing permissions and limitations
// under the License.
-using Apache.Iggy.Enums;
-
namespace Apache.Iggy.Contracts;
/// <summary>
-/// Represents metadata of all nodes in the cluster
+/// Represents transport endpoints (ports) for different protocols
/// </summary>
-public class ClusterMetadata
+public class TransportEndpoints
{
/// <summary>
- /// Name of the cluster
+ /// TCP port
/// </summary>
- public required string Name { get; set; }
+ public required ushort Tcp { get; set; }
/// <summary>
- /// Unique identifier of the cluster
+ /// QUIC port
/// </summary>
- public required uint Id { get; set; }
+ public required ushort Quic { get; set; }
/// <summary>
- /// Transport used for cluster communication
+ /// HTTP port
/// </summary>
- public required Protocol Transport { get; set; }
+ public required ushort Http { get; set; }
/// <summary>
- /// List of all nodes in the cluster
+ /// WebSocket port
/// </summary>
- public required ClusterNode[] Nodes { get; set; } = [];
+ public required ushort WebSocket { get; set; }
}
diff --git a/foreign/csharp/Iggy_SDK/IggyClient/Implementations/TcpMessageStream.cs b/foreign/csharp/Iggy_SDK/IggyClient/Implementations/TcpMessageStream.cs
index 4ca8c1351..3425b1fa0 100644
--- a/foreign/csharp/Iggy_SDK/IggyClient/Implementations/TcpMessageStream.cs
+++ b/foreign/csharp/Iggy_SDK/IggyClient/Implementations/TcpMessageStream.cs
@@ -802,7 +802,9 @@ public sealed class TcpMessageStream : IIggyClient
_stream?.Close();
_stream?.Dispose();
- var connectionAddress = _currentLeaderNode?.Address ?? _configuration.BaseAddress;
+ var connectionAddress = _currentLeaderNode != null
+ ? $"{_currentLeaderNode.Ip}:{_currentLeaderNode.Endpoints.Tcp}"
+ : _configuration.BaseAddress;
var urlPortSplitter = connectionAddress.Split(":");
if (urlPortSplitter.Length > 2)
{
@@ -842,13 +844,14 @@ public sealed class TcpMessageStream : IIggyClient
break;
}
- if (_currentLeaderNode.Address == _configuration.BaseAddress)
+ var currentAddress = $"{_currentLeaderNode.Ip}:{_currentLeaderNode.Endpoints.Tcp}";
+ if (currentAddress == _configuration.BaseAddress)
{
break;
}
_logger.LogInformation("Leader address changed. Trying to reconnect to {Address}",
- _currentLeaderNode.Address);
+ currentAddress);
continue;
}
@@ -898,6 +901,12 @@ public sealed class TcpMessageStream : IIggyClient
return null;
}
+ // Single-node cluster (clustering disabled) - no redirection needed
+ if (clusterMetadata.Nodes.Count() == 1)
+ {
+ return null;
+ }
+
var leaderNode = clusterMetadata.Nodes.FirstOrDefault(x => x.Role == ClusterNodeRole.Leader);
if (leaderNode == null)
{
diff --git a/foreign/csharp/Iggy_SDK/Iggy_SDK.csproj b/foreign/csharp/Iggy_SDK/Iggy_SDK.csproj
index d7a01cf0c..7fe0a5833 100644
--- a/foreign/csharp/Iggy_SDK/Iggy_SDK.csproj
+++ b/foreign/csharp/Iggy_SDK/Iggy_SDK.csproj
@@ -7,7 +7,7 @@
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Apache.Iggy</AssemblyName>
<RootNamespace>Apache.Iggy</RootNamespace>
- <PackageVersion>0.6.0</PackageVersion>
+ <PackageVersion>0.6.0-edge.5</PackageVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
diff --git a/foreign/csharp/Iggy_SDK/Mappers/BinaryMapper.cs b/foreign/csharp/Iggy_SDK/Mappers/BinaryMapper.cs
index 7569ce102..288a0fb5c 100644
--- a/foreign/csharp/Iggy_SDK/Mappers/BinaryMapper.cs
+++ b/foreign/csharp/Iggy_SDK/Mappers/BinaryMapper.cs
@@ -816,12 +816,6 @@ internal static class BinaryMapper
var clusterName = Encoding.UTF8.GetString(payload[4..(4 + (int)nameLength)]);
var position = 4 + (int)nameLength;
- var clusterId = BinaryPrimitives.ReadUInt32LittleEndian(payload[position..(position + 4)]);
- position += 4;
-
- var protocol = (Protocol)payload[position];
- position += 1;
-
var nodesCount = BinaryPrimitives.ReadUInt32LittleEndian(payload[position..(position + 4)]);
position += 4;
@@ -835,38 +829,54 @@ internal static class BinaryMapper
return new ClusterMetadata
{
- Id = clusterId,
Name = clusterName,
- Transport = protocol,
Nodes = nodes
};
}
private static ClusterNode MapClusterNode(ReadOnlySpan<byte> payload)
{
- var id = BinaryPrimitives.ReadUInt32LittleEndian(payload[..4]);
- var position = 4;
+ var position = 0;
+ // Read name
var nameLength = BinaryPrimitives.ReadUInt32LittleEndian(payload[position..(position + 4)]);
position += 4;
var name = Encoding.UTF8.GetString(payload[position..(position + (int)nameLength)]);
position += (int)nameLength;
- var addressLength = BinaryPrimitives.ReadUInt32LittleEndian(payload[position..(position + 4)]);
+ // Read IP
+ var ipLength = BinaryPrimitives.ReadUInt32LittleEndian(payload[position..(position + 4)]);
position += 4;
- var address = Encoding.UTF8.GetString(payload[position..(position + (int)addressLength)]);
- position += (int)addressLength;
+ var ip = Encoding.UTF8.GetString(payload[position..(position + (int)ipLength)]);
+ position += (int)ipLength;
+ // Read transport endpoints (4 ports, each 2 bytes)
+ var tcp = BinaryPrimitives.ReadUInt16LittleEndian(payload[position..(position + 2)]);
+ position += 2;
+ var quic = BinaryPrimitives.ReadUInt16LittleEndian(payload[position..(position + 2)]);
+ position += 2;
+ var http = BinaryPrimitives.ReadUInt16LittleEndian(payload[position..(position + 2)]);
+ position += 2;
+ var webSocket = BinaryPrimitives.ReadUInt16LittleEndian(payload[position..(position + 2)]);
+ position += 2;
+
+ // Read role and status
var role = (ClusterNodeRole)payload[position++];
var status = (ClusterNodeStatus)payload[position];
return new ClusterNode
{
- Id = id,
Name = name,
- Address = address,
+ Ip = ip,
+ Endpoints = new TransportEndpoints
+ {
+ Tcp = tcp,
+ Quic = quic,
+ Http = http,
+ WebSocket = webSocket
+ },
Role = role,
Status = status
};
diff --git a/foreign/java/gradle.properties b/foreign/java/gradle.properties
index ea001d5bf..7f8d985d2 100644
--- a/foreign/java/gradle.properties
+++ b/foreign/java/gradle.properties
@@ -1,2 +1,2 @@
-version=0.6.0
+version=0.6.0-SNAPSHOT
group=org.apache.iggy
diff --git a/foreign/node/package-lock.json b/foreign/node/package-lock.json
index fff48c83c..87689f327 100644
--- a/foreign/node/package-lock.json
+++ b/foreign/node/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "apache-iggy",
- "version": "0.6.0",
+ "version": "0.6.0-edge.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
diff --git a/foreign/node/package.json b/foreign/node/package.json
index 52d679e87..57ecbcc64 100644
--- a/foreign/node/package.json
+++ b/foreign/node/package.json
@@ -1,7 +1,7 @@
{
"name": "apache-iggy",
"type": "module",
- "version": "0.6.0",
+ "version": "0.6.0-edge.3",
"description": "Official Apache Iggy NodeJS SDK",
"keywords": [
"iggy",
diff --git a/foreign/node/src/e2e/tcp.cluster.e2e.ts b/foreign/node/src/e2e/tcp.cluster.e2e.ts
index dffe8f52c..61f3d47e5 100644
--- a/foreign/node/src/e2e/tcp.cluster.e2e.ts
+++ b/foreign/node/src/e2e/tcp.cluster.e2e.ts
@@ -25,20 +25,28 @@ import { getTestClient } from "./test-client.utils.js";
// response is mocked from /core/configs/server.toml
const expectedMeta = {
name: "iggy-cluster",
- id: 0,
- transport: "TCP",
nodes: [
{
- id: 0,
name: "iggy-node-1",
- address: "127.0.0.1:8090",
+ ip: "127.0.0.1",
+ endpoints: {
+ tcp: 8090,
+ quic: 8080,
+ http: 3000,
+ websocket: 8092,
+ },
role: "Leader",
status: "Healthy",
},
{
- id: 1,
name: "iggy-node-2",
- address: "127.0.0.1:8091",
+ ip: "127.0.0.1",
+ endpoints: {
+ tcp: 8091,
+ quic: 8081,
+ http: 3001,
+ websocket: 8093,
+ },
role: "Follower",
status: "Healthy",
},
diff --git a/foreign/node/src/wire/cluster/cluster.type.ts b/foreign/node/src/wire/cluster/cluster.type.ts
index e0cbe6af0..1dbe67a78 100644
--- a/foreign/node/src/wire/cluster/cluster.type.ts
+++ b/foreign/node/src/wire/cluster/cluster.type.ts
@@ -51,7 +51,8 @@ export const ReverseClusterNodeStatus = reverseRecord(ClusterNodeStatus);
export const TransportProtocol = {
TCP: 1,
QUIC: 2,
- HTTP: 3
+ HTTP: 3,
+ WebSocket: 4
} as const;
export type TransportProtocol = typeof TransportProtocol;
diff --git a/foreign/node/src/wire/cluster/cluster.utils.ts b/foreign/node/src/wire/cluster/cluster.utils.ts
index 2913389f5..5f8411246 100644
--- a/foreign/node/src/wire/cluster/cluster.utils.ts
+++ b/foreign/node/src/wire/cluster/cluster.utils.ts
@@ -22,24 +22,29 @@ import { deserializeError } from '../error.utils.js';
import {
type ClusterNodeRoleKey,
type ClusterNodeStatusKey,
- type TransportProtocolKey,
mapClusterNodeRole,
mapClusterNodeStatus,
- mapTransportProtocol,
} from './cluster.type.js';
+export type TransportEndpoints = {
+ tcp: number
+ quic: number
+ http: number
+ websocket: number
+}
+
export type ClusterNode = {
- id: number
name: string
- address: string
+ ip: string
+ endpoints: TransportEndpoints
role: ClusterNodeRoleKey
status: ClusterNodeStatusKey
}
type DeserializedClusterNode = { length: number, data: ClusterNode }
-const CLUSTER_NODE_MIN_BUFFER_SIZE = 16; // 4 + 1 + 4 + 1 + 4 + 1 + 1;
+const CLUSTER_NODE_MIN_BUFFER_SIZE = 18; // 4 + 1 + 4 + 1 + 8 (endpoints) + 1 + 1;
export const deserializeNode = (b: Buffer, pos = 0): DeserializedClusterNode => {
if (b.length - pos < CLUSTER_NODE_MIN_BUFFER_SIZE)
@@ -47,30 +52,46 @@ export const deserializeNode = (b: Buffer, pos = 0): DeserializedClusterNode =>
'cluster node', pos, b.length, CLUSTER_NODE_MIN_BUFFER_SIZE
);
- const id = b.readUInt32LE(pos);
- pos += 4;
+ const startPos = pos;
+ // Read name
const nameLen = b.readUInt32LE(pos);
if (b.length - pos < 4 + nameLen)
deserializeError(
- 'cluster node', pos, b.length, 4 + nameLen, { id, nameLen }
+ 'cluster node', pos, b.length, 4 + nameLen, { nameLen }
);
const name = b.subarray(pos + 4, pos + 4 + nameLen).toString();
pos += nameLen + 4;
- const addrLen = b.readUInt32LE(pos);
- if (b.length - pos < 4 + addrLen)
+ // Read IP
+ const ipLen = b.readUInt32LE(pos);
+ if (b.length - pos < 4 + ipLen)
deserializeError(
- 'cluster node', pos, b.length, 4 + addrLen, { id, nameLen, name, addrLen }
+ 'cluster node', pos, b.length, 4 + ipLen, { nameLen, name, ipLen }
);
- const address = b.subarray(pos + 4, pos + 4 + addrLen).toString();
- pos += addrLen + 4;
+ const ip = b.subarray(pos + 4, pos + 4 + ipLen).toString();
+ pos += ipLen + 4;
+
+ // Read transport endpoints (4 ports, each u16)
+ if (b.length - pos < 8)
+ deserializeError(
+ 'cluster node endpoints', pos, b.length, 8, { nameLen, name, ipLen, ip }
+ );
+ const endpoints: TransportEndpoints = {
+ tcp: b.readUInt16LE(pos),
+ quic: b.readUInt16LE(pos + 2),
+ http: b.readUInt16LE(pos + 4),
+ websocket: b.readUInt16LE(pos + 6)
+ };
+ pos += 8;
+
+ // Read role and status
if (b.length - pos < 2)
deserializeError(
- 'cluster node', pos, b.length, 2, { id, nameLen, name, addrLen, address }
+ 'cluster node', pos, b.length, 2, { nameLen, name, ipLen, ip }
);
const role = mapClusterNodeRole(b.readUInt8(pos));
@@ -80,11 +101,11 @@ export const deserializeNode = (b: Buffer, pos = 0): DeserializedClusterNode =>
pos += 1;
return {
- length: 4 + nameLen + 4 + addrLen + 4 + 1 + 1,
+ length: pos - startPos,
data: {
- id,
name,
- address,
+ ip,
+ endpoints,
role,
status
}
@@ -94,17 +115,12 @@ export const deserializeNode = (b: Buffer, pos = 0): DeserializedClusterNode =>
export type ClusterMetadata = {
// Name of the cluster.
name: string,
- // Unique identifier of the cluster.
- id: number,
- // Transport used for cluster communication
- // (for binary protocol it's u8, 1=TCP, 2=QUIC, 3=HTTP).
- transport: TransportProtocolKey,
// List of all nodes in the cluster.
nodes: ClusterNode[],
};
-// min = 4 + 1 + 4 + 1 + 1 + 4 + CLUSTER_NODE_MIN_BUFFER_SIZE;
-const CLUSTER_METADATA_MIN_SIZE = 15 + CLUSTER_NODE_MIN_BUFFER_SIZE;
+// min = 4 + 1 + 4 + CLUSTER_NODE_MIN_BUFFER_SIZE;
+const CLUSTER_METADATA_MIN_SIZE = 8 + CLUSTER_NODE_MIN_BUFFER_SIZE;
export const deserializeMetadata = (b: Buffer, pos = 0): ClusterMetadata => {
if (b.length - pos < CLUSTER_METADATA_MIN_SIZE)
@@ -112,6 +128,7 @@ export const deserializeMetadata = (b: Buffer, pos = 0): ClusterMetadata => {
'cluster metadata', pos, b.length, CLUSTER_METADATA_MIN_SIZE
);
+ // Read cluster name
const nameLen = b.readUInt32LE(pos);
if (b.length - pos < 4 + nameLen)
deserializeError(
@@ -121,20 +138,16 @@ export const deserializeMetadata = (b: Buffer, pos = 0): ClusterMetadata => {
const name = b.subarray(pos + 4, pos + 4 + nameLen).toString();
pos += nameLen + 4;
- if (b.length - pos < 4 + 1 + 4)
+ // Read nodes count
+ if (b.length - pos < 4)
deserializeError(
- 'cluster metadata', pos, b.length, 4 + 1 + 4, { nameLen, name }
+ 'cluster metadata', pos, b.length, 4, { nameLen, name }
);
- const id = b.readUInt32LE(pos);
- pos += 4;
-
- const transport = mapTransportProtocol(b.readUInt8(pos));
- pos += 1;
-
const nodeCount = b.readUInt32LE(pos);
pos += 4;
+ // Read nodes array
const nodes: ClusterNode[] = [];
for (let i = 0; i < nodeCount; i++) {
const { length, data } = deserializeNode(b, pos);
@@ -144,8 +157,6 @@ export const deserializeMetadata = (b: Buffer, pos = 0): ClusterMetadata => {
return {
name,
- id,
- transport,
nodes
}
};
diff --git a/foreign/python/Cargo.toml b/foreign/python/Cargo.toml
index 4714587f7..e695cea81 100644
--- a/foreign/python/Cargo.toml
+++ b/foreign/python/Cargo.toml
@@ -17,7 +17,7 @@
[package]
name = "apache-iggy"
-version = "0.6.0"
+version = "0.6.0-dev2"
edition = "2021"
authors = ["Dario Lencina Talarico <da...@gmail.com>", "Albin Skott <al...@mattsson.io>"]
license = "Apache-2.0"
@@ -27,7 +27,7 @@ repository = "https://github.com/apache/iggy"
[dependencies]
bytes = "1.10.1"
-iggy = { path = "../../core/sdk", version = "0.8.0" }
+iggy = { path = "../../core/sdk", version = "0.8.0-edge.6" }
pyo3 = "0.26.0"
pyo3-async-runtimes = { version = "0.26.0", features = [
"attributes",
diff --git a/foreign/python/pyproject.toml b/foreign/python/pyproject.toml
index 6d918ab9a..a5828c936 100644
--- a/foreign/python/pyproject.toml
+++ b/foreign/python/pyproject.toml
@@ -22,7 +22,7 @@ build-backend = "maturin"
[project]
name = "apache-iggy"
requires-python = ">=3.7"
-version = "0.6.0"
+version = "0.6.0-dev2"
description = "Apache Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second."
readme = "README.md"
license = { file = "LICENSE" }
diff --git a/web/package.json b/web/package.json
index df3c3a53a..6b47f3217 100644
--- a/web/package.json
+++ b/web/package.json
@@ -1,6 +1,6 @@
{
"name": "iggy-web-ui",
- "version": "0.1.0",
+ "version": "0.1.0-edge.2",
"private": true,
"scripts": {
"dev": "vite dev --port 3050",