Skip to content

Commit

Permalink
chore: update CI toolchain and clean up code (#244)
Browse files Browse the repository at this point in the history
Update toolchain to 2022-07-13, add a makefile.

A few minor refactorings:
- Refactor `scan_messages` interface to share more code paths, and add tests for them.
- Hide `LogFileFormat` from outer crate, it should stay an implementation detail of file_pipe_log.
- Change `DataLayout` to `u64`, because otherwise it needs additional care to make sure `Alignment(0)` and `NoAlignment` don't coexist.
- Remove some tests that aren't very useful.

Signed-off-by: tabokie <[email protected]>
  • Loading branch information
tabokie authored Aug 3, 2022
1 parent c3a6156 commit 6a6fe3b
Show file tree
Hide file tree
Showing 24 changed files with 664 additions and 1,004 deletions.
39 changes: 19 additions & 20 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2022-05-01
toolchain: nightly-2022-07-13
override: true
components: rustfmt, clippy, rust-src
- uses: Swatinem/rust-cache@v1
Expand All @@ -29,24 +29,24 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }}
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
- name: Format
run: cargo fmt --all -- --check
run: |
make format
git diff --exit-code
- name: Clippy
run: cargo clippy --all --all-features --all-targets -- -D clippy::all
run: make clippy
- name: Run tests
run: |
cargo test --all --features all_except_failpoints --verbose -- --nocapture
cargo test --test failpoints --all-features --verbose -- --test-threads 1 --nocapture
run: make test
env:
RUST_BACKTRACE: 1
EXTRA_CARGO_ARGS: '--verbose'
- name: Run asan tests
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
cargo test -Zbuild-std --target x86_64-unknown-linux-gnu --all --features all_except_failpoints --verbose -- --nocapture
cargo test -Zbuild-std --target x86_64-unknown-linux-gnu --test failpoints --all-features --verbose -- --test-threads 1 --nocapture
run: make test
env:
RUST_BACKTRACE: 1
RUSTFLAGS: '-Zsanitizer=address'
RUSTDOCFLAGS: '-Zsanitizer=address'
EXTRA_CARGO_ARGS: '--verbose -Zbuild-std --target x86_64-unknown-linux-gnu'
stable:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -66,16 +66,16 @@ jobs:
- uses: Swatinem/rust-cache@v1
with:
sharedKey: ${{ matrix.os }}-stable
- name: Format
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all --features all_stable --all-targets -- -D clippy::all
run: make clippy
env:
WITH_STABLE_TOOLCHAIN: 'true'
- name: Run tests
run: |
cargo test --all --features all_stable_except_failpoints --verbose -- --nocapture
cargo test --test failpoints --features all_stable --verbose -- --test-threads 1 --nocapture
run: make test
env:
RUST_BACKTRACE: 1
EXTRA_CARGO_ARGS: '--verbose'
WITH_STABLE_TOOLCHAIN: 'true'
coverage:
runs-on: ubuntu-latest
needs: nightly
Expand All @@ -87,7 +87,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2022-05-01
toolchain: nightly-2022-07-13
override: true
components: llvm-tools-preview
- uses: Swatinem/rust-cache@v1
Expand All @@ -97,13 +97,12 @@ jobs:
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install --locked grcov; fi
- name: Run tests
run: |
cargo test --all --features all_except_failpoints
cargo test --test failpoints --all-features -- --test-threads 1
cargo test --all --features all_stable_except_failpoints
cargo test --test failpoints --features all_stable -- --test-threads 1
make test
env WITH_STABLE_TOOLCHAIN=true make test
env:
RUSTFLAGS: '-Zinstrument-coverage'
LLVM_PROFILE_FILE: '%p-%m.profraw'
EXTRA_CARGO_ARGS: '--verbose'
- name: Run grcov
run: grcov `find . \( -name "*.profraw" \) -print` --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov
- name: Upload
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Makefile

## Additionaly arguments passed to cargo.
EXTRA_CARGO_ARGS ?=
## Whether to disable nightly-only feature. [true/false]
WITH_STABLE_TOOLCHAIN ?=

.PHONY: format clippy test

all: format clippy test

## Format code in-place using rustfmt.
format:
cargo fmt --all

## Run clippy.
ifeq ($(WITH_STABLE_TOOLCHAIN), true)
clippy:
cargo clippy --all --features all_stable --all-targets -- -D clippy::all
else
clippy:
cargo clippy --all --all-features --all-targets -- -D clippy::all
endif

## Run tests.
ifeq ($(WITH_STABLE_TOOLCHAIN), true)
test:
cargo test --all --features all_stable_except_failpoints ${EXTRA_CARGO_ARGS} -- --nocapture
cargo test --test failpoints --features all_stable ${EXTRA_CARGO_ARGS} -- --test-threads 1 --nocapture
else
test:
cargo test --all --features all_except_failpoints ${EXTRA_CARGO_ARGS} -- --nocapture
cargo test --test failpoints --all-features ${EXTRA_CARGO_ARGS} -- --test-threads 1 --nocapture
endif
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ Contributions are always welcome! Here are a few tips for making a PR:
- Tests are automatically run against the changes, some of them can be run locally:

```
cargo fmt --all -- --check
cargo +nightly clippy --all --all-features --all-targets -- -D clippy::all
cargo +nightly test --all --features all_except_failpoints
cargo +nightly test --test failpoints --all-features -- --test-threads 1
# rustup default nightly
make
# rustup default stable
env WITH_STABLE_TOOLCHAIN=true make
# filter a specific test case
env EXTRA_CARGO_ARGS=<testname> make test
```

- 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
17 changes: 8 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{util::ReadableSize, Result};
const MIN_RECOVERY_READ_BLOCK_SIZE: usize = 512;
const MIN_RECOVERY_THREADS: usize = 1;

#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum RecoveryMode {
AbsoluteConsistency,
Expand Down Expand Up @@ -84,12 +84,11 @@ pub struct Config {
/// Default: None
pub memory_limit: Option<ReadableSize>,

/// Whether to recycle stale logs.
/// If `true`, `purge` operations on logs will firstly put stale
/// files into a list for recycle. It's only available if
/// `format_version` >= `2`.
/// Whether to recycle stale log files.
/// If `true`, logically purged log files will be reserved for recycling.
/// Only available for `format_version` 2 and above.
///
/// Default: false,
/// Default: false
pub enable_log_recycle: bool,
}

Expand Down Expand Up @@ -152,19 +151,19 @@ impl Config {
if self.enable_log_recycle {
if !self.format_version.has_log_signing() {
return Err(box_err!(
"format_version: {:?} is invalid when 'enable_log_recycle' on, setting it to V2",
"format version {} doesn't support log recycle, use 2 or above",
self.format_version
));
}
if self.purge_threshold.0 / self.target_file_size.0 >= std::u32::MAX as u64 {
return Err(box_err!(
"File count exceed UINT32_MAX, calculated by 'purge-threshold / target-file-size'"
"File count exceed u32::MAX, calculated by `purge-threshold / target-file-size`"
));
}
}
#[cfg(not(feature = "swap"))]
if self.memory_limit.is_some() {
warn!("memory-limit will be ignored because swap feature is not enabled");
warn!("memory-limit will be ignored because swap feature is disabled");
}
Ok(())
}
Expand Down
Loading

0 comments on commit 6a6fe3b

Please sign in to comment.