Skip to content

Commit

Permalink
Refactor: Move storage struct into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Aug 15, 2024
1 parent 2ae4550 commit e54a1fd
Show file tree
Hide file tree
Showing 35 changed files with 402 additions and 358 deletions.
2 changes: 1 addition & 1 deletion openraft/src/core/raft_msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use crate::raft::AppendEntriesResponse;
use crate::raft::SnapshotResponse;
use crate::raft::VoteRequest;
use crate::raft::VoteResponse;
use crate::storage::Snapshot;
use crate::type_config::alias::LogIdOf;
use crate::type_config::alias::OneshotSenderOf;
use crate::type_config::alias::ResponderOf;
use crate::type_config::alias::SnapshotDataOf;
use crate::ChangeMembers;
use crate::RaftState;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::Vote;

pub(crate) mod external_command;
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/core/sm/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::base::BoxAny;
use crate::core::raft_msg::ResultSender;
use crate::error::Infallible;
use crate::raft_state::IOId;
use crate::storage::Snapshot;
use crate::type_config::alias::LogIdOf;
use crate::type_config::alias::SnapshotDataOf;
use crate::RaftTypeConfig;
use crate::Snapshot;

/// The payload of a state machine command.
pub(crate) enum Command<C>
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/core/sm/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use crate::async_runtime::MpscUnboundedSender;
use crate::async_runtime::MpscUnboundedWeakSender;
use crate::async_runtime::SendError;
use crate::core::sm;
use crate::storage::Snapshot;
use crate::type_config::alias::JoinHandleOf;
use crate::type_config::alias::MpscUnboundedSenderOf;
use crate::type_config::alias::MpscUnboundedWeakSenderOf;
use crate::type_config::TypeConfigExt;
use crate::RaftTypeConfig;
use crate::Snapshot;

/// State machine worker handle for sending command to it.
pub(crate) struct Handle<C>
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/core/sm/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::core::ApplyResult;
use crate::display_ext::display_result::DisplayResultExt;
use crate::display_ext::DisplayOptionExt;
use crate::raft_state::IOId;
use crate::storage::SnapshotMeta;
use crate::RaftTypeConfig;
use crate::SnapshotMeta;
use crate::StorageError;

/// The Ok part of a state machine command result.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/core/sm/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::display_ext::DisplayOptionExt;
use crate::display_ext::DisplaySliceExt;
use crate::entry::RaftPayload;
use crate::storage::RaftStateMachine;
use crate::storage::Snapshot;
use crate::type_config::alias::JoinHandleOf;
use crate::type_config::alias::LogIdOf;
use crate::type_config::alias::MpscUnboundedReceiverOf;
Expand All @@ -26,7 +27,6 @@ use crate::RaftLogId;
use crate::RaftLogReader;
use crate::RaftSnapshotBuilder;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::StorageError;

pub(crate) struct Worker<C, SM, LR>
Expand Down
4 changes: 2 additions & 2 deletions openraft/src/engine/engine_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use crate::raft::VoteResponse;
use crate::raft_state::IOId;
use crate::raft_state::LogStateReader;
use crate::raft_state::RaftState;
use crate::storage::Snapshot;
use crate::storage::SnapshotMeta;
use crate::type_config::alias::ResponderOf;
use crate::type_config::alias::SnapshotDataOf;
use crate::type_config::TypeConfigExt;
Expand All @@ -51,8 +53,6 @@ use crate::LogIdOptionExt;
use crate::Membership;
use crate::RaftLogId;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::SnapshotMeta;
use crate::Vote;

/// Raft protocol algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::engine::Engine;
use crate::engine::LogIdList;
use crate::raft_state::IOId;
use crate::raft_state::LogStateReader;
use crate::storage::Snapshot;
use crate::storage::SnapshotMeta;
use crate::testing::log_id;
use crate::type_config::TypeConfigExt;
use crate::EffectiveMembership;
use crate::Membership;
use crate::Snapshot;
use crate::SnapshotMeta;
use crate::StoredMembership;
use crate::Vote;

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/following_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use crate::entry::RaftPayload;
use crate::error::RejectAppendEntries;
use crate::raft_state::IOId;
use crate::raft_state::LogStateReader;
use crate::storage::Snapshot;
use crate::vote::CommittedVote;
use crate::EffectiveMembership;
use crate::LogId;
use crate::LogIdOptionExt;
use crate::RaftLogId;
use crate::RaftState;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::StoredMembership;

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/snapshot_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::display_ext::DisplayOptionExt;
use crate::engine::Command;
use crate::engine::EngineOutput;
use crate::raft_state::LogStateReader;
use crate::storage::SnapshotMeta;
use crate::RaftState;
use crate::RaftTypeConfig;
use crate::SnapshotMeta;

#[cfg(test)]
mod trigger_snapshot_test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use pretty_assertions::assert_eq;

use crate::engine::testing::UTConfig;
use crate::engine::Engine;
use crate::storage::SnapshotMeta;
use crate::testing::log_id;
use crate::Membership;
use crate::SnapshotMeta;
use crate::StoredMembership;

fn m12() -> Membership<UTConfig> {
Expand Down
4 changes: 2 additions & 2 deletions openraft/src/engine/tests/install_full_snapshot_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use crate::engine::LogIdList;
use crate::engine::Respond;
use crate::raft::SnapshotResponse;
use crate::raft_state::IOId;
use crate::storage::Snapshot;
use crate::storage::SnapshotMeta;
use crate::testing::log_id;
use crate::type_config::TypeConfigExt;
use crate::Membership;
use crate::Snapshot;
use crate::SnapshotMeta;
use crate::StoredMembership;
use crate::Vote;

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/tests/trigger_purge_log_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::engine::Command;
use crate::engine::Engine;
use crate::engine::LogIdList;
use crate::progress::Progress;
use crate::storage::SnapshotMeta;
use crate::testing::log_id;
use crate::type_config::TypeConfigExt;
use crate::utime::Leased;
Expand All @@ -17,7 +18,6 @@ use crate::EffectiveMembership;
use crate::LogId;
use crate::Membership;
use crate::MembershipState;
use crate::SnapshotMeta;
use crate::StoredMembership;
use crate::Vote;

Expand Down
12 changes: 6 additions & 6 deletions openraft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ pub use type_config::async_runtime;
pub use type_config::async_runtime::tokio_impls::TokioRuntime;
pub use type_config::AsyncRuntime;

pub use self::storage::LogState;
pub use self::storage::RaftLogReader;
pub use self::storage::RaftSnapshotBuilder;
pub use self::storage::Snapshot;
pub use self::storage::SnapshotMeta;
pub use self::storage::StorageHelper;
pub use crate::base::OptionalSend;
pub use crate::base::OptionalSerde;
pub use crate::base::OptionalSync;
Expand Down Expand Up @@ -109,12 +115,6 @@ pub use crate::raft_state::MembershipState;
pub use crate::raft_state::RaftState;
pub use crate::raft_types::SnapshotId;
pub use crate::raft_types::SnapshotSegmentId;
pub use crate::storage::LogState;
pub use crate::storage::RaftLogReader;
pub use crate::storage::RaftSnapshotBuilder;
pub use crate::storage::Snapshot;
pub use crate::storage::SnapshotMeta;
pub use crate::storage::StorageHelper;
pub use crate::storage_error::ErrorSubject;
pub use crate::storage_error::ErrorVerb;
pub use crate::storage_error::StorageError;
Expand Down
8 changes: 4 additions & 4 deletions openraft/src/network/snapshot_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ mod tokio_rt {
use crate::network::RPCOption;
use crate::raft::InstallSnapshotRequest;
use crate::raft::SnapshotResponse;
use crate::storage::Snapshot;
use crate::type_config::TypeConfigExt;
use crate::ErrorSubject;
use crate::ErrorVerb;
use crate::OptionalSend;
use crate::Raft;
use crate::RaftNetwork;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::StorageError;
use crate::ToStorageResult;
use crate::Vote;
Expand Down Expand Up @@ -271,11 +271,11 @@ use crate::error::StreamingError;
use crate::network::RPCOption;
use crate::raft::InstallSnapshotRequest;
use crate::raft::SnapshotResponse;
use crate::storage::Snapshot;
use crate::OptionalSend;
use crate::Raft;
use crate::RaftNetwork;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::SnapshotId;
use crate::Vote;

Expand Down Expand Up @@ -395,10 +395,10 @@ mod tests {
use crate::raft::InstallSnapshotResponse;
use crate::raft::VoteRequest;
use crate::raft::VoteResponse;
use crate::storage::Snapshot;
use crate::storage::SnapshotMeta;
use crate::RaftNetwork;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::SnapshotMeta;
use crate::StoredMembership;
use crate::Vote;

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/network/v2/adapt_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use crate::raft::AppendEntriesResponse;
use crate::raft::SnapshotResponse;
use crate::raft::VoteRequest;
use crate::raft::VoteResponse;
use crate::storage::Snapshot;
use crate::OptionalSend;
use crate::RaftNetwork;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::Vote;

impl<C, V1> RaftNetworkV2<C> for V1
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/network/v2/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use crate::raft::AppendEntriesResponse;
use crate::raft::SnapshotResponse;
use crate::raft::VoteRequest;
use crate::raft::VoteResponse;
use crate::storage::Snapshot;
use crate::OptionalSend;
use crate::OptionalSync;
use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::Vote;

/// A trait defining the interface for a Raft network between cluster members.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/raft/message/install_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use crate::storage::SnapshotMeta;
use crate::RaftTypeConfig;
use crate::SnapshotMeta;
use crate::Vote;

/// An RPC sent by the Raft leader to send chunks of a snapshot to a follower (§7).
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/raft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub use crate::raft::runtime_config_handle::RuntimeConfigHandle;
use crate::raft::trigger::Trigger;
use crate::storage::RaftLogStorage;
use crate::storage::RaftStateMachine;
use crate::storage::Snapshot;
use crate::type_config::alias::JoinErrorOf;
use crate::type_config::alias::ResponderOf;
use crate::type_config::alias::ResponderReceiverOf;
Expand All @@ -94,7 +95,6 @@ use crate::OptionalSend;
use crate::RaftNetworkFactory;
use crate::RaftState;
pub use crate::RaftTypeConfig;
use crate::Snapshot;
use crate::StorageHelper;
use crate::Vote;

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/raft_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use validit::Validate;
use crate::engine::LogIdList;
use crate::error::ForwardToLeader;
use crate::log_id::RaftLogId;
use crate::storage::SnapshotMeta;
use crate::utime::Leased;
use crate::LogId;
use crate::LogIdOptionExt;
use crate::RaftTypeConfig;
use crate::ServerState;
use crate::SnapshotMeta;
use crate::Vote;

pub(crate) mod io_state;
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/raft_state/tests/validate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use validit::Validate;

use crate::engine::testing::UTConfig;
use crate::engine::LogIdList;
use crate::storage::SnapshotMeta;
use crate::CommittedLeaderId;
use crate::LogId;
use crate::RaftState;
use crate::SnapshotMeta;

fn log_id(term: u64, index: u64) -> LogId<u64> {
LogId::<u64> {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/replication/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use core::fmt;

use crate::error::StreamingError;
use crate::raft::SnapshotResponse;
use crate::storage::SnapshotMeta;
use crate::type_config::alias::InstantOf;
use crate::RaftTypeConfig;
use crate::SnapshotMeta;

/// Callback payload when a snapshot transmission finished, successfully or not.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/replication/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ use crate::error::StreamingError;
use crate::log_id_range::LogIdRange;
use crate::raft::SnapshotResponse;
use crate::replication::callbacks::SnapshotCallback;
use crate::storage::SnapshotMeta;
use crate::type_config::alias::InstantOf;
use crate::LogId;
use crate::RaftTypeConfig;
use crate::SnapshotMeta;

/// Request to replicate a chunk of data, logs or snapshot.
///
Expand Down
15 changes: 15 additions & 0 deletions openraft/src/storage/log_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::LogId;
use crate::RaftTypeConfig;

/// The state about logs.
///
/// Invariance: last_purged_log_id <= last_applied <= last_log_id
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct LogState<C: RaftTypeConfig> {
/// The greatest log id that has been purged after being applied to state machine.
pub last_purged_log_id: Option<LogId<C::NodeId>>,

/// The log id of the last present entry if there are any entries.
/// Otherwise the same value as `last_purged_log_id`.
pub last_log_id: Option<LogId<C::NodeId>>,
}
Loading

0 comments on commit e54a1fd

Please sign in to comment.