From c171b68e216636f52c1fa1f70e893c8c14da2976 Mon Sep 17 00:00:00 2001 From: Liang Tang Date: Thu, 30 May 2024 00:11:12 +0000 Subject: [PATCH] address comments Signed-off-by: Liang Tang --- src/cluster.c | 28 ++++++++++++++++++++++++++++ src/cluster_legacy.c | 27 --------------------------- src/cluster_legacy.h | 2 +- src/server.c | 11 ++--------- src/server.h | 8 +------- 5 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 71d1cc9124..0c0c869543 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -35,6 +35,7 @@ #include "server.h" #include "cluster.h" +#include "cluster_legacy.h" #include @@ -107,6 +108,33 @@ ConnectionType *connTypeOfCluster(void) { return connectionTypeTcp(); } +void delUnOwnedKeys(void) { + if (!server.cluster_enabled) { + return; + } + unsigned int deleted_keys = 0; + unsigned int unowned_slots = 0; + clusterNode *master; + if (clusterNodeIsMaster(server.cluster->myself)) { + master = server.cluster->myself; + } else { + master = server.cluster->myself->slaveof; + } + for (int i = 0; i < CLUSTER_SLOTS; i++) { + if (server.cluster->slots[i] != master) { + unsigned int deleted = delKeysInSlot(i); + deleted_keys += deleted; + if (deleted > 0) { + unowned_slots++; + serverLog(LL_NOTICE, "Deleted %u keys from unowned slot: %d after loading RDB", deleted, i); + } + } + } + serverLog(LL_NOTICE, "Deleted totoal: %d unowned keys from total: %d unowned slots after loading RDB", + deleted_keys, unowned_slots); + return; +} + /* ----------------------------------------------------------------------------- * DUMP, RESTORE and MIGRATE commands * -------------------------------------------------------------------------- */ diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 920bcdf782..63364d3596 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -6552,30 +6552,3 @@ void clusterReplicateOpenSlots(void) { zfree(argv); } - -del_stat delUnOwnedKeys(void) { - del_stat result = {0, 0}; - if (!server.cluster_enabled) { - return result; - } - - clusterNode *master; - if (clusterNodeIsMaster(server.cluster->myself)) { - master = myself; - } else { - master = server.cluster->myself->slaveof; - } - for (int i = 0; i < CLUSTER_SLOTS; i++) { - if (server.cluster->slots[i] != master) { - unsigned int deleted = delKeysInSlot(i); - result.deleted_keys += deleted; - if (deleted > 0) { - result.unowned_slots++; - serverLog(LL_NOTICE, "Deleted %u keys from unowned slot: %d after loading RDB", deleted, i); - } - } - } - serverLog(LL_NOTICE, "Deleted totoal: %d unowned keys from total: %d unowned slots after loading RDB", - result.deleted_keys, result.unowned_slots); - return result; -} diff --git a/src/cluster_legacy.h b/src/cluster_legacy.h index cc02f30a8b..6951eb0532 100644 --- a/src/cluster_legacy.h +++ b/src/cluster_legacy.h @@ -364,5 +364,5 @@ struct clusterState { unsigned char owner_not_claiming_slot[CLUSTER_SLOTS / 8]; }; - +unsigned int delKeysInSlot(unsigned int hashslot); #endif // CLUSTER_LEGACY_H diff --git a/src/server.c b/src/server.c index 1d64b65eda..bdfb27ec16 100644 --- a/src/server.c +++ b/src/server.c @@ -2656,8 +2656,6 @@ void initServer(void) { server.rdb_save_time_start = -1; server.rdb_last_load_keys_expired = 0; server.rdb_last_load_keys_loaded = 0; - server.stat_persistence_startup_load_keys_deleted = 0; - server.stat_persistence_startup_load_unowned_slots = 0; server.dirty = 0; resetServerStats(); /* A few stats we don't want to reset: server startup time, and peak mem. */ @@ -5584,9 +5582,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) { aof_bio_fsync_status == C_OK) ? "ok" : "err", "aof_last_cow_size:%zu\r\n", server.stat_aof_cow_bytes, "module_fork_in_progress:%d\r\n", server.child_type == CHILD_TYPE_MODULE, - "module_fork_last_cow_size:%zu\r\n", server.stat_module_cow_bytes, - "total_startup_load_deleted_keys:%lld\r\n", server.stat_persistence_startup_load_keys_deleted, - "total_startup_load_unowned_slots:%lld\r\n", server.stat_persistence_startup_load_unowned_slots)); + "module_fork_last_cow_size:%zu\r\n", server.stat_module_cow_bytes)); /* clang-format on */ if (server.aof_enabled) { @@ -6945,15 +6941,12 @@ int main(int argc, char **argv) { serverLog(LL_NOTICE, "Server initialized"); aofLoadManifestFromDisk(); loadDataFromDisk(); - del_stat stat = delUnOwnedKeys(); - server.stat_persistence_startup_load_keys_deleted = stat.deleted_keys; - server.stat_persistence_startup_load_unowned_slots = stat.unowned_slots; aofOpenIfNeededOnServerStart(); aofDelHistoryFiles(); 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 08a78b0782..a179328bd9 100644 --- a/src/server.h +++ b/src/server.h @@ -1814,8 +1814,6 @@ struct valkeyServer { invocation of the event loop. */ unsigned int max_new_conns_per_cycle; /* The maximum number of tcp connections that will be accepted during each invocation of the event loop. */ - long long stat_persistence_startup_load_keys_deleted; - long long stat_persistence_startup_load_unowned_slots; /* AOF persistence */ int aof_enabled; /* AOF configuration */ int aof_state; /* AOF_(ON|OFF|WAIT_REWRITE) */ @@ -3537,12 +3535,8 @@ unsigned long LFUDecrAndReturn(robj *o); int performEvictions(void); void startEvictionTimeProc(void); -typedef struct { - unsigned int unowned_slots; - unsigned int deleted_keys; -} del_stat; /* delete unowned keys from database at server start up after loading persistence files. */ -del_stat delUnOwnedKeys(void); +void delUnOwnedKeys(void); /* Keys hashing / comparison functions for dict.c hash tables. */ uint64_t dictSdsHash(const void *key);