Skip to content

fix: address PR 15 review gaps — verify_invariants, validation, dead code - #20

Merged
nerdsane merged 1 commit into
mainfrom
fix/pr15-review-gaps
Mar 8, 2026
Merged

fix: address PR 15 review gaps — verify_invariants, validation, dead code#20
nerdsane merged 1 commit into
mainfrom
fix/pr15-review-gaps

Conversation

@nerdsane

@nerdsane nerdsane commented Mar 7, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes 5 gaps identified by domain expert review of PR #15 (memory optimizations).

  • CommandExecutor::verify_invariants() — New TigerStyle method checking 3 invariants: orphaned expirations, stale expired keys, empty collections. Called after every eviction in debug builds.
  • ConnectionPoolConfig validationmax_connections > 0 and buffer_pool_size > 0 bounds added to PerformanceConfig::validate()
  • Remove dead key_count field — Was initialized to 0, never updated, never read, had #[allow(dead_code)]
  • Vec::with_capacity() — Pre-allocate expired_keys vec in both eviction methods
  • 4 new tests — ConnectionPoolConfig defaults, TOML parsing, partial TOML, validation errors

What verify_invariants() catches

This closes the gap where a bug like "LPOP forgets to clean up empty list" would only be caught if LLEN happened to be called on that exact key later. Now it's caught immediately after every eviction cycle.

// Invariant 1: every key in expirations exists in data
// Invariant 2: no expired keys remain after eviction
// Invariant 3: no empty collections in data

Test plan

  • 9 executor DST tests pass (verify_invariants fires across 100+ seeds × 1000+ ops)
  • 8 perf_config tests pass (including 4 new)
  • cargo clippy --release -p redis-sim -- -D warnings — 0 warnings

🤖 Generated with Claude Code

…code

Fixes identified by domain expert review of PR 15 (memory optimizations):

1. Add CommandExecutor::verify_invariants() (TigerStyle)
   - Invariant 1: every expiration key exists in data
   - Invariant 2: no expired keys remain after eviction
   - Invariant 3: no empty collections in data
   Called after both eviction methods in debug builds.

2. Add validate() bounds for ConnectionPoolConfig (Rust Style)
   - max_connections must be > 0
   - buffer_pool_size must be > 0

3. Remove dead key_count field from CommandExecutor
   Initialized to 0, never updated, never read. Had #[allow(dead_code)].

4. Use Vec::with_capacity() in eviction (TigerStyle)
   Pre-allocate expired_keys vec at 25% of expirations map size.

5. Add ConnectionPoolConfig test coverage (Rust Style)
   - Default values asserted
   - TOML parsing with and without [connection_pool] section
   - Validation error tests for zero values

Verified: 9 executor DST tests pass (verify_invariants fires on every
eviction across 100+ seeds × 1000+ ops), 8 perf_config tests pass,
0 clippy warnings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nerdsane
nerdsane merged commit 08ff584 into main Mar 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant