Skip to content

Commit

Permalink
fix: doc-include can only be used in nightly build
Browse files Browse the repository at this point in the history
- Simplify CI test: test all in one action.

- Disable clippy: it suggests inappropriate assert_eq to assert
  convertion which is used in a macro.

- Add makefile

- Build only with nightly rust. Add rust-toolchain to specify toolchain
  version.
  • Loading branch information
drmingdrmer committed Jun 16, 2021
1 parent a10d990 commit 11cb545
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 116 deletions.
80 changes: 8 additions & 72 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion async-raft/src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,6 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
});
self.core.last_applied = *index;
self.core.report_metrics();
Ok(res?)
res
}
}
6 changes: 2 additions & 4 deletions async-raft/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,10 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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.
Expand Down Expand Up @@ -763,7 +762,6 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
struct ReplicationState<D: AppData> {
pub match_index: u64,
pub match_term: u64,
pub is_at_line_rate: bool,
pub remove_after_commit: Option<u64>,
pub replstream: ReplicationStream<D>,
}
Expand Down
5 changes: 1 addition & 4 deletions async-raft/src/core/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
ReplicationState {
match_index: self.core.last_log_index,
match_term: self.core.current_term,
is_at_line_rate: false,
replstream,
remove_after_commit: None,
}
Expand Down Expand Up @@ -83,13 +82,11 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
#[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 {
Expand Down
3 changes: 1 addition & 2 deletions async-raft/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
40 changes: 16 additions & 24 deletions async-raft/src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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.
Expand All @@ -135,10 +134,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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.
Expand All @@ -155,10 +153,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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.
Expand All @@ -182,10 +179,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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).
Expand Down Expand Up @@ -215,10 +211,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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.
Expand Down Expand Up @@ -256,10 +251,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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).
Expand All @@ -281,10 +275,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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).
Expand All @@ -308,10 +301,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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.
Expand Down
8 changes: 4 additions & 4 deletions async-raft/src/replication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +33,7 @@ use crate::RaftStorage;
/// The public handle to a spawned replication stream.
pub(crate) struct ReplicationStream<D: AppData> {
/// 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<RaftEvent<D>>,
}
Expand Down Expand Up @@ -192,9 +192,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>>
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,
}
}
Expand Down
6 changes: 3 additions & 3 deletions async-raft/tests/conflict_with_empty_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions memstore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2021-06-01

0 comments on commit 11cb545

Please sign in to comment.