diff --git a/openraft/src/core/sm/response.rs b/openraft/src/core/sm/response.rs index 4790e84f5..a563b8f70 100644 --- a/openraft/src/core/sm/response.rs +++ b/openraft/src/core/sm/response.rs @@ -10,12 +10,12 @@ pub(crate) enum Response where C: RaftTypeConfig { /// Build a snapshot, it returns result via the universal RaftCore response channel. - BuildSnapshot(SnapshotMeta), + BuildSnapshot(SnapshotMeta), /// When finishing installing a snapshot. /// /// It does not return any value to RaftCore. - InstallSnapshot(Option>), + InstallSnapshot(Option>), /// Send back applied result to RaftCore. Apply(ApplyResult), diff --git a/openraft/src/engine/engine_impl.rs b/openraft/src/engine/engine_impl.rs index 3c587761f..ed75232ed 100644 --- a/openraft/src/engine/engine_impl.rs +++ b/openraft/src/engine/engine_impl.rs @@ -522,7 +522,7 @@ where C: RaftTypeConfig /// - Engine only keeps the snapshot meta with the greatest last-log-id; /// - and a snapshot smaller than last-committed is not allowed to be installed. #[tracing::instrument(level = "debug", skip_all)] - pub(crate) fn finish_building_snapshot(&mut self, meta: SnapshotMeta) { + pub(crate) fn finish_building_snapshot(&mut self, meta: SnapshotMeta) { tracing::info!(snapshot_meta = display(&meta), "{}", func_name!()); self.state.io_state_mut().set_building_snapshot(false); diff --git a/openraft/src/engine/handler/snapshot_handler/mod.rs b/openraft/src/engine/handler/snapshot_handler/mod.rs index 1ab398c83..206154665 100644 --- a/openraft/src/engine/handler/snapshot_handler/mod.rs +++ b/openraft/src/engine/handler/snapshot_handler/mod.rs @@ -49,7 +49,7 @@ where C: RaftTypeConfig /// /// [`RaftStateMachine`]: crate::storage::RaftStateMachine #[tracing::instrument(level = "debug", skip_all)] - pub(crate) fn update_snapshot(&mut self, meta: SnapshotMeta) -> bool { + pub(crate) fn update_snapshot(&mut self, meta: SnapshotMeta) -> bool { tracing::info!("update_snapshot: {:?}", meta); if meta.last_log_id <= self.state.snapshot_last_log_id().copied() { diff --git a/openraft/src/raft/message/install_snapshot.rs b/openraft/src/raft/message/install_snapshot.rs index f48806db9..73be4dd2e 100644 --- a/openraft/src/raft/message/install_snapshot.rs +++ b/openraft/src/raft/message/install_snapshot.rs @@ -14,7 +14,7 @@ pub struct InstallSnapshotRequest { pub vote: Vote, /// Metadata of a snapshot: snapshot_id, last_log_ed membership etc. - pub meta: SnapshotMeta, + pub meta: SnapshotMeta, /// The byte offset where this chunk of data is positioned in the snapshot file. pub offset: u64, diff --git a/openraft/src/raft_state/mod.rs b/openraft/src/raft_state/mod.rs index 7382b941e..89b305cc3 100644 --- a/openraft/src/raft_state/mod.rs +++ b/openraft/src/raft_state/mod.rs @@ -70,7 +70,7 @@ where C: RaftTypeConfig pub membership_state: MembershipState, /// The metadata of the last snapshot. - pub snapshot_meta: SnapshotMeta, + pub snapshot_meta: SnapshotMeta, // -- // -- volatile fields: they are not persisted. diff --git a/openraft/src/replication/callbacks.rs b/openraft/src/replication/callbacks.rs index 867c7b331..88b30e5ca 100644 --- a/openraft/src/replication/callbacks.rs +++ b/openraft/src/replication/callbacks.rs @@ -20,7 +20,7 @@ pub(crate) struct SnapshotCallback { pub(crate) start_time: InstantOf, /// Meta data of the snapshot to be replicated. - pub(crate) snapshot_meta: SnapshotMeta, + pub(crate) snapshot_meta: SnapshotMeta, /// The result of the snapshot replication. pub(crate) result: Result, StreamingError>>, @@ -29,7 +29,7 @@ pub(crate) struct SnapshotCallback { impl SnapshotCallback { pub(in crate::replication) fn new( start_time: InstantOf, - snapshot_meta: SnapshotMeta, + snapshot_meta: SnapshotMeta, result: Result, StreamingError>>, ) -> Self { Self { diff --git a/openraft/src/replication/request.rs b/openraft/src/replication/request.rs index 7f1f15988..9cfb56873 100644 --- a/openraft/src/replication/request.rs +++ b/openraft/src/replication/request.rs @@ -150,7 +150,7 @@ where C: RaftTypeConfig pub(crate) fn new_snapshot_callback( request_id: RequestId, start_time: InstantOf, - snapshot_meta: SnapshotMeta, + snapshot_meta: SnapshotMeta, result: Result, StreamingError>>, ) -> Self { Self::SnapshotCallback(DataWithId::new( diff --git a/openraft/src/storage/mod.rs b/openraft/src/storage/mod.rs index 458a6e353..79873e14d 100644 --- a/openraft/src/storage/mod.rs +++ b/openraft/src/storage/mod.rs @@ -19,13 +19,11 @@ pub use v2::RaftLogStorageExt; pub use v2::RaftStateMachine; use crate::display_ext::DisplayOption; -use crate::node::Node; use crate::raft_types::SnapshotId; pub use crate::storage::callback::LogApplied; pub use crate::storage::callback::LogFlushed; use crate::LogId; use crate::MessageSummary; -use crate::NodeId; use crate::OptionalSend; use crate::OptionalSync; use crate::RaftTypeConfig; @@ -34,16 +32,14 @@ use crate::StoredMembership; #[derive(Debug, Clone, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))] -pub struct SnapshotMeta -where - NID: NodeId, - N: Node, +pub struct SnapshotMeta +where C: RaftTypeConfig { /// Log entries upto which this snapshot includes, inclusive. - pub last_log_id: Option>, + pub last_log_id: Option>, /// The last applied membership config. - pub last_membership: StoredMembership, + pub last_membership: StoredMembership, /// To identify a snapshot when transferring. /// Caveat: even when two snapshot is built with the same `last_log_id`, they still could be @@ -51,10 +47,8 @@ where pub snapshot_id: SnapshotId, } -impl fmt::Display for SnapshotMeta -where - NID: NodeId, - N: Node, +impl fmt::Display for SnapshotMeta +where C: RaftTypeConfig { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -67,22 +61,18 @@ where } } -impl MessageSummary> for SnapshotMeta -where - NID: NodeId, - N: Node, +impl MessageSummary> for SnapshotMeta +where C: RaftTypeConfig { fn summary(&self) -> String { self.to_string() } } -impl SnapshotMeta -where - NID: NodeId, - N: Node, +impl SnapshotMeta +where C: RaftTypeConfig { - pub fn signature(&self) -> SnapshotSignature { + pub fn signature(&self) -> SnapshotSignature { SnapshotSignature { last_log_id: self.last_log_id, last_membership_log_id: *self.last_membership.log_id(), @@ -90,8 +80,8 @@ where } } - /// Returns a ref to the id of the last log that is included in this snasphot. - pub fn last_log_id(&self) -> Option<&LogId> { + /// Returns a ref to the id of the last log that is included in this snapshot. + pub fn last_log_id(&self) -> Option<&LogId> { self.last_log_id.as_ref() } } @@ -102,7 +92,7 @@ pub struct Snapshot where C: RaftTypeConfig { /// metadata of a snapshot - pub meta: SnapshotMeta, + pub meta: SnapshotMeta, /// A read handle to the associated snapshot. pub snapshot: Box, @@ -112,7 +102,7 @@ impl Snapshot where C: RaftTypeConfig { #[allow(dead_code)] - pub(crate) fn new(meta: SnapshotMeta, snapshot: Box) -> Self { + pub(crate) fn new(meta: SnapshotMeta, snapshot: Box) -> Self { Self { meta, snapshot } } } diff --git a/openraft/src/storage/v2.rs b/openraft/src/storage/v2.rs index 7804ef34a..555b5aa4a 100644 --- a/openraft/src/storage/v2.rs +++ b/openraft/src/storage/v2.rs @@ -221,7 +221,7 @@ where C: RaftTypeConfig /// snapshot. async fn install_snapshot( &mut self, - meta: &SnapshotMeta, + meta: &SnapshotMeta, snapshot: Box, ) -> Result<(), StorageError>; diff --git a/stores/memstore/src/lib.rs b/stores/memstore/src/lib.rs index a0d06f4ba..855ea0ea7 100644 --- a/stores/memstore/src/lib.rs +++ b/stores/memstore/src/lib.rs @@ -89,7 +89,7 @@ openraft::declare_raft_types!( /// The application snapshot type which the `MemStore` works with. #[derive(Debug)] pub struct MemStoreSnapshot { - pub meta: SnapshotMeta, + pub meta: SnapshotMeta, /// The data of the state machine at the time of this snapshot. pub data: Vec, @@ -484,7 +484,7 @@ impl RaftStateMachine for Arc { #[tracing::instrument(level = "trace", skip(self, snapshot))] async fn install_snapshot( &mut self, - meta: &SnapshotMeta, + meta: &SnapshotMeta, snapshot: Box>, ) -> Result<(), StorageError> { tracing::info!( diff --git a/stores/rocksstore/src/lib.rs b/stores/rocksstore/src/lib.rs index 324e6565e..13484d85c 100644 --- a/stores/rocksstore/src/lib.rs +++ b/stores/rocksstore/src/lib.rs @@ -89,7 +89,7 @@ pub struct RocksResponse { #[derive(Serialize, Deserialize, Debug)] pub struct RocksSnapshot { - pub meta: SnapshotMeta, + pub meta: SnapshotMeta, /// The data of the state machine at the time of this snapshot. pub data: Vec, @@ -459,7 +459,7 @@ impl RaftStateMachine for RocksStateMachine { async fn install_snapshot( &mut self, - meta: &SnapshotMeta, + meta: &SnapshotMeta, snapshot: Box>, ) -> Result<(), StorageError> { tracing::info!( diff --git a/stores/sledstore/src/lib.rs b/stores/sledstore/src/lib.rs index d0129b60f..ecaa444ce 100644 --- a/stores/sledstore/src/lib.rs +++ b/stores/sledstore/src/lib.rs @@ -79,7 +79,7 @@ pub struct ExampleResponse { #[derive(Serialize, Deserialize, Debug)] pub struct ExampleSnapshot { - pub meta: SnapshotMeta, + pub meta: SnapshotMeta, /// The data of the state machine at the time of this snapshot. pub data: Vec, @@ -641,7 +641,7 @@ impl RaftStateMachine for Arc { #[tracing::instrument(level = "trace", skip(self, snapshot))] async fn install_snapshot( &mut self, - meta: &SnapshotMeta, + meta: &SnapshotMeta, snapshot: Box>, ) -> Result<(), StorageError> { tracing::info!(