From 3c8d15f8c3e3aca887555e3509e9c6fe4205ae1e Mon Sep 17 00:00:00 2001 From: Harkrishn Patro Date: Mon, 11 Mar 2024 11:19:30 -0700 Subject: [PATCH] Pick random slot for a node to distribute operation across slots in redis-benchmark (#12986) Distribute operations via `redis-benchmark` on different slots owned by node. `current_slot_index` is never updated hence the value is always `0` and the tag used is always the first slot owned by the node. Hence any read/write operation via `redis-benchmark` in cluster mode always happens on a particular slot. This is inconvenient to load data uniformly via `redis-benchmark`. --- src/redis-benchmark.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 05d054de1..f1cc39a7e 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -166,7 +166,6 @@ typedef struct clusterNode { sds replicate; /* Master ID if node is a slave */ int *slots; int slots_count; - int current_slot_index; int *updated_slots; /* Used by updateClusterSlotsConfiguration */ int updated_slots_count; /* Used by updateClusterSlotsConfiguration */ int replicas_count; @@ -417,7 +416,6 @@ static void setClusterKeyHashTag(client c) { assert(c->thread_id >= 0); clusterNode *node = c->cluster_node; assert(node); - assert(node->current_slot_index < node->slots_count); int is_updating_slots = 0; atomicGet(config.is_updating_slots, is_updating_slots); /* If updateClusterSlotsConfiguration is updating the slots array, @@ -427,7 +425,7 @@ static void setClusterKeyHashTag(client c) { * updateClusterSlotsConfiguration won't actually do anything, since * the updated_slots_count array will be already NULL. */ if (is_updating_slots) updateClusterSlotsConfiguration(); - int slot = node->slots[node->current_slot_index]; + int slot = node->slots[rand() % node->slots_count]; const char *tag = crc16_slot_table[slot]; int taglen = strlen(tag); size_t i; @@ -1047,7 +1045,6 @@ static clusterNode *createClusterNode(char *ip, int port) { node->replicas_count = 0; node->slots = zmalloc(CLUSTER_SLOTS * sizeof(int)); node->slots_count = 0; - node->current_slot_index = 0; node->updated_slots = NULL; node->updated_slots_count = 0; node->migrating = NULL; @@ -1370,7 +1367,6 @@ static void updateClusterSlotsConfiguration(void) { int *oldslots = node->slots; node->slots = node->updated_slots; node->slots_count = node->updated_slots_count; - node->current_slot_index = 0; node->updated_slots = NULL; node->updated_slots_count = 0; zfree(oldslots);