From 218358bbbd6ed9b717db50868ca069a3731e08b2 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 10 Feb 2014 23:48:42 +0100 Subject: [PATCH] Cluster: conditions to clear "migrating" on slot for SETSLOT ... NODE changed. If the slot is manually assigned to another node, clear the migrating status regardless of the fact it was previously assigned to us or not, as long as we no longer have keys for this slot. This avoid a race during slots migration that may leave the slot in migrating status in the source node, since it received an update message from the destination node that is already claiming the slot. This way we are sure that redis-trib at the end of the slot migration is always able to close the slot correctly. --- src/cluster.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index f9899fae..8296e1c3 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -3154,10 +3154,10 @@ void clusterCommand(redisClient *c) { return; } } - /* If this node was the slot owner and the slot was marked as - * migrating, assigning the slot to another node will clear + /* If this slot is in migrating status but we have no keys + * for it assigning the slot to another node will clear * the migratig status. */ - if (server.cluster->slots[slot] == myself && + if (countKeysInSlot(slot) == 0 && server.cluster->migrating_slots_to[slot]) server.cluster->migrating_slots_to[slot] = NULL;