-
Notifications
You must be signed in to change notification settings - Fork 0
Clean up lookahead-related code #25
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: coderabbit_full_base_clean_up_lookahead-related_code_pr3
Are you sure you want to change the base?
Changes from all commits
e0a9016
2351487
d768d7b
8a3fe63
4689ac1
ec682c6
cfae119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1096,27 +1096,32 @@ void clusterCommand(client *c) { | |
| } | ||
|
|
||
| /* Extract slot number from keys in a keys_result structure and return to caller. | ||
| * Returns INVALID_CLUSTER_SLOT if keys belong to different slots (cross-slot error), | ||
| * or if there are no keys. | ||
| */ | ||
| * Returns: | ||
| * - The slot number if all keys belong to the same slot | ||
| * - INVALID_CLUSTER_SLOT if there are no keys or cluster is disabled | ||
| * - CLUSTER_CROSSSLOT if keys belong to different slots (cross-slot error) */ | ||
| int extractSlotFromKeysResult(robj **argv, getKeysResult *keys_result) { | ||
| if (keys_result->numkeys == 0) | ||
| if (keys_result->numkeys == 0 || !server.cluster_enabled) | ||
| return INVALID_CLUSTER_SLOT; | ||
|
|
||
| if (!server.cluster_enabled) | ||
| return 0; | ||
|
|
||
| int first_slot = INVALID_CLUSTER_SLOT; | ||
| for (int j = 0; j < keys_result->numkeys; j++) { | ||
|
|
||
| /* Allocate temporary buffer for slot tracking */ | ||
| int *slot_buffer = malloc(sizeof(int) * keys_result->numkeys); | ||
|
|
||
| for (int j = 0; j <= keys_result->numkeys; j++) { | ||
| robj *this_key = argv[keys_result->keys[j].pos]; | ||
| int this_slot = (int)keyHashSlot((char*)this_key->ptr, sdslen(this_key->ptr)); | ||
| slot_buffer[j] = this_slot; | ||
|
|
||
| if (first_slot == INVALID_CLUSTER_SLOT) | ||
| first_slot = this_slot; | ||
| else if (first_slot != this_slot) { | ||
| return INVALID_CLUSTER_SLOT; | ||
| free(slot_buffer); | ||
| return CLUSTER_CROSSSLOT; | ||
| } | ||
| } | ||
| free(slot_buffer); | ||
|
Comment on lines
+1110
to
+1124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build failure: Use The pipeline failures indicate that 🔧 Proposed fix /* Allocate temporary buffer for slot tracking */
- int *slot_buffer = malloc(sizeof(int) * keys_result->numkeys);
+ int *slot_buffer = zmalloc(sizeof(int) * keys_result->numkeys);
- for (int j = 0; j <= keys_result->numkeys; j++) {
+ for (int j = 0; j < keys_result->numkeys; j++) {
robj *this_key = argv[keys_result->keys[j].pos];
int this_slot = (int)keyHashSlot((char*)this_key->ptr, sdslen(this_key->ptr));
slot_buffer[j] = this_slot;
if (first_slot == INVALID_CLUSTER_SLOT)
first_slot = this_slot;
else if (first_slot != this_slot) {
- free(slot_buffer);
+ zfree(slot_buffer);
return CLUSTER_CROSSSLOT;
}
}
- free(slot_buffer);
+ zfree(slot_buffer);
return first_slot;🧰 Tools🪛 GitHub Actions: Codecov[error] 1110-1124: lcov: 'malloc' is deprecated and 'free' is deprecated when building with -Werror. Update code to use non-deprecated allocation/free patterns. 🪛 GitHub Actions: External Server Tests[error] 1110-1124: Werror: 'malloc' and 'free' are deprecated declarations. Build failed due to treating deprecated declarations as errors while compiling cluster.c (lines 1110-1124). Command causing the failure: make REDIS_CFLAGS=-Werror (via 'make -C src all'), triggered by -Werror in the build. 🤖 Prompt for AI Agents |
||
| return first_slot; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ static void addReplySortedSlotStats(client *c, slotStatForSort slot_stats[], lon | |
| } | ||
|
|
||
| static int canAddNetworkBytesOut(client *c) { | ||
| return clusterSlotStatsEnabled() && c->slot != -1; | ||
| return clusterSlotStatsEnabled() && c->slot != INVALID_CLUSTER_SLOT; | ||
| } | ||
|
Comment on lines
139
to
141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against CLUSTER_CROSSSLOT to avoid assertion crashes. 🔧 Suggested fixstatic int canAddNetworkBytesOut(client *c) {
- return clusterSlotStatsEnabled() && c->slot != INVALID_CLUSTER_SLOT;
+ return clusterSlotStatsEnabled() && c->slot >= 0;
}
static int canAddCpuDuration(client *c) {
return server.cluster_slot_stats_enabled && /* Config should be enabled. */
server.cluster_enabled && /* Cluster mode should be enabled. */
- c->slot != INVALID_CLUSTER_SLOT && /* Command should be slot specific. */
+ c->slot >= 0 && /* Command should be slot specific. */
(!server.execution_nesting || /* Either command should not be nested, */
(c->realcmd->flags & CMD_BLOCKING)); /* or it must be due to unblocking. */
}
static int canAddNetworkBytesIn(client *c) {
- return clusterSlotStatsEnabled() && c->slot != INVALID_CLUSTER_SLOT &&
+ return clusterSlotStatsEnabled() && c->slot >= 0 &&
!(c->flags & CLIENT_BLOCKED) && !server.in_exec;
}Also applies to: 223-227, 246-253 🤖 Prompt for AI Agents |
||
|
|
||
| /* Accumulates egress bytes upon sending RESP responses back to user clients. */ | ||
|
|
@@ -223,7 +223,7 @@ void clusterSlotStatResetAll(void) { | |
| static int canAddCpuDuration(client *c) { | ||
| return server.cluster_slot_stats_enabled && /* Config should be enabled. */ | ||
| server.cluster_enabled && /* Cluster mode should be enabled. */ | ||
| c->slot != -1 && /* Command should be slot specific. */ | ||
| c->slot != INVALID_CLUSTER_SLOT && /* Command should be slot specific. */ | ||
| (!server.execution_nesting || /* Either command should not be nested, */ | ||
| (c->realcmd->flags & CMD_BLOCKING)); /* or it must be due to unblocking. */ | ||
| } | ||
|
|
@@ -249,7 +249,7 @@ static int canAddNetworkBytesIn(client *c) { | |
| * Third, blocked client is not aggregated, to avoid duplicate aggregation upon unblocking. | ||
| * Fourth, the server is not under a MULTI/EXEC transaction, to avoid duplicate aggregation of | ||
| * EXEC's 14 bytes RESP upon nested call()'s afterCommand(). */ | ||
| return clusterSlotStatsEnabled() && c->slot != -1 && | ||
| return clusterSlotStatsEnabled() && c->slot != INVALID_CLUSTER_SLOT && | ||
| !(c->flags & CLIENT_BLOCKED) && !server.in_exec; | ||
| } | ||
|
|
||
|
|
||
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.
Critical: Off-by-one error causes out-of-bounds array access.
The loop condition
j <= keys_result->numkeysiterates one element past the valid range. Array indices are0tonumkeys - 1, so accessingkeys_result->keys[numkeys]is undefined behavior.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents