Fix HINCRBYFLOAT removes field expiration on replica#9
Conversation
📝 WalkthroughWalkthroughThe changes introduce support for preserving field expiration during HINCRBYFLOAT operations. Two new shared constants (HSETEX and FIELDS) are added to the shared objects infrastructure, the HINCRBYFLOAT replication logic is refactored to use HSETEX with KEEPTTL semantics instead of basic HSET, and a test is added to validate TTL preservation on replicas. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/t_hash.c`:
- Line 2559: The hashTypeSet call is missing the HASH_SET_KEEP_TTL flag causing
TTL loss on master; update the call to use both flags (bitwise OR) so it becomes
HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL, mirroring the usage in hincrbyCommand
(which uses HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL) to preserve field
expiration and keep master/replica consistent (modify the hashTypeSet(c->db, o,
c->argv[2]->ptr, new, ...) invocation accordingly).
🧹 Nitpick comments (1)
tests/unit/type/hash-field-expire.tcl (1)
1990-1996: Consider adding master TTL verification to ensure consistency.The test verifies TTL on the replica but doesn't explicitly check that TTL is preserved on the master after
HINCRBYFLOAT. Adding a master-side assertion would ensure no inconsistency between master and replica.♻️ Proposed addition to verify master TTL
r -1 hincrbyfloat h1 f1 1.1 r -1 hincrbyfloat h1 f2 1.1 + # Verify TTL is preserved on master + assert_range [r -1 httl h1 FIELDS 1 f1] 90 100 + # Expiration time should not be removed on replica and the value # should be equal to the master. wait_for_ofs_sync [srv -1 client] [srv 0 client] assert_range [r httl h1 FIELDS 1 f1] 90 100
| int len = ld2string(buf,sizeof(buf),value,LD_STR_HUMAN); | ||
| new = sdsnewlen(buf,len); | ||
| hashTypeSet(c->db, o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL); | ||
| hashTypeSet(c->db, o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE); |
There was a problem hiding this comment.
Missing HASH_SET_KEEP_TTL flag causes TTL loss on master.
The HASH_SET_KEEP_TTL flag is missing from hashTypeSet. Compare with hincrbyCommand at line 2506 which uses HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL.
Without this flag:
- Master removes the field's TTL during the set operation
- Replica preserves TTL via the replicated
HSETEX ... KEEPTTL ...command - This creates an inconsistency between master and replica
The existing test at line 851-857 (HINCRBYFLOAT - preserve expiration time of the field) verifies TTL preservation locally and would fail with this code.
🐛 Proposed fix to preserve TTL on master
- hashTypeSet(c->db, o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE);
+ hashTypeSet(c->db, o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| hashTypeSet(c->db, o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE); | |
| hashTypeSet(c->db, o,c->argv[2]->ptr,new,HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL); |
🤖 Prompt for AI Agents
In `@src/t_hash.c` at line 2559, The hashTypeSet call is missing the
HASH_SET_KEEP_TTL flag causing TTL loss on master; update the call to use both
flags (bitwise OR) so it becomes HASH_SET_TAKE_VALUE | HASH_SET_KEEP_TTL,
mirroring the usage in hincrbyCommand (which uses HASH_SET_TAKE_VALUE |
HASH_SET_KEEP_TTL) to preserve field expiration and keep master/replica
consistent (modify the hashTypeSet(c->db, o, c->argv[2]->ptr, new, ...)
invocation accordingly).
Benchmark PR from agentic-review-benchmarks#9
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.