diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e2139c96..114085fee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,91 +8,27 @@ jobs: - name: Setup | Checkout uses: actions/checkout@v2 + # use rust-toolchain file - name: Setup | Toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable - default: true + components: rustfmt, clippy # unit tests - name: Unit Tests uses: actions-rs/cargo@v1 with: command: test - args: -p async-raft --lib - - # integration tests - - name: Integration Test - uses: actions-rs/cargo@v1 - with: - command: test - args: -p async-raft # release build - name: Build | Release Mode uses: actions-rs/cargo@v1 with: command: build - args: -p async-raft --release - - build-async-raft-nightly: - name: build async-raft nightly - runs-on: ubuntu-latest - steps: - - name: Setup | Checkout - uses: actions/checkout@v2 + args: --release --all-features - - name: Setup | Toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - default: true - - name: Build | Release Mode - uses: actions-rs/cargo@v1 - with: - command: build - args: -p async-raft --release --all-features - - build-memstore: - name: build memstore - runs-on: ubuntu-latest - steps: - - name: Setup | Checkout - uses: actions/checkout@v2 - - name: Setup | Toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - default: true - - # unit tests - - name: Unit Tests - uses: actions-rs/cargo@v1 - with: - command: test - args: -p memstore - - # release build - - name: Build | Release Mode - uses: actions-rs/cargo@v1 - with: - command: build - args: -p memstore --release - - clippy: - name: clippy - runs-on: ubuntu-latest - steps: - - name: Setup | Checkout - uses: actions/checkout@v2 - - name: Setup | Toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - default: true - components: clippy - - name: Clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets -- -D warnings + # - name: Clippy + # uses: actions-rs/clippy-check@v1 + # with: + # token: ${{ secrets.GITHUB_TOKEN }} + # args: --all-targets -- -D warnings diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..f54700870 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +all: test lint + +test: + cargo test + +fmt: + cargo fmt + +lint: + cargo fmt + cargo clippy --all-targets -- -D warnings + +clean: + cargo clean + +.PHONY: test fmt lint clean diff --git a/async-raft/src/core/client.rs b/async-raft/src/core/client.rs index f878c2265..3b98906b9 100644 --- a/async-raft/src/core/client.rs +++ b/async-raft/src/core/client.rs @@ -424,6 +424,6 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage }); self.core.last_applied = *index; self.core.report_metrics(); - Ok(res?) + res } } diff --git a/async-raft/src/core/mod.rs b/async-raft/src/core/mod.rs index d8eadf89b..d96320e19 100644 --- a/async-raft/src/core/mod.rs +++ b/async-raft/src/core/mod.rs @@ -298,11 +298,10 @@ impl, S: RaftStorage> Ra current_term: self.current_term, voted_for: self.voted_for, }; - Ok(self - .storage + self.storage .save_hard_state(&hs) .await - .map_err(|err| self.map_fatal_storage_error(err))?) + .map_err(|err| self.map_fatal_storage_error(err)) } /// Update core's target state, ensuring all invariants are upheld. @@ -763,7 +762,6 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage struct ReplicationState { pub match_index: u64, pub match_term: u64, - pub is_at_line_rate: bool, pub remove_after_commit: Option, pub replstream: ReplicationStream, } diff --git a/async-raft/src/core/replication.rs b/async-raft/src/core/replication.rs index 994b03ad6..2e28ab884 100644 --- a/async-raft/src/core/replication.rs +++ b/async-raft/src/core/replication.rs @@ -41,7 +41,6 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage ReplicationState { match_index: self.core.last_log_index, match_term: self.core.current_term, - is_at_line_rate: false, replstream, remove_after_commit: None, } @@ -83,13 +82,11 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage #[tracing::instrument(level = "trace", skip(self, target, is_line_rate))] async fn handle_rate_update(&mut self, target: NodeId, is_line_rate: bool) -> RaftResult<()> { // Get a handle the target's replication stat & update it as needed. - if let Some(state) = self.nodes.get_mut(&target) { - state.is_at_line_rate = is_line_rate; + if let Some(_state) = self.nodes.get_mut(&target) { return Ok(()); } // Else, if this is a non-voter, then update as needed. if let Some(state) = self.non_voters.get_mut(&target) { - state.state.is_at_line_rate = is_line_rate; state.is_ready_to_join = is_line_rate; // Issue a response on the non-voters response channel if needed. if state.is_ready_to_join { diff --git a/async-raft/src/lib.rs b/async-raft/src/lib.rs index 892b19edf..e6f8855ee 100644 --- a/async-raft/src/lib.rs +++ b/async-raft/src/lib.rs @@ -1,5 +1,4 @@ -#![cfg_attr(feature = "docinclude", feature(external_doc))] -#![cfg_attr(feature = "docinclude", doc(include = "../README.md"))] +#![doc = include_str!("../README.md")] pub mod config; mod core; diff --git a/async-raft/src/raft.rs b/async-raft/src/raft.rs index 789889639..689f5e210 100644 --- a/async-raft/src/raft.rs +++ b/async-raft/src/raft.rs @@ -119,10 +119,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::AppendEntries { rpc, tx }) .map_err(|_| RaftError::ShuttingDown)?; - Ok(rx - .await + rx.await .map_err(|_| RaftError::ShuttingDown) - .and_then(|res| res)?) + .and_then(|res| res) } /// Submit a VoteRequest (RequestVote in the spec) RPC to this Raft node. @@ -135,10 +134,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::RequestVote { rpc, tx }) .map_err(|_| RaftError::ShuttingDown)?; - Ok(rx - .await + rx.await .map_err(|_| RaftError::ShuttingDown) - .and_then(|res| res)?) + .and_then(|res| res) } /// Submit an InstallSnapshot RPC to this Raft node. @@ -155,10 +153,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::InstallSnapshot { rpc, tx }) .map_err(|_| RaftError::ShuttingDown)?; - Ok(rx - .await + rx.await .map_err(|_| RaftError::ShuttingDown) - .and_then(|res| res)?) + .and_then(|res| res) } /// Get the ID of the current leader from this Raft node. @@ -182,10 +179,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::ClientReadRequest { tx }) .map_err(|_| ClientReadError::RaftError(RaftError::ShuttingDown))?; - Ok(rx - .await + rx.await .map_err(|_| ClientReadError::RaftError(RaftError::ShuttingDown)) - .and_then(|res| res)?) + .and_then(|res| res) } /// Submit a mutating client request to Raft to update the state of the system (§5.1). @@ -215,10 +211,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::ClientWriteRequest { rpc, tx }) .map_err(|_| ClientWriteError::RaftError(RaftError::ShuttingDown))?; - Ok(rx - .await + rx.await .map_err(|_| ClientWriteError::RaftError(RaftError::ShuttingDown)) - .and_then(|res| res)?) + .and_then(|res| res) } /// Initialize a pristine Raft node with the given config. @@ -256,10 +251,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::Initialize { members, tx }) .map_err(|_| RaftError::ShuttingDown)?; - Ok(rx - .await + rx.await .map_err(|_| InitializeError::RaftError(RaftError::ShuttingDown)) - .and_then(|res| res)?) + .and_then(|res| res) } /// Synchronize a new Raft node, bringing it up-to-speed (§6). @@ -281,10 +275,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::AddNonVoter { id, tx }) .map_err(|_| RaftError::ShuttingDown)?; - Ok(rx - .await + rx.await .map_err(|_| ChangeConfigError::RaftError(RaftError::ShuttingDown)) - .and_then(|res| res)?) + .and_then(|res| res) } /// Propose a cluster configuration change (§6). @@ -308,10 +301,9 @@ impl, S: RaftStorage> Ra .tx_api .send(RaftMsg::ChangeMembership { members, tx }) .map_err(|_| RaftError::ShuttingDown)?; - Ok(rx - .await + rx.await .map_err(|_| ChangeConfigError::RaftError(RaftError::ShuttingDown)) - .and_then(|res| res)?) + .and_then(|res| res) } /// Get a handle to the metrics channel. diff --git a/async-raft/src/replication/mod.rs b/async-raft/src/replication/mod.rs index 708e6d23e..d0dfc7b3e 100644 --- a/async-raft/src/replication/mod.rs +++ b/async-raft/src/replication/mod.rs @@ -10,7 +10,7 @@ use tokio::io::AsyncSeek; use tokio::io::AsyncSeekExt; use tokio::sync::mpsc; use tokio::sync::oneshot; -use tokio::task::JoinHandle; +// use tokio::task::JoinHandle; use tokio::time::interval; use tokio::time::timeout; use tokio::time::Duration; @@ -33,7 +33,7 @@ use crate::RaftStorage; /// The public handle to a spawned replication stream. pub(crate) struct ReplicationStream { /// The spawn handle the `ReplicationCore` task. - pub handle: JoinHandle<()>, + // pub handle: JoinHandle<()>, /// The channel used for communicating with the replication task. pub repltx: mpsc::UnboundedSender>, } @@ -192,9 +192,9 @@ impl, S: RaftStorage> replication_buffer: Vec::new(), outbound_buffer: Vec::new(), }; - let handle = tokio::spawn(this.main()); + let _handle = tokio::spawn(this.main()); ReplicationStream { - handle, + // handle, repltx: raftrx_tx, } } diff --git a/async-raft/tests/conflict_with_empty_entries.rs b/async-raft/tests/conflict_with_empty_entries.rs index 30ed196d1..492e858c0 100644 --- a/async-raft/tests/conflict_with_empty_entries.rs +++ b/async-raft/tests/conflict_with_empty_entries.rs @@ -59,7 +59,7 @@ async fn conflict_with_empty_entries() -> Result<()> { }; let resp = router.append_entries(0, rpc).await?; - assert_eq!(false, resp.success); + assert!(!resp.success); assert!(resp.conflict_opt.is_some()); let c = resp.conflict_opt.unwrap(); assert_eq!(ConflictOpt { term: 0, index: 0 }, c); @@ -93,7 +93,7 @@ async fn conflict_with_empty_entries() -> Result<()> { }; let resp = router.append_entries(0, rpc).await?; - assert_eq!(true, resp.success); + assert!(resp.success); assert!(resp.conflict_opt.is_none()); // Expect a conflict with prev_log_index == 3 @@ -108,7 +108,7 @@ async fn conflict_with_empty_entries() -> Result<()> { }; let resp = router.append_entries(0, rpc).await?; - assert_eq!(false, resp.success); + assert!(!resp.success); assert!(resp.conflict_opt.is_some()); let c = resp.conflict_opt.unwrap(); assert_eq!(ConflictOpt { term: 1, index: 2 }, c); diff --git a/memstore/src/lib.rs b/memstore/src/lib.rs index e1ee8c9a4..def9329d3 100644 --- a/memstore/src/lib.rs +++ b/memstore/src/lib.rs @@ -1,5 +1,4 @@ -#![cfg_attr(feature = "docinclude", feature(external_doc))] -#![cfg_attr(feature = "docinclude", doc(include = "../README.md"))] +#![doc = include_str!("../README.md")] #[cfg(test)] mod test; diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 000000000..6ff299803 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2021-06-01