Skip to content

Commit

Permalink
Merge branch 'master' into extract-fsync-handle
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <mrcroxx@outlook.com>
  • Loading branch information
MrCroxx committed Nov 4, 2021
2 parents c2a5c52 + 829dfc6 commit 790bdce
Show file tree
Hide file tree
Showing 14 changed files with 614 additions and 451 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ jobs:
- name: Clippy
run: cargo clippy --features failpoints --all --all-targets -- -D clippy::all
- name: Run tests
run: RUST_BACKTRACE=1 cargo test --features failpoints --workspace --verbose -- --nocapture --skip test_io_error
- name: Run IO tests
run: RUST_BACKTRACE=1 cargo test --package raft-engine --test failpoints --features failpoints -- --test-threads 1
run: |
cargo test --all --verbose
cargo test --test failpoints --features failpoints --verbose -- --test-threads 1 --nocapture
env:
RUST_BACKTRACE: 1
- name: Run asan tests
if: ${{ matrix.os == 'ubuntu-latest' }}
run: cargo test -Zbuild-std --target x86_64-unknown-linux-gnu --features failpoints --verbose -- --nocapture --skip test_io_error
Expand All @@ -64,7 +66,9 @@ jobs:
- name: Install grcov
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install --locked grcov; fi
- name: Run tests
run: cargo test --features failpoints --all --verbose
run: |
cargo test --all --verbose
cargo test --test failpoints --features failpoints -- --test-threads 1 --nocapture
env:
RUSTFLAGS: '-Zinstrument-coverage'
LLVM_PROFILE_FILE: '%p-%m.profraw'
Expand Down
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ edition = "2018"
name = "append-compact-purge"
path = "examples/append_compact_purge.rs"

[[test]]
name = "failpoints"
path = "tests/failpoints/mod.rs"
required-features = ["failpoints"]

[[bench]]
name = "benches"
path = "tests/benches/mod.rs"
harness = false
required-features = ["failpoints"]

[dependencies]
byteorder = "1.2"
crc32fast = "1.2"
Expand Down Expand Up @@ -52,14 +63,4 @@ protobuf = { git = "https://github.com/pingcap/rust-protobuf", rev = "82b49fea7e
protobuf-codegen = { git = "https://github.com/pingcap/rust-protobuf", rev = "82b49fea7e696fd647b5aca0a6c6ec944eab3189" }

[workspace]
members = ["stress"]

[[bench]]
name = "bench_recovery"
harness = false
required-features = ["failpoints"]

[[test]]
name = "failpoints"
path = "failpoints/mod.rs"
required-features = ["failpoints"]
members = [ "stress" ]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Contributions are always welcome! Here are a few tips for making a PR:
```
cargo fmt --all -- --check
cargo clippy --all --all-targets -- -D clippy::all
cargo test --features failpoints --workspace -- --skip io_error_tests
cargo test --package raft-engine --test io_error_test --features failpoints -- --test-threads 1
cargo test --all
cargo test --test failpoints --features failpoints -- --test-threads 1
```

- For changes that might induce performance effects, please quote the targeted benchmark results in the PR description. In addition to micro-benchmarks, there is a standalone [stress test tool](https://github.com/tikv/raft-engine/tree/master/stress) which you can use to demonstrate the system performance.
Expand Down
1 change: 0 additions & 1 deletion failpoints/mod.rs

This file was deleted.

40 changes: 27 additions & 13 deletions src/consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::Result;

#[derive(Default)]
pub struct ConsistencyChecker {
// Raft group id -> last index
pending: HashMap<u64, u64>,
// Raft group id -> last uncorrupted index
// Raft group id -> first index, last index
raft_groups: HashMap<u64, (u64, u64)>,
// Raft group id -> last unaffected index
corrupted: HashMap<u64, u64>,
}

impl ConsistencyChecker {
pub fn finish(self) -> Vec<(u64, u64)> {
self.corrupted.into_iter().collect()
pub fn finish(self) -> HashMap<u64, u64> {
self.corrupted
}
}

Expand All @@ -29,26 +29,40 @@ impl ReplayMachine for ConsistencyChecker {
let incoming_first_index = ents.0.first().unwrap().index;
let incoming_last_index = ents.0.last().unwrap().index;
let last_index = self
.pending
.raft_groups
.entry(item.raft_group_id)
.or_insert(incoming_last_index);
if *last_index + 1 < incoming_first_index {
.or_insert((incoming_first_index, incoming_last_index));
if last_index.1 + 1 < incoming_first_index {
self.corrupted
.insert(item.raft_group_id, incoming_first_index);
.entry(item.raft_group_id)
.or_insert(last_index.1);
}
*last_index = incoming_last_index;
last_index.1 = incoming_last_index;
}
}
}
Ok(())
}

fn merge(&mut self, mut rhs: Self, _queue: LogQueue) -> Result<()> {
for (id, last_index) in rhs.pending.drain() {
self.pending.insert(id, last_index);
let mut new_corrupted: HashMap<u64, u64> = HashMap::default();
// Find holes between self and rhs.
for (id, (first, last)) in rhs.raft_groups.drain() {
self.raft_groups
.entry(id)
.and_modify(|(_, l)| {
if *l + 1 < first {
new_corrupted.insert(id, *l);
}
*l = last;
})
.or_insert((first, last));
}
for (id, last_index) in new_corrupted.drain() {
self.corrupted.entry(id).or_insert(last_index);
}
for (id, last_index) in rhs.corrupted.drain() {
self.corrupted.insert(id, last_index);
self.corrupted.entry(id).or_insert(last_index);
}
Ok(())
}
Expand Down
Loading

0 comments on commit 790bdce

Please sign in to comment.