Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

chore: bench improvements#206

Merged
shikhar merged 7 commits intomainfrom
benchdeb
Jan 25, 2026
Merged

chore: bench improvements#206
shikhar merged 7 commits intomainfrom
benchdeb

Conversation

@shikhar
Copy link
Member

@shikhar shikhar commented Jan 25, 2026

No description provided.

@shikhar shikhar changed the title bench chore: bench improvements Jan 25, 2026
@shikhar shikhar marked this pull request as ready for review January 25, 2026 02:11
@shikhar shikhar requested a review from a team as a code owner January 25, 2026 02:11
@greptile-apps
Copy link

greptile-apps bot commented Jan 25, 2026

Greptile Overview

Greptile Summary

This PR improves the benchmarking functionality in the S2 CLI with better verification and cleaner code.

Key Changes:

  • Improved hash verification: replaced run_hasher (which hashed all hash values) with chain_hash tracking that stores only the final hash in the chain, making verification more efficient and meaningful
  • Added duplicate detection: introduced check for header_hash == prev_hash to catch duplicate records at src/bench.rs:360
  • Added record count validation: verifies that write and read record counts match for both live reads and catchup reads at src/bench.rs:627-634 and src/bench.rs:693-701
  • Refactored record creation: renamed record() to new_record() and changed it to use .expect("valid") instead of returning Result, simplifying error handling
  • Cleaner error handling: simplified bench cleanup in src/main.rs:539-551 using ? operator instead of manual result unwrapping
  • Dependency updates: updated s2-sdk to 0.23.0 and uuid to 1.20.0

The changes strengthen data integrity verification by ensuring the hash chain is continuous (no duplicates) and complete (same record count), while also making the code more maintainable.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured improvements to verification logic with no breaking changes or risky patterns. The new duplicate detection and record count validation strengthen correctness guarantees. Error handling simplification is idiomatic Rust. All changes are isolated to benchmarking code with clear semantics.
  • No files require special attention

Important Files Changed

Filename Overview
src/bench.rs improved hash verification with chain hash tracking, duplicate detection, and record count validation
src/main.rs simplified error handling using ? operator instead of manual result unwrapping

Sequence Diagram

sequenceDiagram
    participant Main
    participant BenchRun
    participant Writer as bench_write
    participant Reader as bench_read
    participant CatchupReader as bench_read_catchup
    participant Stream as S2Stream

    Main->>BenchRun: run(stream, params)
    BenchRun->>Writer: spawn write task
    BenchRun->>Reader: spawn read task
    
    par Write Path
        loop until duration or stop
            Writer->>Writer: generate record body with chain_hash(prev_hash, body)
            Writer->>Stream: submit record with hash header
            Stream-->>Writer: ack
            Writer->>Writer: update prev_hash
            Writer->>BenchRun: yield BenchWriteSample
        end
        Writer->>Writer: set chain_hash = prev_hash
        Writer->>BenchRun: final sample with chain_hash
    and Read Path
        loop until write done
            Reader->>Stream: read batch
            Stream-->>Reader: batch with records
            Reader->>Reader: extract header_hash from record
            Reader->>Reader: check header_hash != prev_hash (duplicate check)
            Reader->>Reader: compute chain_hash(prev_hash, body)
            Reader->>Reader: verify computed_hash == header_hash
            Reader->>Reader: update prev_hash = computed_hash
            Reader->>BenchRun: yield BenchReadSample
        end
        Reader->>Reader: set chain_hash = prev_hash
        Reader->>BenchRun: final sample with chain_hash
    end
    
    BenchRun->>BenchRun: verify write_sample.records == read_sample.records
    BenchRun->>BenchRun: verify write_chain_hash == read_chain_hash
    
    BenchRun->>CatchupReader: bench_read_catchup()
    loop read all written records
        CatchupReader->>Stream: read batch
        Stream-->>CatchupReader: batch
        CatchupReader->>CatchupReader: verify hash chain
        CatchupReader->>BenchRun: yield sample
    end
    CatchupReader->>BenchRun: final sample with chain_hash
    
    BenchRun->>BenchRun: verify write_sample.records == catchup_sample.records
    BenchRun->>BenchRun: verify write_chain_hash == catchup_chain_hash
    BenchRun-->>Main: Ok(())
Loading

@shikhar shikhar merged commit 01368f0 into main Jan 25, 2026
6 checks passed
@shikhar shikhar deleted the benchdeb branch January 25, 2026 02:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant