-
Notifications
You must be signed in to change notification settings - Fork 0
Code Review Bench PR #14637 - Fix adjacent slot range behavior in ASM operations #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: base_pr_14637_20260125_9355
Are you sure you want to change the base?
Code Review Bench PR #14637 - Fix adjacent slot range behavior in ASM operations #2
Conversation
Code Review
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
| int slotRangeArrayIsEqual(slotRangeArray *slots1, slotRangeArray *slots2) { | ||
| if (slots1->num_ranges != slots2->num_ranges) return 0; | ||
|
|
||
| /* Sort slot ranges first */ | ||
| qsort(slots1->ranges, slots1->num_ranges, sizeof(slotRange), compareSlotRange); | ||
| qsort(slots2->ranges, slots2->num_ranges, sizeof(slotRange), compareSlotRange); | ||
| slotRangeArraySortAndMerge(slots1); | ||
| slotRangeArraySortAndMerge(slots2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Bug: slotRangeArrayIsEqual checks count before merging
The num_ranges comparison at line 1877 happens before slotRangeArraySortAndMerge() is called at lines 1879-1880. This means two slot range arrays that represent the same set of slots but have different pre-merge num_ranges will incorrectly be reported as not equal.
For example:
- Array A:
{7000-7001, 7002-7003}→ num_ranges = 2, merges to{7000-7003}(num_ranges = 1) - Array B:
{7000-7003}→ num_ranges = 1
slotRangeArrayIsEqual(A, B) would return 0 at line 1877 before ever merging, even though both arrays represent slots 7000-7003.
The fix is to move the num_ranges comparison after both slotRangeArraySortAndMerge() calls.
Was this helpful? React with 👍 / 👎
| int slotRangeArrayIsEqual(slotRangeArray *slots1, slotRangeArray *slots2) { | |
| if (slots1->num_ranges != slots2->num_ranges) return 0; | |
| /* Sort slot ranges first */ | |
| qsort(slots1->ranges, slots1->num_ranges, sizeof(slotRange), compareSlotRange); | |
| qsort(slots2->ranges, slots2->num_ranges, sizeof(slotRange), compareSlotRange); | |
| slotRangeArraySortAndMerge(slots1); | |
| slotRangeArraySortAndMerge(slots2); | |
| int slotRangeArrayIsEqual(slotRangeArray *slots1, slotRangeArray *slots2) { | |
| slotRangeArraySortAndMerge(slots1); | |
| slotRangeArraySortAndMerge(slots2); | |
| if (slots1->num_ranges != slots2->num_ranges) return 0; | |
| for (int i = 0; i < slots1->num_ranges; i++) { |
- Apply suggested fix
| sds err = NULL; | ||
| if (validateSlotRanges(slots, &err) != C_OK) { | ||
| addReplyErrorSds(c, err); | ||
| if (slotRangeArrayNormalizeAndValidate(slots, &err) != C_OK) { | ||
| sdsfree(err); | ||
| slotRangeArrayFree(slots); | ||
| return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Bug: Validation error silently dropped, no reply sent to client
In parseSlotRangesOrReply, the validation error message from slotRangeArrayNormalizeAndValidate() is silently freed at line 2016 without sending any error reply to the client. The old code was:
addReplyErrorSds(c, err); // sends error AND takes ownership of errThe new code is:
sdsfree(err); // silently discards error messageSince the function name convention is *OrReply (meaning it replies on error), and callers like clusterMigrationCommandImport simply return when parseSlotRangesOrReply returns NULL (trusting that an error was already sent), the client will receive no response at all. This will cause the client connection to hang or timeout.
The fix should restore the error reply to the client. Note that addReplyErrorSds takes ownership of the sds string, so sdsfree(err) should be removed when using it.
Was this helpful? React with 👍 / 👎
| sds err = NULL; | |
| if (validateSlotRanges(slots, &err) != C_OK) { | |
| addReplyErrorSds(c, err); | |
| if (slotRangeArrayNormalizeAndValidate(slots, &err) != C_OK) { | |
| sdsfree(err); | |
| slotRangeArrayFree(slots); | |
| return NULL; | |
| if (slotRangeArrayNormalizeAndValidate(slots, &err) != C_OK) { | |
| addReplyErrorSds(c, err); | |
| slotRangeArrayFree(slots); | |
| return NULL; | |
| } |
- Apply suggested fix
Code Review Bench PR redis#14637 - Fix adjacent slot range behavior in ASM operations
Benchmark PR for Gitar evaluation
Original PR: agentic-review-benchmarks#2
Fix adjacent slot range behavior in ASM operations
Summary by Gitar
slotRangeArraySortAndMerge()to merge adjacent ranges (e.g., 1000-2000 + 2001-3000 → 1000-3000)addReplyErrorSds()withsdsfree()inparseSlotRangesOrReply()to prevent leak+=to=inasmActiveTrimStart()to prevent key count accumulationasmCountKeysInSlots()This will update automatically on new commits.