mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-17 12:00:44 +02:00
* rust: apply clippy --fix to both crates The mechanical part of a clippy sweep: `cargo clippy --all-targets --fix` on seaweed-volume and the seaweed-worker workspace, hand-reviewed. Both manifests declare their MSRV (1.91.1 and 1.94.1), so every suggestion clippy applied is within it: the collapsible_if sites become let chains (1.88, edition 2024), `% n == 0` becomes is_multiple_of (1.87), chunks_exact with a constant becomes as_chunks (1.88), repeat().take() becomes repeat_n (1.82), and io::Error::new(Other, ..) becomes io::Error::other (1.74). The rest is redundant clones, borrows, casts, closures and field names. Nothing here changes behaviour. The three let_and_return sites in needle_map.rs and store_ec.rs deserve a note: the `let result = ..; result` shape was a deliberate edition-2021 workaround to drop a redb guard before the table it borrows. Edition 2024 drops tail-expression temporaries before locals, which is why clippy now flags it, and the two comments that described the workaround say so instead. Manual edits on top of the tool output: the blocks clippy rewrote are re-indented the way rustfmt lays them out (only those blocks — the crate is not rustfmt-clean and a whole-crate fmt would bury this diff), the blank lines let_and_return left behind are removed, and the CRC legacy_value test compares against a literal worked out from the original shift formula rather than restating rotate_right. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CjZY429aVU74SLDmo1wiuU * rust: clear the clippy warnings --fix cannot apply, and say why the rest stay Hand fixes for the lints clippy only reports. Behaviour is unchanged throughout; each rewrite is the one clippy names. - needless_range_loop (7): index loops over shard vectors become iterator loops. Where the old code indexed `v[..n]` the new loop iterates `v[..n]` so an undersized vector still panics the same way. - field_reassign_with_default (6): struct literals with `..Default`. - redundant_pattern_matching (3): `if let Err(_) = guard.check()` becomes `.is_err()`, which also releases the read guard at the end of the condition instead of at the end of the block. - manual_strip (2), manual_checked_ops, format_in_format_args, redundant_locals, wrong_self_convention (to_vif takes self by value, so it is into_vif; CompactEntry is Copy, so to_needle_value takes self). - type_complexity (2): `OrphanShardLoad` and `RawNeedleEntry` name two tuples that were spelled out inline. - new_without_default: CompactNeedleMap gets a Default that calls new(). - suspicious_open_options: a test helper spells out `.truncate(false)`, which is what `.create(true).write(true)` already did. What stays, and the attribute that says so: - too_many_arguments (10): `#[expect]` on each function. Folding 8–15 parameters into a struct is a design change, not a lint fix. - await_holding_lock / readonly_write_lock: one test holds the store write guard across a sleep on purpose, as a barrier that parks the copy task at the mount block. `#[expect(.., reason = ..)]` records it. - module_inception: needle/needle.rs mirrors the Go package layout. Two lints become crate-wide policy in `[lints.clippy]`, with the reason next to each: result_large_err, because every RPC path returns tonic::Status (176 bytes) and boxing it would change every handler signature; and needless_update, because `..Default::default()` on a protobuf message literal is what lets a proto gain a field without touching every constructor (all 11 sites are pb messages). The worker workspace gets the same table and its members opt in with `lints.workspace = true`; its generated plugin.rs also allows large_enum_variant on prost's oneof enums. Both crates are now clean under `cargo clippy --all-targets -- -D warnings`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CjZY429aVU74SLDmo1wiuU * rust volume: use the std APIs the 1.91 MSRV already pays for The crate declares rust-version 1.91.1, so a few things the code still worked around are plain std now. All of them come from the 1.85–1.91 release notes; nothing here needs a newer toolchain than the manifest already requires. - std::sync::LazyLock (1.80) replaces the lazy_static! block in metrics.rs, and the lazy_static dependency goes. Every use site reads the same through Deref, so no caller changes. - Duration::from_mins / from_hours (1.91) replace `from_secs(v * 60)` and `from_secs(v * 3600)` in the option parser and the shard-location refresh TTLs. One difference for the parser: an absurd count that overflows u64 seconds now panics in release builds too, where the multiplication used to wrap. - Result::flatten (1.89) replaces `.and_then(|r| r)` on the replication join handle. - OsStr::display (1.87) replaces `to_string_lossy()` where the name was only being formatted; the output is byte-identical. - `#[allow]` becomes `#[expect]` (1.81) on the suppressions that are meant to be permanent, so a suppression that stops being needed becomes a warning rather than lingering. Doing that found four that already had: dead_code on ChunkManifest, base_name and last_io_error, and too_many_arguments on read_from_data_shards, which is down to seven parameters. Those attributes are deleted. The three allows that depend on cfg (a unix-only mutation, a linux-only field set, a profiling-only parameter) stay as allow, because expect would be unfulfilled on the other platforms. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CjZY429aVU74SLDmo1wiuU * ci: add a commented-out clippy step to both Rust workflows Both crates are warning-free under `cargo clippy --all-targets -D warnings` now. Whether that becomes a gate is a policy call, so the step is present but commented out; uncommenting it is the whole change. The comment points at the `[lints.clippy]` table where crate-wide exceptions are recorded, so the gate does not become a reason to sprinkle allows. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CjZY429aVU74SLDmo1wiuU * rust volume: guard parse_duration against overflow panics Duration::from_mins/from_hours panic when the count overflows u64 seconds. Use checked_mul so an oversized CLI value falls back to the parser default instead of crashing volume startup. --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Chris Lu <chris.lu@gmail.com>
245 lines
9.0 KiB
YAML
245 lines
9.0 KiB
YAML
name: "Rust Volume Server Tests"
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [ master ]
|
|
paths:
|
|
- 'seaweed-volume/**'
|
|
- 'test/volume_server/**'
|
|
- 'weed/pb/volume_server.proto'
|
|
- 'weed/pb/volume_server_pb/**'
|
|
- '.github/workflows/rust-volume-server-tests.yml'
|
|
push:
|
|
branches: [ master, main ]
|
|
paths:
|
|
- 'seaweed-volume/**'
|
|
- 'test/volume_server/**'
|
|
- 'weed/pb/volume_server.proto'
|
|
- 'weed/pb/volume_server_pb/**'
|
|
- '.github/workflows/rust-volume-server-tests.yml'
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
|
|
jobs:
|
|
rust-unit-tests:
|
|
name: Rust Unit Tests
|
|
runs-on: ubuntu-22.04
|
|
timeout-minutes: 15
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v7
|
|
|
|
- name: Install Rust toolchain
|
|
uses: dtolnay/rust-toolchain@stable
|
|
|
|
# cargo tracks its own inputs but not the runner's C toolchain, so a cached
|
|
# target/ can carry C objects built against a different glibc than we link against.
|
|
- name: Fingerprint build toolchain
|
|
id: toolchain
|
|
run: echo "fingerprint=$(getconf GNU_LIBC_VERSION | tr ' ' '-')-rustc-$(rustc -V | awk '{print $2}')" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Cache cargo registry and target
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
seaweed-volume/target
|
|
key: rust-${{ steps.toolchain.outputs.fingerprint }}-${{ hashFiles('seaweed-volume/Cargo.lock') }}
|
|
restore-keys: |
|
|
rust-${{ steps.toolchain.outputs.fingerprint }}-
|
|
|
|
- name: Build Rust volume server
|
|
run: cd seaweed-volume && cargo build --release
|
|
|
|
# The crate is warning-free under clippy as of the sweep that added
|
|
# this step. Uncomment to make that a gate; `[lints.clippy]` in
|
|
# seaweed-volume/Cargo.toml is where crate-wide exceptions live.
|
|
# - name: Clippy
|
|
# run: cd seaweed-volume && cargo clippy --all-targets -- -D warnings
|
|
|
|
- name: Run Rust unit tests
|
|
run: cd seaweed-volume && cargo test
|
|
|
|
- name: Run Rust unit tests (redb experimental cursor)
|
|
run: cd seaweed-volume && cargo test --features redb-experimental-cursor --lib storage::needle_map
|
|
|
|
rust-integration-tests:
|
|
name: Rust Integration Tests
|
|
runs-on: ubuntu-22.04
|
|
timeout-minutes: 30
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v7
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: 'go.mod'
|
|
|
|
- name: Install Rust toolchain
|
|
uses: dtolnay/rust-toolchain@stable
|
|
|
|
# cargo tracks its own inputs but not the runner's C toolchain, so a cached
|
|
# target/ can carry C objects built against a different glibc than we link against.
|
|
- name: Fingerprint build toolchain
|
|
id: toolchain
|
|
run: echo "fingerprint=$(getconf GNU_LIBC_VERSION | tr ' ' '-')-rustc-$(rustc -V | awk '{print $2}')" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Cache cargo registry and target
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
seaweed-volume/target
|
|
key: rust-${{ steps.toolchain.outputs.fingerprint }}-${{ hashFiles('seaweed-volume/Cargo.lock') }}
|
|
restore-keys: |
|
|
rust-${{ steps.toolchain.outputs.fingerprint }}-
|
|
|
|
- name: Build Go weed binary
|
|
run: |
|
|
cd weed
|
|
go build -tags 5BytesOffset -o weed .
|
|
chmod +x weed
|
|
./weed version
|
|
|
|
- name: Build Rust volume binary
|
|
run: cd seaweed-volume && cargo build --release
|
|
|
|
- name: Run integration tests
|
|
env:
|
|
WEED_BINARY: ${{ github.workspace }}/weed/weed
|
|
RUST_VOLUME_BINARY: ${{ github.workspace }}/seaweed-volume/target/release/weed-volume
|
|
run: |
|
|
echo "Running Rust volume server integration tests..."
|
|
go test -v -count=1 -timeout=15m ./test/volume_server/rust/...
|
|
|
|
- name: Collect logs on failure
|
|
if: failure()
|
|
run: |
|
|
mkdir -p /tmp/rust-volume-server-it-logs
|
|
find /tmp -maxdepth 1 -type d -name "seaweedfs_volume_server_it_*" -print -exec cp -r {} /tmp/rust-volume-server-it-logs/ \; || true
|
|
|
|
- name: Archive logs on failure
|
|
if: failure()
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: rust-volume-server-integration-test-logs
|
|
path: /tmp/rust-volume-server-it-logs/
|
|
if-no-files-found: warn
|
|
retention-days: 7
|
|
|
|
- name: Test summary
|
|
if: always()
|
|
run: |
|
|
echo "## Rust Volume Server Integration Test Summary" >> "$GITHUB_STEP_SUMMARY"
|
|
echo "- Suite: test/volume_server/rust" >> "$GITHUB_STEP_SUMMARY"
|
|
echo "- Command: go test -v -count=1 -timeout=15m ./test/volume_server/rust/..." >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
rust-volume-go-tests:
|
|
name: Go Tests with Rust Volume (${{ matrix.test-type }} - Shard ${{ matrix.shard }})
|
|
runs-on: ubuntu-22.04
|
|
timeout-minutes: 45
|
|
env:
|
|
# Keep in step with the length of matrix.shard below.
|
|
SHARD_COUNT: 3
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
test-type: [grpc, http]
|
|
shard: [1, 2, 3]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v7
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: 'go.mod'
|
|
|
|
- name: Install Rust toolchain
|
|
uses: dtolnay/rust-toolchain@stable
|
|
|
|
# cargo tracks its own inputs but not the runner's C toolchain, so a cached
|
|
# target/ can carry C objects built against a different glibc than we link against.
|
|
- name: Fingerprint build toolchain
|
|
id: toolchain
|
|
run: echo "fingerprint=$(getconf GNU_LIBC_VERSION | tr ' ' '-')-rustc-$(rustc -V | awk '{print $2}')" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Cache cargo registry and target
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
seaweed-volume/target
|
|
key: rust-${{ steps.toolchain.outputs.fingerprint }}-${{ hashFiles('seaweed-volume/Cargo.lock') }}
|
|
restore-keys: |
|
|
rust-${{ steps.toolchain.outputs.fingerprint }}-
|
|
|
|
- name: Build Go weed binary
|
|
run: |
|
|
cd weed
|
|
go build -tags 5BytesOffset -o weed .
|
|
chmod +x weed
|
|
./weed version
|
|
|
|
- name: Build Rust volume binary
|
|
run: cd seaweed-volume && cargo build --release
|
|
|
|
# Dealing the listed tests out one by one keeps the shards even. Bucketing
|
|
# them by first letter did not: names cluster, so ^Test[I-S] drew 50 of
|
|
# the 114 grpc tests and ran nearly twice as long as the other two shards.
|
|
- name: Select this shard's tests
|
|
env:
|
|
TEST_TYPE: ${{ matrix.test-type }}
|
|
SHARD: ${{ matrix.shard }}
|
|
run: |
|
|
tests=$(go test -tags 5BytesOffset ./test/volume_server/"$TEST_TYPE"/... -list '.*' | grep '^Test' | sort -u)
|
|
# An empty list would make -run match nothing and the shard pass vacuously.
|
|
[ -n "$tests" ] || { echo "listed no tests in test/volume_server/$TEST_TYPE"; exit 1; }
|
|
selected=$(echo "$tests" | awk -v n="$SHARD_COUNT" -v i="$SHARD" 'NR % n == i - 1')
|
|
echo "shard $SHARD of $SHARD_COUNT runs $(echo "$selected" | wc -l) of $(echo "$tests" | wc -l) tests"
|
|
echo "TEST_PATTERN=^($(echo "$selected" | paste -sd'|' -))\$" >> "$GITHUB_ENV"
|
|
|
|
- name: Run volume server integration tests with Rust volume
|
|
env:
|
|
WEED_BINARY: ${{ github.workspace }}/weed/weed
|
|
RUST_VOLUME_BINARY: ${{ github.workspace }}/seaweed-volume/target/release/weed-volume
|
|
VOLUME_SERVER_IMPL: rust
|
|
run: |
|
|
echo "Running Go volume server tests with Rust volume for ${{ matrix.test-type }} (Shard ${{ matrix.shard }} of ${SHARD_COUNT})..."
|
|
go test -v -count=1 -tags 5BytesOffset -timeout=30m ./test/volume_server/${{ matrix.test-type }}/... -run "${TEST_PATTERN}"
|
|
|
|
- name: Collect logs on failure
|
|
if: failure()
|
|
run: |
|
|
mkdir -p /tmp/rust-volume-go-test-logs
|
|
find /tmp -maxdepth 1 -type d -name "seaweedfs_volume_server_it_*" -print -exec cp -r {} /tmp/rust-volume-go-test-logs/ \; || true
|
|
|
|
- name: Archive logs on failure
|
|
if: failure()
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: rust-volume-go-test-logs-${{ matrix.test-type }}-shard${{ matrix.shard }}
|
|
path: /tmp/rust-volume-go-test-logs/
|
|
if-no-files-found: warn
|
|
retention-days: 7
|
|
|
|
- name: Test summary
|
|
if: always()
|
|
run: |
|
|
echo "## Rust Volume - Go Test Summary (${{ matrix.test-type }} - Shard ${{ matrix.shard }})" >> "$GITHUB_STEP_SUMMARY"
|
|
echo "- Suite: test/volume_server/${{ matrix.test-type }} (shard ${{ matrix.shard }} of ${SHARD_COUNT}, see 'Select this shard's tests' for the split)" >> "$GITHUB_STEP_SUMMARY"
|
|
echo "- Volume server: Rust (VOLUME_SERVER_IMPL=rust)" >> "$GITHUB_STEP_SUMMARY"
|