Skip to content

Refactor some of ASM and slot-stats functions#4

Open
tomerqodo wants to merge 3 commits intocursor_full_base_refactor_some_of_asm_and_slot-stats_functions_pr4from
cursor_full_head_refactor_some_of_asm_and_slot-stats_functions_pr4
Open

Refactor some of ASM and slot-stats functions#4
tomerqodo wants to merge 3 commits intocursor_full_base_refactor_some_of_asm_and_slot-stats_functions_pr4from
cursor_full_head_refactor_some_of_asm_and_slot-stats_functions_pr4

Conversation

@tomerqodo
Copy link
Copy Markdown

@tomerqodo tomerqodo commented Jan 26, 2026

Benchmark PR from agentic-review-benchmarks#4


Note

  • Centralized init: New clusterCommonInit() sets up cluster_slot_stats and calls asmInit(); used at startup before clusterInit().
  • ASM hooks moved: asmCron() and asmBeforeSleep() now run from server.c alongside clusterCron()/clusterBeforeSleep() instead of legacy cluster paths.
  • Slot verification refactor: verifyClusterConfigWithData() now delegates to clusterDeleteKeysInUnownedSlots() and clusterClaimUnassignedSlots() (legacy impl) to drop keys in non-owned slots and take ownership of unassigned slots with data.
  • Command routing: CLUSTER migration and CLUSTER syncslots handled in common clusterCommand(); removed from legacy handler.
  • Minor cleanups: Removed duplicate/reset logic from legacy init; header updated with clusterCommonInit() and clusterClaimUnassignedSlots() declarations.

Written by Cursor Bugbot for commit 865827b. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/cluster.c
* legacy slot migration approach either, since the importing state
* has already been persisted in node.conf. */
clusterDelKeysInSlot(i, 0);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data loss: keys deleted from unassigned slots before claiming

High Severity

The clusterDeleteKeysInUnownedSlots() function deletes keys from any slot where clusterIsMySlot(i) returns false. However, for unassigned slots (owner is NULL), clusterIsMySlot() also returns false because getNodeBySlot() returns NULL. This causes keys in unassigned slots to be deleted instead of preserved for claiming. When clusterClaimUnassignedSlots() runs afterward, the slots have no keys and won't be claimed, resulting in data loss. The original code explicitly checked server.cluster->slots[j] == NULL to distinguish unassigned slots from slots owned by others.

Additional Locations (1)

Fix in Cursor Fix in Web

Comment thread src/cluster.c
/* This function is called at server startup in order to initialize cluster data
* structures that are shared between the different cluster implementations. */
void clusterCommonInit(void) {
server.cluster_slot_stats = malloc(CLUSTER_SLOTS*sizeof(clusterSlotStat));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using malloc instead of zmalloc breaks memory tracking

Medium Severity

The clusterCommonInit() function uses malloc() for allocating server.cluster_slot_stats, but the original code in server.c used zmalloc(). Redis uses zmalloc for memory tracking and accounting. Using plain malloc bypasses this system, causing inaccurate memory usage reporting and potential inconsistencies.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants