Refactor some of ASM and slot-stats functions#17
Conversation
WalkthroughThe pull request refactors cluster initialization and slot management by introducing centralized initialization functions, replacing legacy auxiliary startup steps and cron hooks, and updating server startup and maintenance loops to use the new patterns. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/cluster.c`:
- Around line 2135-2141: The allocation for server.cluster_slot_stats in
clusterCommonInit uses deprecated malloc; replace it with Redis's allocator
(e.g., zmalloc or zcalloc) so CI doesn't fail. Update the assignment of
server.cluster_slot_stats to use zmalloc/zcalloc with the size computed from
CLUSTER_SLOTS and sizeof(clusterSlotStat) (or use zcalloc to get zeroed memory
if resetClusterStats relies on zeroed state), and ensure any necessary include
for the Redis allocator is present; keep the rest of clusterCommonInit
(resetClusterStats, asmInit) unchanged.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/cluster.csrc/cluster.hsrc/cluster_legacy.csrc/server.c
🧰 Additional context used
🧬 Code graph analysis (4)
src/cluster.c (3)
src/cluster_asm.c (2)
clusterMigrationCommand(992-1007)clusterSyncSlotsCommand(1764-2091)src/cluster_legacy.c (4)
clusterNodeIsSlave(5923-5925)getMyClusterNode(5832-5834)getImportingSlotSource(6491-6493)clusterClaimUnassignedSlots(5262-5284)src/kvstore.c (1)
kvstoreSize(329-331)
src/cluster.h (1)
src/cluster.c (1)
clusterCommonInit(2137-2141)
src/server.c (3)
src/cluster_asm.c (2)
asmCron(2507-2576)asmBeforeSleep(2463-2505)src/cluster_legacy.c (2)
clusterCron(4731-4935)clusterBeforeSleep(4942-4976)src/cluster.c (1)
clusterCommonInit(2137-2141)
src/cluster_legacy.c (1)
src/cluster.c (1)
countKeysInSlot(820-822)
🪛 GitHub Actions: CI
src/cluster.c
[error] 2138-2138: clusterCommonInit: 'malloc' is deprecated [-Werror=deprecated-declarations]. Warnings are treated as errors during build.
src/cluster.h
[error] 1-1: Command failed: make -C src all (cluster.o build error).
src/server.c
[error] 1-1: Command failed: make -C src all (cluster.o build error).
src/cluster_legacy.c
[error] 1-1: Command failed: make -C src all (cluster.o build error).
🪛 GitHub Actions: Codecov
src/cluster.c
[error] 2138-2138: malloc is deprecated and treated as an error by the compiler (-Werror=deprecated-declarations). This usage occurs in clusterCommonInit at cluster.c:2138.
🪛 GitHub Actions: External Server Tests
src/cluster.c
[error] 2138-2138: Command 'make REDIS_CFLAGS=-Werror' failed: 'malloc' is deprecated (deprecated-declarations) in clusterCommonInit. Remove deprecated usage or replace with a supported allocation pattern.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Analyze (cpp)
- GitHub Check: build-old-chain-jemalloc
- GitHub Check: build-old-chain-jemalloc
🔇 Additional comments (9)
src/cluster.h (1)
86-92: No action required. The declarations forclusterCommonInit()(line 89) andclusterClaimUnassignedSlots()(line 92) are both properly implemented. Bothcluster.oandcluster_legacy.oare unconditionally linked in the standard build, so there is no risk of link errors from missing definitions.src/server.c (3)
1657-1660: LGTM — ASM cron integrated ahead of cluster cron.
Line 1657-1660: RunningasmCron()beforeclusterCron()keeps ASM task retries/timeouts progressing without changing cluster tick cadence.
1841-1844: LGTM — ASM before-sleep hook added alongside cluster maintenance.
Line 1841-1844: ASM pre-sleep work is still executed beforeblockedBeforeSleep(), so task state can advance without delaying blocked-client handling.
7739-7741: Code wiring is correct; no build issues detected.Verification confirms:
clusterCommonInitprototype (cluster.h:89) matches definition (cluster.c:2137)- Slot-stats (
server.cluster_slot_stats) allocated exactly once at cluster.c:2138 insideclusterCommonInit()- Function call sequence at server.c:7740 correctly invokes
clusterCommonInit()beforeclusterInit()The dependency chain is properly established and no prototype/definition mismatches or multiple initialization sites exist.
src/cluster.c (4)
1092-1095: LGTM: ASM subcommands are now wired intoclusterCommand.The routing looks consistent with the existing dispatch pattern.
2126-2134: Reset path looks consistent.The guard on
server.cluster_enabledkeeps this safe during non-cluster startup.
2143-2169: LGTM: unowned slot cleanup is safely gated to masters.The checks for ownership/importing align with the intended cleanup behavior.
2172-2214: LGTM: startup verification flow is clear and centralized.The sequence (DB check → delete unowned → claim unassigned) reads well.
src/cluster_legacy.c (1)
5259-5284: No action needed.clusterClaimUnassignedSlots()is called only once at server startup withinverifyClusterConfigWithData(), which is invoked insrc/server.cline 7768 during the server initialization sequence (after loading data from disk and before accepting connections). There is no risk of repeated invocations causing latency, and deferral is not necessary.Likely an incorrect or invalid review comment.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| /* 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)); | ||
| resetClusterStats(); | ||
| asmInit(); | ||
| } |
There was a problem hiding this comment.
Replace deprecated malloc to fix CI build failure (Line 2138).
The pipeline is failing on -Werror=deprecated-declarations. Use Redis’s allocator instead.
🐛 Proposed fix
- server.cluster_slot_stats = malloc(CLUSTER_SLOTS*sizeof(clusterSlotStat));
+ server.cluster_slot_stats = zcalloc(CLUSTER_SLOTS * sizeof(clusterSlotStat));🧰 Tools
🪛 GitHub Actions: CI
[error] 2138-2138: clusterCommonInit: 'malloc' is deprecated [-Werror=deprecated-declarations]. Warnings are treated as errors during build.
🪛 GitHub Actions: Codecov
[error] 2138-2138: malloc is deprecated and treated as an error by the compiler (-Werror=deprecated-declarations). This usage occurs in clusterCommonInit at cluster.c:2138.
🪛 GitHub Actions: External Server Tests
[error] 2138-2138: Command 'make REDIS_CFLAGS=-Werror' failed: 'malloc' is deprecated (deprecated-declarations) in clusterCommonInit. Remove deprecated usage or replace with a supported allocation pattern.
🤖 Prompt for AI Agents
In `@src/cluster.c` around lines 2135 - 2141, The allocation for
server.cluster_slot_stats in clusterCommonInit uses deprecated malloc; replace
it with Redis's allocator (e.g., zmalloc or zcalloc) so CI doesn't fail. Update
the assignment of server.cluster_slot_stats to use zmalloc/zcalloc with the size
computed from CLUSTER_SLOTS and sizeof(clusterSlotStat) (or use zcalloc to get
zeroed memory if resetClusterStats relies on zeroed state), and ensure any
necessary include for the Redis allocator is present; keep the rest of
clusterCommonInit (resetClusterStats, asmInit) unchanged.
Benchmark PR from qodo-benchmark#96
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.