Skip to content

Commit

Permalink
Change: remove unused trait RaftStorageDebug
Browse files Browse the repository at this point in the history
`RaftStorageDebug` has only one method `get_state_machine()`,
and state machine is entirely a user defined struct. Obtaining a state
machine does not imply anything about the struct or behavior of it.
  • Loading branch information
drmingdrmer committed Apr 10, 2023
1 parent 964047b commit e056998
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 31 deletions.
14 changes: 5 additions & 9 deletions memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use openraft::EntryPayload;
use openraft::LogId;
use openraft::RaftLogId;
use openraft::RaftStorage;
use openraft::RaftStorageDebug;
use openraft::SnapshotMeta;
use openraft::StorageError;
use openraft::StorageIOError;
Expand Down Expand Up @@ -136,6 +135,11 @@ impl MemStore {
pub async fn new_async() -> Arc<Self> {
Arc::new(Self::new())
}

/// Get a handle to the state machine for testing purposes.
pub async fn get_state_machine(&self) -> MemStoreStateMachine {
self.sm.write().await.clone()
}
}

impl Default for MemStore {
Expand All @@ -144,14 +148,6 @@ impl Default for MemStore {
}
}

#[async_trait]
impl RaftStorageDebug<MemStoreStateMachine> for Arc<MemStore> {
/// Get a handle to the state machine for testing purposes.
async fn get_state_machine(&mut self) -> MemStoreStateMachine {
self.sm.write().await.clone()
}
}

#[async_trait]
impl RaftLogReader<Config> for Arc<MemStore> {
async fn try_get_log_entries<RB: RangeBounds<u64> + Clone + Debug + Send + Sync>(
Expand Down
1 change: 0 additions & 1 deletion openraft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ pub use crate::storage::LogState;
pub use crate::storage::RaftLogReader;
pub use crate::storage::RaftSnapshotBuilder;
pub use crate::storage::RaftStorage;
pub use crate::storage::RaftStorageDebug;
pub use crate::storage::Snapshot;
pub use crate::storage::SnapshotMeta;
pub use crate::storage::StorageHelper;
Expand Down
7 changes: 0 additions & 7 deletions openraft/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,3 @@ where C: RaftTypeConfig
&mut self,
) -> Result<Option<Snapshot<C::NodeId, C::Node, Self::SnapshotData>>, StorageError<C::NodeId>>;
}

/// APIs for debugging a store.
#[async_trait]
pub trait RaftStorageDebug<SM> {
/// Get a handle to the state machine for testing purposes.
async fn get_state_machine(&mut self) -> SM;
}
12 changes: 0 additions & 12 deletions openraft/src/store_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::storage::Snapshot;
use crate::DefensiveCheck;
use crate::LogId;
use crate::RaftStorage;
use crate::RaftStorageDebug;
use crate::RaftTypeConfig;
use crate::SnapshotMeta;
use crate::StorageError;
Expand Down Expand Up @@ -144,17 +143,6 @@ where
{
}

#[async_trait]
impl<C, T, SM> RaftStorageDebug<SM> for StoreExt<C, T>
where
T: RaftStorage<C> + RaftStorageDebug<SM>,
C: RaftTypeConfig,
{
async fn get_state_machine(&mut self) -> SM {
self.inner().get_state_machine().await
}
}

#[async_trait]
impl<C: RaftTypeConfig, T: RaftStorage<C>> RaftStorage<C> for StoreExt<C, T>
where
Expand Down
3 changes: 1 addition & 2 deletions tests/tests/metrics/t20_metrics_state_machine_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::time::Duration;
use anyhow::Result;
use maplit::btreeset;
use openraft::Config;
use openraft::RaftStorageDebug;
use openraft::ServerState;

use crate::fixtures::init_default_ut_tracing;
Expand Down Expand Up @@ -57,7 +56,7 @@ async fn metrics_state_machine_consistency() -> Result<()> {
log_index += 1;
for node_id in 0..2 {
router.wait_for_log(&btreeset![node_id], Some(log_index), None, "write one log").await?;
let mut sto = router.get_storage_handle(&node_id)?;
let sto = router.get_storage_handle(&node_id)?;
assert!(sto.get_state_machine().await.client_status.get("foo").is_some());
}

Expand Down

0 comments on commit e056998

Please sign in to comment.