diff --git a/src/cluster.c b/src/cluster.c index 162004d703..3cd6527dae 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -108,6 +108,22 @@ ConnectionType *connTypeOfCluster(void) { return connectionTypeTcp(); } +/* Delete unowned keys from database at server start up after loading persistence files. */ +void delUnownedKeys(void) { + if (!server.cluster_enabled) { + return; + } + clusterNode *primary = clusterNodeGetPrimary(server.cluster->myself); + for (unsigned int i = 0; i < CLUSTER_SLOTS; i++) { + if (server.cluster->slots[i] != primary) { + unsigned int deleted = delKeysInSlot(i); + if (deleted > 0) { + serverLog(LL_VERBOSE, "Deleted %u keys from unowned slot: %d after loading RDB", deleted, i); + } + } + } +} + /* ----------------------------------------------------------------------------- * DUMP, RESTORE and MIGRATE commands * -------------------------------------------------------------------------- */ diff --git a/src/cluster.h b/src/cluster.h index aefb3a7b82..8023d6bae0 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -128,4 +128,5 @@ int isNodeAvailable(clusterNode *node); long long getNodeReplicationOffset(clusterNode *node); sds aggregateClientOutputBuffer(client *c); void resetClusterStats(void); +unsigned int delKeysInSlot(unsigned int); #endif /* __CLUSTER_H */ diff --git a/src/server.c b/src/server.c index d332e6989c..13b226b2c0 100644 --- a/src/server.c +++ b/src/server.c @@ -6930,7 +6930,7 @@ int main(int argc, char **argv) { if (server.cluster_enabled) { serverAssert(verifyClusterConfigWithData() == C_OK); } - + delUnownedKeys(); for (j = 0; j < CONN_TYPE_MAX; j++) { connListener *listener = &server.listeners[j]; if (listener->ct == NULL) continue; diff --git a/src/server.h b/src/server.h index ccdece20dd..b9820e2890 100644 --- a/src/server.h +++ b/src/server.h @@ -3678,6 +3678,8 @@ unsigned long LFUDecrAndReturn(robj *o); int performEvictions(void); void startEvictionTimeProc(void); +void delUnownedKeys(void); + /* Keys hashing / comparison functions for dict.c hash tables. */ uint64_t dictSdsHash(const void *key); uint64_t dictSdsCaseHash(const void *key);