Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistence - Remove Unowned Keys #568

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ ConnectionType *connTypeOfCluster(void) {
return connectionTypeTcp();
}

/* delete unowned keys from database at server start up after loading persistence files. */
PingXie marked this conversation as resolved.
Show resolved Hide resolved
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
* -------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading