Repository navigation
Conversation
PragmaTwice
self-requested a review
October 10, 2026 13:07
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Timestamp inconsistency can alter expiration semantics, and the slow path can repeatedly rescan large expired prefixes.
3 open findings
What changed in this PR
Fixes stale hash metadata causing newly written fields to inherit an expired hash’s key-level TTL.
Changes:
- Validates HFE metadata before field-creating writes.
- Recreates metadata when no live fields remain.
- Adds stale-TTL regression tests.
| File | Description |
|---|---|
src/types/redis_hash.cc |
Implements metadata validation across hash write paths. |
src/types/redis_hash.h |
Declares the validation helper. |
tests/cppunit/types/hash_test.cc |
Adds regression coverage for stale TTL inheritance. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Fix #3635. When all fields in a hash expire via HFE (Hash Field Expiration), ordinary read operations (e.g. HGET) lazily skip expired fields without repairing the hash metadata. A subsequent write (e.g. HSET) then reuses the stale metadata — including its version and key-level TTL — causing the new field to inherit the old key's expiration.
Root Cause
ExpireFields uses ExpandExpireBounds which only expands lower/upper bounds but never shrinks them. After shortening a field TTL, upper retains the old larger value. When all fields expire, no read-path cleanup occurs (unless an accurate HLEN happens to trigger scanAndRepair). The next write reuses the stale metadata with the old version and key-level TTL.
The Fix
Add ensureValidMetadata that runs unconditionally before any write operation that can create new fields (MSet, IncrBy, IncrByFloat, SetFieldsWithExpire). The function determines whether existing metadata is still valid:
persist > 0: permanent fields exist → metadata is valid → O(1).
persist == 0: all fields carry TTL →
Fast path: now < lower → all TTL fields still alive → valid → O(1).
Fast path: now > upper → all TTL fields expired → invalid → reset → O(1).
Slow path: scan subkeys for the first live field. If found → valid. If none → stale → reset.
Design decisions:
Always runs, not gated by hash-length-mode. This is a correctness fix, not a precision trade-off.
Lightweight scan: no cleanup of expired fields during the check. Expired subkeys are cleaned up by subsequent scanAndRepair, lazy expiry, or compaction.
AI Assistance Disclosure
The code changes and unit tests in this PR were implemented with the assistance of Qoder, an AI-powered coding tool. I have personally reviewed all generated code and tests thoroughly to verify that the logic correctly implements the proposed design, handles edge cases properly, and aligns with the project's coding conventions. All 48 hash unit tests pass.