krishvishal commented on code in PR #2620:
URL: https://github.com/apache/iggy/pull/2620#discussion_r2745418975


##########
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>>;
+
+    /// Get stored consumer offset.
+    ///
+    /// Returns the last stored offset, or 0 if none exists.
+    fn get_consumer_offset(
+        &self,
+        consumer: PollingConsumer,
+        namespace: IggyNamespace,
+    ) -> impl Future<Output = Result<u64, Self::Error>>;
+
+    /// Get partition's current commit offset.
+    ///
+    /// Returns the highest committed offset (visible to consumers).
+    /// In clustered mode, may lag slightly behind the primary.
+    fn get_offset(
+        &self,
+        namespace: IggyNamespace,
+    ) -> impl Future<Output = Result<u64, Self::Error>>;
+
+    /// Initialize storage for a new partition.
+    ///
+    /// Sets up segments directory, initial segment, and offset tracking.
+    fn create_partition(
+        &self,
+        namespace: IggyNamespace,
+    ) -> impl Future<Output = Result<(), Self::Error>>;
+
+    /// Delete partition and all its data.
+    ///
+    /// Removes messages, segments, indexes, and consumer offsets.
+    fn delete_partition(
+        &self,
+        namespace: IggyNamespace,
+    ) -> impl Future<Output = Result<(), Self::Error>>;
+
+    /// Purge all messages, preserving partition structure.
+    ///
+    /// Resets offset to 0. Consumer offsets become invalid.
+    fn purge_partition(
+        &self,
+        namespace: IggyNamespace,
+    ) -> impl Future<Output = Result<(), Self::Error>>;
+}
+
+/// Low-level partition storage operations for the consensus layer.
+///
+/// This trait is the interface between VSR consensus and the underlying
+/// storage engine. It provides the primitives needed for:
+///
+/// - **Prepare phase**: Durably storing messages before acknowledgment
+/// - **Commit phase**: Advancing the visibility boundary
+/// - **Read path**: Reading committed messages for consumers
+/// - **Recovery**: Reconstructing consensus state after restart
+pub trait PartitionStorage {

Review Comment:
   As discussed. I've removed this trait for now.



-- 
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]

Reply via email to