Ver Fonte

Move raft code into its own directory.

Jing Yang há 2 anos atrás
pai
commit
23c826e6f9
56 ficheiros alterados com 96 adições e 84 exclusões
  1. 4 32
      Cargo.toml
  2. 7 7
      README.md
  3. 22 22
      durio/Cargo.lock
  4. 1 1
      durio/Cargo.toml
  5. 1 1
      durio/run_smoke_test.sh
  6. 1 1
      durio/src/raft_service.rs
  7. 2 2
      durio/src/storage.rs
  8. 1 1
      kvraft/Cargo.toml
  9. 2 2
      kvraft/src/server.rs
  10. 1 1
      kvraft/src/snapshot_holder.rs
  11. 40 0
      raft/Cargo.toml
  12. 0 0
      raft/src/apply_command.rs
  13. 0 0
      raft/src/beat_ticker.rs
  14. 0 0
      raft/src/daemon_env.rs
  15. 0 0
      raft/src/daemon_watch.rs
  16. 0 0
      raft/src/election.rs
  17. 0 0
      raft/src/heartbeats.rs
  18. 0 0
      raft/src/index_term.rs
  19. 0 0
      raft/src/lib.rs
  20. 0 0
      raft/src/log_array.rs
  21. 0 0
      raft/src/messages.rs
  22. 0 0
      raft/src/peer_progress.rs
  23. 0 0
      raft/src/process_append_entries.rs
  24. 0 0
      raft/src/process_install_snapshot.rs
  25. 0 0
      raft/src/process_request_vote.rs
  26. 0 0
      raft/src/raft.rs
  27. 0 0
      raft/src/raft_state.rs
  28. 0 0
      raft/src/remote/mod.rs
  29. 0 0
      raft/src/remote/remote_context.rs
  30. 0 0
      raft/src/remote/remote_peer.rs
  31. 0 0
      raft/src/remote/remote_raft.rs
  32. 0 0
      raft/src/remote/term_marker.rs
  33. 0 0
      raft/src/replicable_command.rs
  34. 0 0
      raft/src/snapshot.rs
  35. 0 0
      raft/src/storage/decode_and_encode.rs
  36. 0 0
      raft/src/storage/internal.rs
  37. 0 0
      raft/src/storage/mod.rs
  38. 0 0
      raft/src/sync_log_entries.rs
  39. 0 0
      raft/src/utils/do_nothing.rs
  40. 0 0
      raft/src/utils/integration_test.rs
  41. 0 0
      raft/src/utils/mod.rs
  42. 0 0
      raft/src/utils/rpcs.rs
  43. 0 0
      raft/src/utils/shared_sender.rs
  44. 0 0
      raft/src/verify_authority.rs
  45. 0 0
      raft/tests/agreement_tests.rs
  46. 0 0
      raft/tests/election_tests.rs
  47. 0 0
      raft/tests/persist_tests.rs
  48. 0 0
      raft/tests/prevote_tests.rs
  49. 1 1
      raft/tests/regression_tests.rs
  50. 0 0
      raft/tests/snapshot_tests.rs
  51. 1 1
      test_configs/Cargo.toml
  52. 4 4
      test_configs/src/in_memory_storage.rs
  53. 1 1
      test_configs/src/interceptor/mod.rs
  54. 1 1
      test_configs/src/raft/config.rs
  55. 5 5
      test_configs/src/rpcs.rs
  56. 1 1
      test_configs/src/utils.rs

+ 4 - 32
Cargo.toml

@@ -1,5 +1,4 @@
-[package]
-name = "ruaft"
+[workspace.package]
 version = "0.1.0"
 description = "Raft implemented in Rust"
 authors = ["Jing Yang <ditsing@gmail.com>"]
@@ -10,44 +9,17 @@ readme = "README.md"
 repository = "https://github.com/ditsing/ruaft"
 homepage = "https://github.com/ditsing/ruaft"
 
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-async-trait = "0.1"
-bincode = "1.3.3"
-bytes = "1.1"
-crossbeam-utils = "0.8"
-futures-channel = "0.3.21"
-futures-util = "0.3.21"
-lazy_static = "1.4.0"
-log = "0.4"
-parking_lot = "0.12"
-rand = "0.8"
-serde = "1.0"
-serde_derive = "1.0"
-serde_bytes = "0.11.9"
-tokio = { version = "1.7", features = ["net", "rt-multi-thread", "sync", "time", "parking_lot"] }
-test_utils = { path = "test_utils", optional = true }
-
-[features]
-default = []
-integration-test = ["test_utils"]
-
-[dev-dependencies]
-scopeguard = "1.1.0"
-stdext = "0.3"
-test_configs = { path = "test_configs" }
-test_utils = { path = "test_utils" }
-
 [workspace]
+resolver = "2"
 members = [
+    "raft",
     "kvraft",
     "linearizability",
     "test_configs",
     "test_utils",
 ]
 default-members = [
-    ".",
+    "raft",
     "kvraft",
     "linearizability",
     "test_configs",

+ 7 - 7
README.md

@@ -127,11 +127,11 @@ assuming there is no thread starvation.
 
 [durio]: https://github.com/ditsing/ruaft/tree/master/durio
 [kvraft]: https://github.com/ditsing/ruaft/tree/master/kvraft
-[labrpc]: https://github.com/ditsing/librpc
+[labrpc]: https://github.com/ditsing/labrpc
 [tarpc]: https://github.com/google/tarpc
-[lib]: https://github.com/ditsing/ruaft/blob/master/src/lib.rs
-[apply_command]: https://github.com/ditsing/ruaft/blob/master/src/apply_command.rs
-[persister]: https://github.com/ditsing/ruaft/blob/master/src/persister.rs
-[remote_raft]: https://github.com/ditsing/ruaft/blob/master/src/remote_raft.rs
-[save_snapshot]: https://github.com/ditsing/ruaft/blob/master/src/snapshot.rs
-[snapshot_tests]: https://github.com/ditsing/ruaft/blob/master/tests/snapshot_tests.rs
+[lib]: https://github.com/ditsing/ruaft/blob/master/raft/src/lib.rs
+[apply_command]: https://github.com/ditsing/ruaft/blob/master/raft/src/apply_command.rs
+[persister]: https://github.com/ditsing/ruaft/blob/master/raft/src/persister.rs
+[remote_raft]: https://github.com/ditsing/ruaft/blob/master/raft/src/remote/remote_raft.rs
+[save_snapshot]: https://github.com/ditsing/ruaft/blob/master/raft/src/snapshot.rs
+[snapshot_tests]: https://github.com/ditsing/ruaft/blob/master/raft/tests/snapshot_tests.rs

+ 22 - 22
durio/Cargo.lock

@@ -203,8 +203,8 @@ dependencies = [
  "lazy_static",
  "log",
  "parking_lot",
+ "raft",
  "reqwest",
- "ruaft",
  "serde",
  "serde_derive",
  "serde_json",
@@ -541,8 +541,8 @@ dependencies = [
  "futures",
  "log",
  "parking_lot",
+ "raft",
  "rand",
- "ruaft",
  "serde",
  "serde_derive",
  "tokio",
@@ -797,6 +797,26 @@ dependencies = [
  "proc-macro2",
 ]
 
+[[package]]
+name = "raft"
+version = "0.1.0"
+dependencies = [
+ "async-trait",
+ "bincode",
+ "bytes",
+ "crossbeam-utils",
+ "futures-channel",
+ "futures-util",
+ "lazy_static",
+ "log",
+ "parking_lot",
+ "rand",
+ "serde",
+ "serde_bytes",
+ "serde_derive",
+ "tokio",
+]
+
 [[package]]
 name = "rand"
 version = "0.8.5"
@@ -899,26 +919,6 @@ dependencies = [
  "winreg",
 ]
 
-[[package]]
-name = "ruaft"
-version = "0.1.0"
-dependencies = [
- "async-trait",
- "bincode",
- "bytes",
- "crossbeam-utils",
- "futures-channel",
- "futures-util",
- "lazy_static",
- "log",
- "parking_lot",
- "rand",
- "serde",
- "serde_bytes",
- "serde_derive",
- "tokio",
-]
-
 [[package]]
 name = "rustc-demangle"
 version = "0.1.23"

+ 1 - 1
durio/Cargo.toml

@@ -23,7 +23,7 @@ kvraft = { path = "../kvraft" }
 lazy_static = "1.4.0"
 log = "0.4"
 parking_lot = "0.12"
-ruaft = { path = ".." }
+raft = { path = "../raft" }
 serde = "1.0"
 serde_derive = "1.0"
 serde_json = "1.0"

+ 1 - 1
durio/run_smoke_test.sh

@@ -1,2 +1,2 @@
 #!/bin/bash
-RUST_LOG=ruaft=debug,kvraft=debug cargo test -p durio -- --include-ignored --nocapture
+RUST_LOG=raft=debug,kvraft=debug cargo test -p durio -- --include-ignored --nocapture

+ 1 - 1
durio/src/raft_service.rs

@@ -5,7 +5,7 @@ use async_trait::async_trait;
 use tarpc::context::Context;
 
 use kvraft::UniqueKVOp;
-use ruaft::{
+use raft::{
     AppendEntriesArgs, AppendEntriesReply, InstallSnapshotArgs,
     InstallSnapshotReply, Raft, RemoteRaft, RequestVoteArgs, RequestVoteReply,
 };

+ 2 - 2
durio/src/storage.rs

@@ -1,8 +1,8 @@
-use ruaft::storage::{
+use raft::storage::{
     RaftLogEntryRef, RaftStorageMonitorTrait, RaftStoragePersisterTrait,
     RaftStorageTrait, RaftStoredState,
 };
-use ruaft::{Index, Term};
+use raft::{Index, Term};
 
 #[derive(Default)]
 pub struct DoNothingRaftStorage;

+ 1 - 1
kvraft/Cargo.toml

@@ -10,7 +10,7 @@ futures = "0.3.21"
 log = "0.4"
 parking_lot = "0.12"
 rand = "0.8"
-ruaft = { path = ".." }
+raft = { path = "../raft" }
 serde = "1.0"
 serde_derive = "1.0"
 test_utils = { path = "../test_utils", optional = true }

+ 2 - 2
kvraft/src/server.rs

@@ -9,8 +9,8 @@ use futures::FutureExt;
 use parking_lot::Mutex;
 use serde_derive::{Deserialize, Serialize};
 
-use ruaft::storage::RaftStorageTrait;
-use ruaft::{
+use raft::storage::RaftStorageTrait;
+use raft::{
     ApplyCommandMessage, Index, Raft, RemoteRaft, Term, VerifyAuthorityResult,
 };
 #[cfg(all(not(test), feature = "integration-test"))]

+ 1 - 1
kvraft/src/snapshot_holder.rs

@@ -4,7 +4,7 @@ use parking_lot::Mutex;
 use serde::de::DeserializeOwned;
 use serde::Serialize;
 
-use ruaft::Snapshot;
+use raft::Snapshot;
 
 #[derive(Default)]
 pub(crate) struct SnapshotHolder<T> {

+ 40 - 0
raft/Cargo.toml

@@ -0,0 +1,40 @@
+[package]
+name = "raft"
+version = "0.1.0"
+description = "Raft implemented in Rust"
+authors = ["Jing Yang <ditsing@gmail.com>"]
+edition = "2021"
+license = "MIT"
+keywords = ["raft", "consensus-protocol"]
+readme = "README.md"
+repository = "https://github.com/ditsing/ruaft"
+homepage = "https://github.com/ditsing/ruaft"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+async-trait = "0.1"
+bincode = "1.3.3"
+bytes = "1.1"
+crossbeam-utils = "0.8"
+futures-channel = "0.3.21"
+futures-util = "0.3.21"
+lazy_static = "1.4.0"
+log = "0.4"
+parking_lot = "0.12"
+rand = "0.8"
+serde = "1.0"
+serde_derive = "1.0"
+serde_bytes = "0.11.9"
+tokio = { version = "1.7", features = ["net", "rt-multi-thread", "sync", "time", "parking_lot"] }
+test_utils = { path = "../test_utils", optional = true }
+
+[features]
+default = []
+integration-test = ["test_utils"]
+
+[dev-dependencies]
+scopeguard = "1.1.0"
+stdext = "0.3"
+test_configs = { path = "../test_configs" }
+test_utils = { path = "../test_utils" }

+ 0 - 0
src/apply_command.rs → raft/src/apply_command.rs


+ 0 - 0
src/beat_ticker.rs → raft/src/beat_ticker.rs


+ 0 - 0
src/daemon_env.rs → raft/src/daemon_env.rs


+ 0 - 0
src/daemon_watch.rs → raft/src/daemon_watch.rs


+ 0 - 0
src/election.rs → raft/src/election.rs


+ 0 - 0
src/heartbeats.rs → raft/src/heartbeats.rs


+ 0 - 0
src/index_term.rs → raft/src/index_term.rs


+ 0 - 0
src/lib.rs → raft/src/lib.rs


+ 0 - 0
src/log_array.rs → raft/src/log_array.rs


+ 0 - 0
src/messages.rs → raft/src/messages.rs


+ 0 - 0
src/peer_progress.rs → raft/src/peer_progress.rs


+ 0 - 0
src/process_append_entries.rs → raft/src/process_append_entries.rs


+ 0 - 0
src/process_install_snapshot.rs → raft/src/process_install_snapshot.rs


+ 0 - 0
src/process_request_vote.rs → raft/src/process_request_vote.rs


+ 0 - 0
src/raft.rs → raft/src/raft.rs


+ 0 - 0
src/raft_state.rs → raft/src/raft_state.rs


+ 0 - 0
src/remote/mod.rs → raft/src/remote/mod.rs


+ 0 - 0
src/remote/remote_context.rs → raft/src/remote/remote_context.rs


+ 0 - 0
src/remote/remote_peer.rs → raft/src/remote/remote_peer.rs


+ 0 - 0
src/remote/remote_raft.rs → raft/src/remote/remote_raft.rs


+ 0 - 0
src/remote/term_marker.rs → raft/src/remote/term_marker.rs


+ 0 - 0
src/replicable_command.rs → raft/src/replicable_command.rs


+ 0 - 0
src/snapshot.rs → raft/src/snapshot.rs


+ 0 - 0
src/storage/decode_and_encode.rs → raft/src/storage/decode_and_encode.rs


+ 0 - 0
src/storage/internal.rs → raft/src/storage/internal.rs


+ 0 - 0
src/storage/mod.rs → raft/src/storage/mod.rs


+ 0 - 0
src/sync_log_entries.rs → raft/src/sync_log_entries.rs


+ 0 - 0
src/utils/do_nothing.rs → raft/src/utils/do_nothing.rs


+ 0 - 0
src/utils/integration_test.rs → raft/src/utils/integration_test.rs


+ 0 - 0
src/utils/mod.rs → raft/src/utils/mod.rs


+ 0 - 0
src/utils/rpcs.rs → raft/src/utils/rpcs.rs


+ 0 - 0
src/utils/shared_sender.rs → raft/src/utils/shared_sender.rs


+ 0 - 0
src/verify_authority.rs → raft/src/verify_authority.rs


+ 0 - 0
tests/agreement_tests.rs → raft/tests/agreement_tests.rs


+ 0 - 0
tests/election_tests.rs → raft/tests/election_tests.rs


+ 0 - 0
tests/persist_tests.rs → raft/tests/persist_tests.rs


+ 0 - 0
tests/prevote_tests.rs → raft/tests/prevote_tests.rs


+ 1 - 1
tests/regression_tests.rs → raft/tests/regression_tests.rs

@@ -1,7 +1,7 @@
 use std::sync::Arc;
 use std::time::{Duration, Instant};
 
-use ruaft::utils::integration_test::{
+use raft::utils::integration_test::{
     unpack_append_entries_args, unpack_append_entries_reply,
 };
 use test_configs::interceptor::{make_config, RaftRpcEvent};

+ 0 - 0
tests/snapshot_tests.rs → raft/tests/snapshot_tests.rs


+ 1 - 1
test_configs/Cargo.toml

@@ -18,7 +18,7 @@ log = "0.4"
 once_cell = "1.12.0"
 parking_lot = "0.12"
 rand = "0.8"
-ruaft = { path = "..", features = ["integration-test"] }
+raft = { path = "../raft", features = ["integration-test"] }
 serde = "1.0"
 test_utils = { path = "../test_utils" }
 

+ 4 - 4
test_configs/src/in_memory_storage.rs

@@ -5,11 +5,11 @@ use std::sync::Arc;
 
 use parking_lot::Mutex;
 
-use ruaft::storage::{
+use raft::storage::{
     RaftLogEntryRef, RaftStorageMonitorTrait, RaftStoragePersisterTrait,
     RaftStorageTrait, RaftStoredLogEntry, RaftStoredState,
 };
-use ruaft::{Index, Term};
+use raft::{Index, Term};
 
 #[derive(Clone)]
 pub struct State {
@@ -222,11 +222,11 @@ mod tests {
 
     use parking_lot::Mutex;
 
-    use ruaft::storage::{
+    use raft::storage::{
         RaftLogEntryRef, RaftStorageMonitorTrait, RaftStoragePersisterTrait,
         RaftStorageTrait,
     };
-    use ruaft::{Index, Term};
+    use raft::{Index, Term};
 
     use crate::in_memory_storage::{InMemoryState, State};
     use crate::InMemoryStorage;

+ 1 - 1
test_configs/src/interceptor/mod.rs

@@ -10,7 +10,7 @@ use once_cell::sync::OnceCell;
 use kvraft::{
     GetArgs, KVServer, PutAppendArgs, PutAppendEnum, UniqueId, UniqueKVOp,
 };
-use ruaft::{
+use raft::{
     AppendEntriesArgs, AppendEntriesReply, InstallSnapshotArgs,
     InstallSnapshotReply, Raft, RemoteRaft, ReplicableCommand, RequestVoteArgs,
     RequestVoteReply,

+ 1 - 1
test_configs/src/raft/config.rs

@@ -8,7 +8,7 @@ use anyhow::{anyhow, bail};
 use parking_lot::Mutex;
 use rand::{thread_rng, Rng};
 
-use ruaft::{ApplyCommandMessage, Raft, Term};
+use raft::{ApplyCommandMessage, Raft, Term};
 
 use crate::register_server;
 use crate::utils::{sleep_millis, NO_SNAPSHOT};

+ 5 - 5
test_configs/src/rpcs.rs

@@ -12,7 +12,7 @@ use kvraft::{
     CommitSentinelArgs, CommitSentinelReply, GetArgs, GetReply, KVServer,
     PutAppendArgs, PutAppendReply, RemoteKvraft,
 };
-use ruaft::{
+use raft::{
     AppendEntriesArgs, AppendEntriesReply, InstallSnapshotArgs,
     InstallSnapshotReply, Raft, ReplicableCommand, RequestVoteArgs,
     RequestVoteReply,
@@ -52,7 +52,7 @@ impl RpcClient {
 }
 
 #[async_trait]
-impl<Command: ReplicableCommand> ruaft::RemoteRaft<Command> for RpcClient {
+impl<Command: ReplicableCommand> raft::RemoteRaft<Command> for RpcClient {
     async fn request_vote(
         &self,
         args: RequestVoteArgs,
@@ -216,12 +216,12 @@ pub fn register_kv_server<
 
 #[cfg(test)]
 mod tests {
-    use ruaft::utils::do_nothing::DoNothingRaftStorage;
-    use ruaft::utils::integration_test::{
+    use raft::utils::do_nothing::DoNothingRaftStorage;
+    use raft::utils::integration_test::{
         make_append_entries_args, make_request_vote_args,
         unpack_append_entries_reply, unpack_request_vote_reply,
     };
-    use ruaft::{ApplyCommandMessage, RemoteRaft, Term};
+    use raft::{ApplyCommandMessage, RemoteRaft, Term};
 
     use super::*;
 

+ 1 - 1
test_configs/src/utils.rs

@@ -11,4 +11,4 @@ pub fn sleep_election_timeouts(count: u64) {
 
 /// Pass this function to [`Raft::new`] if the application will not accept
 /// any request for taking snapshots.
-pub const NO_SNAPSHOT: fn(ruaft::Index) = |_| {};
+pub const NO_SNAPSHOT: fn(raft::Index) = |_| {};