You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by gk...@apache.org on 2025/11/25 18:29:42 UTC
(iggy) branch add_message_bus_and_vsr_consensus created (now b1bc475ea)
This is an automated email from the ASF dual-hosted git repository.
gkoszyk pushed a change to branch add_message_bus_and_vsr_consensus
in repository https://gitbox.apache.org/repos/asf/iggy.git
at b1bc475ea feat(cluster): add message_bus module and vsr consesus stub
This branch includes the following new commits:
new b1bc475ea feat(cluster): add message_bus module and vsr consesus stub
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(iggy) 01/01: feat(cluster): add message_bus module and vsr consesus stub
Posted by gk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gkoszyk pushed a commit to branch add_message_bus_and_vsr_consensus
in repository https://gitbox.apache.org/repos/asf/iggy.git
commit b1bc475eae76a7197dc5ee3891a00793312fbb66
Author: numminex <g....@gmail.com>
AuthorDate: Tue Nov 25 19:29:32 2025 +0100
feat(cluster): add message_bus module and vsr consesus stub
---
Cargo.lock | 16 ++++++++++++++++
Cargo.toml | 2 +-
core/consensus/Cargo.toml | 2 +-
core/consensus/src/impls.rs | 24 +++++++++++++++++++++++-
core/consensus/src/lib.rs | 9 +++++++--
core/{metadata => journal}/Cargo.toml | 6 +++---
core/{consensus => journal}/src/lib.rs | 26 ++++++--------------------
core/{consensus => message_bus}/Cargo.toml | 5 ++---
core/{consensus => message_bus}/src/lib.rs | 21 +++------------------
core/metadata/Cargo.toml | 2 +-
core/metadata/src/impls/metadata.rs | 24 ++++++++++++++++++++----
11 files changed, 83 insertions(+), 54 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 7f9717f85..739f32f07 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1920,6 +1920,9 @@ dependencies = [
[[package]]
name = "consensus"
version = "0.1.0"
+dependencies = [
+ "message_bus",
+]
[[package]]
name = "console"
@@ -5258,6 +5261,14 @@ dependencies = [
"libc",
]
+[[package]]
+name = "journal"
+version = "0.1.0"
+dependencies = [
+ "consensus",
+ "tracing",
+]
+
[[package]]
name = "js-sys"
version = "0.3.82"
@@ -5751,11 +5762,16 @@ version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
+[[package]]
+name = "message_bus"
+version = "0.1.0"
+
[[package]]
name = "metadata"
version = "0.1.0"
dependencies = [
"consensus",
+ "journal",
"tracing",
]
diff --git a/Cargo.toml b/Cargo.toml
index 39c8e1ea0..aa762a788 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -40,7 +40,7 @@ members = [
"core/connectors/sources/postgres_source",
"core/connectors/sources/random_source",
"core/consensus",
- "core/integration",
+ "core/integration", "core/journal", "core/message_bus",
"core/metadata",
"core/sdk",
"core/server",
diff --git a/core/consensus/Cargo.toml b/core/consensus/Cargo.toml
index d2af60528..513b817d4 100644
--- a/core/consensus/Cargo.toml
+++ b/core/consensus/Cargo.toml
@@ -22,12 +22,12 @@ description = "Iggy consensus module"
edition = "2024"
license = "Apache-2.0"
keywords = ["iggy", "messaging", "streaming"]
-categories = ["command-line-utilities", "database", "network-programming"]
homepage = "https://iggy.apache.org"
documentation = "https://iggy.apache.org/docs"
repository = "https://github.com/apache/iggy"
readme = "../../../README.md"
[dependencies]
+message_bus = { path = "../message_bus" }
diff --git a/core/consensus/src/impls.rs b/core/consensus/src/impls.rs
index e6951017e..52cb6f1bf 100644
--- a/core/consensus/src/impls.rs
+++ b/core/consensus/src/impls.rs
@@ -15,9 +15,25 @@
// specific language governing permissions and limitations
// under the License.
+use std::cell::Cell;
use crate::{Consensus, Project};
+use message_bus::IggyMessageBus;
-pub struct VsrConsensus;
+pub struct VsrConsensus {
+ op: Cell<u64>,
+}
+
+impl VsrConsensus {
+ pub fn advance_commit_number(&self) {}
+
+ pub fn update_op(&self, op: u64) {
+ self.op.set(op);
+ }
+
+ pub fn op(&self) -> u64 {
+ self.op.get()
+ }
+}
#[derive(Clone)]
pub struct Request;
@@ -43,6 +59,8 @@ impl Project<PrepareOk> for Prepare {
pub struct PrepareOk;
impl Consensus for VsrConsensus {
+ type MessageBus = IggyMessageBus;
+
type RequestMessage = Request;
type ReplicateMessage = Prepare;
type AckMessage = PrepareOk;
@@ -58,4 +76,8 @@ impl Consensus for VsrConsensus {
fn post_replicate_verify(&self, _message: &Self::ReplicateMessage) {
todo!()
}
+
+ fn is_follower(&self) -> bool {
+ todo!()
+ }
}
diff --git a/core/consensus/src/lib.rs b/core/consensus/src/lib.rs
index 60737e1fd..d75f2f79e 100644
--- a/core/consensus/src/lib.rs
+++ b/core/consensus/src/lib.rs
@@ -15,12 +15,15 @@
// specific language governing permissions and limitations
// under the License.
-pub trait Project<U> {
+use message_bus::MessageBus;
+
+pub trait Project<T> {
type Consensus: Consensus;
- fn project(self, consensus: &Self::Consensus) -> U;
+ fn project(self, consensus: &Self::Consensus) -> T;
}
pub trait Consensus {
+ type MessageBus: MessageBus;
// I am wondering, whether we should create a dedicated trait for cloning, so it's explicit that we do ref counting.
type RequestMessage: Project<Self::ReplicateMessage, Consensus = Self> + Clone;
type ReplicateMessage: Project<Self::AckMessage, Consensus = Self> + Clone;
@@ -31,6 +34,8 @@ pub trait Consensus {
// TODO: Figure out how we can achieve that without exposing such methods in the Consensus trait.
fn post_replicate_verify(&self, message: &Self::ReplicateMessage);
+
+ fn is_follower(&self) -> bool;
}
mod impls;
diff --git a/core/metadata/Cargo.toml b/core/journal/Cargo.toml
similarity index 91%
copy from core/metadata/Cargo.toml
copy to core/journal/Cargo.toml
index c43490878..c413fed07 100644
--- a/core/metadata/Cargo.toml
+++ b/core/journal/Cargo.toml
@@ -16,13 +16,12 @@
# under the License.
[package]
-name = "metadata"
+name = "journal"
version = "0.1.0"
-description = "Iggy metadata module"
+description = "Iggy journal module"
edition = "2024"
license = "Apache-2.0"
keywords = ["iggy", "messaging", "streaming"]
-categories = ["database", "network-programming"]
homepage = "https://iggy.apache.org"
documentation = "https://iggy.apache.org/docs"
repository = "https://github.com/apache/iggy"
@@ -31,3 +30,4 @@ readme = "../../../README.md"
[dependencies]
consensus = { path = "../consensus" }
tracing = { workspace = true }
+
diff --git a/core/consensus/src/lib.rs b/core/journal/src/lib.rs
similarity index 51%
copy from core/consensus/src/lib.rs
copy to core/journal/src/lib.rs
index 60737e1fd..4af87cda2 100644
--- a/core/consensus/src/lib.rs
+++ b/core/journal/src/lib.rs
@@ -15,23 +15,9 @@
// specific language governing permissions and limitations
// under the License.
-pub trait Project<U> {
- type Consensus: Consensus;
- fn project(self, consensus: &Self::Consensus) -> U;
-}
-
-pub trait Consensus {
- // I am wondering, whether we should create a dedicated trait for cloning, so it's explicit that we do ref counting.
- type RequestMessage: Project<Self::ReplicateMessage, Consensus = Self> + Clone;
- type ReplicateMessage: Project<Self::AckMessage, Consensus = Self> + Clone;
- type AckMessage;
-
- fn pipeline_message(&self, message: Self::ReplicateMessage);
- fn verify_pipeline(&self);
-
- // TODO: Figure out how we can achieve that without exposing such methods in the Consensus trait.
- fn post_replicate_verify(&self, message: &Self::ReplicateMessage);
-}
-
-mod impls;
-pub use impls::*;
+// TODO: We already have a `Journal` trait inside of the `storage` module `journal.rs` file.
+// But the interface was designed for partition log, not an generic journal.
+pub trait Journal {
+ type Entry;
+ fn append(&self, entry: Self::Entry) -> impl Future<Output = ()>;
+}
\ No newline at end of file
diff --git a/core/consensus/Cargo.toml b/core/message_bus/Cargo.toml
similarity index 89%
copy from core/consensus/Cargo.toml
copy to core/message_bus/Cargo.toml
index d2af60528..713b8fec9 100644
--- a/core/consensus/Cargo.toml
+++ b/core/message_bus/Cargo.toml
@@ -16,13 +16,12 @@
# under the License.
[package]
-name = "consensus"
+name = "message_bus"
version = "0.1.0"
-description = "Iggy consensus module"
+description = "Iggy message bus module"
edition = "2024"
license = "Apache-2.0"
keywords = ["iggy", "messaging", "streaming"]
-categories = ["command-line-utilities", "database", "network-programming"]
homepage = "https://iggy.apache.org"
documentation = "https://iggy.apache.org/docs"
repository = "https://github.com/apache/iggy"
diff --git a/core/consensus/src/lib.rs b/core/message_bus/src/lib.rs
similarity index 52%
copy from core/consensus/src/lib.rs
copy to core/message_bus/src/lib.rs
index 60737e1fd..b6c4b5de2 100644
--- a/core/consensus/src/lib.rs
+++ b/core/message_bus/src/lib.rs
@@ -15,23 +15,8 @@
// specific language governing permissions and limitations
// under the License.
-pub trait Project<U> {
- type Consensus: Consensus;
- fn project(self, consensus: &Self::Consensus) -> U;
-}
+pub trait MessageBus {}
-pub trait Consensus {
- // I am wondering, whether we should create a dedicated trait for cloning, so it's explicit that we do ref counting.
- type RequestMessage: Project<Self::ReplicateMessage, Consensus = Self> + Clone;
- type ReplicateMessage: Project<Self::AckMessage, Consensus = Self> + Clone;
- type AckMessage;
+pub struct IggyMessageBus;
- fn pipeline_message(&self, message: Self::ReplicateMessage);
- fn verify_pipeline(&self);
-
- // TODO: Figure out how we can achieve that without exposing such methods in the Consensus trait.
- fn post_replicate_verify(&self, message: &Self::ReplicateMessage);
-}
-
-mod impls;
-pub use impls::*;
+impl MessageBus for IggyMessageBus {}
diff --git a/core/metadata/Cargo.toml b/core/metadata/Cargo.toml
index c43490878..9c4eb7170 100644
--- a/core/metadata/Cargo.toml
+++ b/core/metadata/Cargo.toml
@@ -22,7 +22,6 @@ description = "Iggy metadata module"
edition = "2024"
license = "Apache-2.0"
keywords = ["iggy", "messaging", "streaming"]
-categories = ["database", "network-programming"]
homepage = "https://iggy.apache.org"
documentation = "https://iggy.apache.org/docs"
repository = "https://github.com/apache/iggy"
@@ -31,3 +30,4 @@ readme = "../../../README.md"
[dependencies]
consensus = { path = "../consensus" }
tracing = { workspace = true }
+journal = { path = "../journal" }
diff --git a/core/metadata/src/impls/metadata.rs b/core/metadata/src/impls/metadata.rs
index 924ffa06f..04604e05d 100644
--- a/core/metadata/src/impls/metadata.rs
+++ b/core/metadata/src/impls/metadata.rs
@@ -15,14 +15,17 @@
// specific language governing permissions and limitations
// under the License.
use consensus::{Consensus, Prepare, Project, VsrConsensus};
+use journal::Journal;
use tracing::{debug, warn};
// TODO: Define a trait (probably in some external crate)
#[expect(unused)]
trait Metadata {
type Consensus: Consensus;
+ type Journal: Journal<Entry = <Self::Consensus as Consensus>::ReplicateMessage>;
+
fn on_request(&self, message: <Self::Consensus as Consensus>::RequestMessage);
- fn on_replicate(&self, message: <Self::Consensus as Consensus>::ReplicateMessage);
+ fn on_replicate(&self, message: <Self::Consensus as Consensus>::ReplicateMessage) -> impl Future<Output = ()>;
fn on_ack(&self, message: <Self::Consensus as Consensus>::AckMessage);
}
@@ -34,8 +37,12 @@ struct IggyMetadata<M, J, S> {
snapshot: S,
}
-impl<M, J, S> Metadata for IggyMetadata<M, J, S> {
+impl<M, J, S> Metadata for IggyMetadata<M, J, S>
+where
+ J: Journal<Entry = Prepare>,
+{
type Consensus = VsrConsensus;
+ type Journal = J;
fn on_request(&self, message: <Self::Consensus as Consensus>::RequestMessage) {
// TODO: Bunch of asserts.
debug!("handling metadata request");
@@ -43,12 +50,18 @@ impl<M, J, S> Metadata for IggyMetadata<M, J, S> {
self.pipeline_prepare(prepare);
}
- fn on_replicate(&self, message: <Self::Consensus as Consensus>::ReplicateMessage) {
+ async fn on_replicate(&self, message: <Self::Consensus as Consensus>::ReplicateMessage) {
if !self.fence_old_prepare(&message) {
self.replicate(message.clone());
} else {
warn!("received old prepare, not replicating");
}
+
+ if self.consensus.is_follower() {
+ self.consensus.advance_commit_number();
+ }
+ //self.consensus.update_op(header.op());
+ self.journal.append(message).await;
}
fn on_ack(&self, _message: <Self::Consensus as Consensus>::AckMessage) {
@@ -56,7 +69,10 @@ impl<M, J, S> Metadata for IggyMetadata<M, J, S> {
}
}
-impl<M, J, S> IggyMetadata<M, J, S> {
+impl<M, J, S> IggyMetadata<M, J, S>
+where
+ J: Journal<Entry = Prepare>,
+{
#[expect(unused)]
fn pipeline_prepare(&self, prepare: Prepare) {
debug!("inserting prepare into metadata pipeline");