krishvishal commented on code in PR #2620:
URL: https://github.com/apache/iggy/pull/2620#discussion_r2742034384
##########
core/partitions/src/lib.rs:
##########
@@ -19,15 +19,222 @@ mod iggy_partition;
mod iggy_partitions;
mod types;
+use iggy_common::sharding::IggyNamespace;
pub use iggy_partition::IggyPartition;
pub use iggy_partitions::IggyPartitions;
-pub use types::{PollMetadata, PollingArgs, PollingConsumer,
SendMessagesResult};
+pub use types::{
+ AppendResult, PartitionOffsets, PollMetadata, PollingArgs,
PollingConsumer, SendMessagesResult,
+};
-/// The core abstraction for partition operations in clustering.
+/// High-level partition operations for request handlers.
///
-/// This trait defines the data-plane operations for partitions that
-/// need to be coordinated across a cluster using viewstamped replication.
-/// Implementations can vary between single-node and clustered deployments.
+/// This trait abstracts over both single-node vs clustered modes.
+///
+/// # Implementation:
+///
+/// ## Single-node:
+///
+/// ```text
+/// send_messages() ──► storage.append_prepared()
+/// │
+/// ▼
+/// storage.advance_commit()
+/// │
+/// ▼
+/// Return success
+/// ```
+///
+/// ## Clustered
+///
+/// ```text
+/// send_messages() ──► Create Prepare(messages)
+/// │
+/// ▼
+/// Broadcast to replicas
+/// │
+/// ▼
+/// Replicas: storage.append_prepared()
+/// │
+/// ▼
+/// Wait for quorum PrepareOk
+/// │
+/// ▼
+/// storage.advance_commit()
+/// │
+/// ▼
+/// Return success
+/// ```
pub trait Partitions {
- // TODO(hubcio): define partition operations like poll, send, create,
delete, etc.
+ /// The message batch type for write operations.
+ type MessageBatch;
+
+ /// The result type returned from poll operations.
+ type PollResult;
+
+ type Error;
+
+ /// Send messages to a partition.
+ ///
+ /// Messages are appended atomically as a batch with sequentially assigned
+ /// offsets. Returns only:
+ /// - Single-node: after durable local write (fsync)
+ /// - Clustered: after VSR quorum acknowledgment
+ fn send_messages(
+ &self,
+ namespace: IggyNamespace,
+ batch: Self::MessageBatch,
+ ) -> impl Future<Output = Result<SendMessagesResult, Self::Error>>;
+
+ /// Store consumer offset for progress tracking.
+ ///
+ /// Persists the consumer's position, enabling resumption after restarts.
+ fn store_consumer_offset(
+ &self,
+ consumer: PollingConsumer,
+ namespace: IggyNamespace,
+ offset: u64,
+ ) -> impl Future<Output = Result<(), Self::Error>>;
+
+ /// Poll messages from a partition.
+ ///
+ /// Returns only **committed** messages according to the polling strategy.
+ /// Messages that are prepared but not yet committed are not visible.
+ fn poll_messages(
+ &self,
+ consumer: PollingConsumer,
+ namespace: IggyNamespace,
+ args: PollingArgs,
+ ) -> impl Future<Output = Result<(Self::PollResult, PollMetadata),
Self::Error>>;
Review Comment:
Done. Removed it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]