Repository navigation
fix: size redis command round counters by enum range - #522
Conversation
redis_cmd_current_rounds_ was sized by the number of registered commands but indexed by the RedisCommandType enum value. Optional commands are pinned with gaps at 176-186 (COMPACT/FAULT_INJECT/ELOQVEC_*/KEYSPACE), so their enum values exceed the registered-command count and indexing them read/wrote past the buffer (caught by ASan when running fault_inject). Size the per-core vector by the enum value range instead.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughUpdates Redis metrics initialization to use a fixed 256-slot vector for ChangesMetrics vector sizing fix
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/redis_service.cpp (1)
741-750: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGood fix, but consider guarding against future enum growth.
The fixed size of 256 correctly covers the pinned enum gaps described in the PR objectives. To prevent this bug from silently reoccurring if
RedisCommandTypegrows past 256, consider a compile-time guard tied to the enum's max value.♻️ Suggested defensive guard
if (metrics::enable_metrics) { redis_cmd_current_rounds_.resize(core_num_); for (auto &vec : redis_cmd_current_rounds_) { + // NOLINTNEXTLINE if RedisCommandType ever exceeds 256, bump this. + static_assert(static_cast<size_t>(RedisCommandType::MAX_VALUE) < 256, + "redis_cmd_current_rounds_ sizing must cover enum range"); // Indexed by RedisCommandType, whose values are pinned with gaps // (optional commands occupy 176-186), so size by the enum range // rather than the number of registered commands. vec.resize(256, 1); }(Adjust
RedisCommandType::MAX_VALUEto whatever the actual last/sentinel enumerator is named.)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/redis_service.cpp` around lines 741 - 750, The fixed 256 resize in the metrics initialization is fine for the current enum gaps, but `redis_cmd_current_rounds_` should be protected against future `RedisCommandType` growth. Add a compile-time guard in the same initialization area that checks the enum’s maximum/sentinel value (for example the last `RedisCommandType` enumerator used by the command indexing logic) and fails the build if it exceeds the 256 slot capacity, so `redis_service.cpp` cannot silently overflow this assumption later.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/redis_service.cpp`:
- Around line 741-750: The fixed 256 resize in the metrics initialization is
fine for the current enum gaps, but `redis_cmd_current_rounds_` should be
protected against future `RedisCommandType` growth. Add a compile-time guard in
the same initialization area that checks the enum’s maximum/sentinel value (for
example the last `RedisCommandType` enumerator used by the command indexing
logic) and fails the build if it exceeds the 256 slot capacity, so
`redis_service.cpp` cannot silently overflow this assumption later.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0c54252a-3407-4819-8a81-0afb4a140a37
📒 Files selected for processing (1)
src/redis_service.cpp
redis_cmd_current_rounds_ was sized by the number of registered commands but indexed by the RedisCommandType enum value. Optional commands are pinned with gaps at 176-186 (COMPACT/FAULT_INJECT/ELOQVEC_*/KEYSPACE), so their enum values exceed the registered-command count and indexing them read/wrote past the buffer (caught by ASan when running fault_inject). Size the per-core vector by the enum value range instead.
Summary by CodeRabbit