Refactor some of ASM and slot-stats functions#26
Conversation
Code Review by Qodo
1. clusterDeleteKeysInUnownedSlots() not static
|
| /* This function is called after the node startup in order to check if there | ||
| * are any slots that we have keys for, but are not assigned to us. If so, | ||
| * we delete the keys. */ | ||
| void clusterDeleteKeysInUnownedSlots(void) { |
There was a problem hiding this comment.
1. clusterdeletekeysinunownedslots() not static 📘 Rule violation ⛯ Reliability
• clusterDeleteKeysInUnownedSlots() is defined without static even though it appears to be an internal helper used only within src/cluster.c. • Leaving it non-static unnecessarily exports the symbol and increases the chance of symbol collisions or unintended external use.
Agent prompt
## Issue description
`clusterDeleteKeysInUnownedSlots()` is an internal helper but is exported as a global symbol because it is not declared `static`.
## Issue Context
This function is used as a helper from within `src/cluster.c` (e.g., by `verifyClusterConfigWithData()`). It should not be externally visible.
## Fix Focus Areas
- src/cluster.c[2143-2214]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| void clusterDeleteKeysInUnownedSlots(void) { | ||
| if (clusterNodeIsSlave(getMyClusterNode())) return; | ||
|
|
||
| /* Check that all the slots we have keys for are assigned to us. Otherwise, | ||
| * delete the keys. */ | ||
| for (int i = 0; i < CLUSTER_SLOTS; i++) { | ||
| /* Skip if: no keys in the slot, it's our slot, or we are importing it. */ | ||
| if (!countKeysInSlot(i) || | ||
| clusterIsMySlot(i) || | ||
| getImportingSlotSource(i)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| serverLog(LL_NOTICE, "I have keys for slot %d, but the slot is " | ||
| "assigned to another node. " | ||
| "Deleting keys in the slot.", i); | ||
| /* With atomic slot migration, it is safe to drop keys from slots | ||
| * that are not owned. This will not result in data loss under the | ||
| * legacy slot migration approach either, since the importing state | ||
| * has already been persisted in node.conf. */ | ||
| clusterDelKeysInSlot(i, 0); | ||
| } |
There was a problem hiding this comment.
2. Deletes unassigned-slot keys 🐞 Bug ✓ Correctness
• clusterDeleteKeysInUnownedSlots() deletes keys for any slot that has keys, is not “my slot”, and is not importing; this also matches slots with no owner (unassigned), so keys in unassigned slots can be deleted at startup. • verifyClusterConfigWithData() then calls clusterClaimUnassignedSlots(), but it can no longer claim those slots because the keys were deleted. • Impact: silent data loss on restart when node.conf lacks slot ownership but DB0 contains keys for those slots.
Agent prompt
### Issue description
`clusterDeleteKeysInUnownedSlots()` currently deletes keys for slots that have keys, are not owned by this node, and are not importing. This condition also matches *unassigned* slots (owner == NULL), which means keys in unassigned slots can be deleted before `clusterClaimUnassignedSlots()` gets a chance to take ownership.
### Issue Context
This runs during `verifyClusterConfigWithData()` after loading data, so it can cause silent data loss at startup.
### Fix Focus Areas
- src/cluster.c[2146-2168]
- src/cluster.c[2209-2213]
- src/cluster.c[1722-1724]
- src/cluster_legacy.c[5266-5283]
- src/cluster_legacy.c[6499-6501]
### Implementation notes
- Add an explicit `if (getNodeBySlot(i) == NULL) continue;` (or equivalent helper) before deleting.
- Consider swapping the order in `verifyClusterConfigWithData()` to claim first, then delete unowned (owned-by-other) slots.
- Update the log text to avoid claiming "assigned to another node" when the slot is actually unassigned.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#4