From fa2b454113a352760c4b5c38e7c7679c438a7264 Mon Sep 17 00:00:00 2001 From: chejinge Date: Wed, 19 Jun 2024 19:42:49 +0800 Subject: [PATCH 1/2] fix:not correct used bgsave_info_ --- include/pika_server.h | 29 ++++++++++++++--------------- src/pika_server.cc | 8 ++++---- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/pika_server.h b/include/pika_server.h index 4811c54045..68e1c462b8 100644 --- a/include/pika_server.h +++ b/include/pika_server.h @@ -310,8 +310,7 @@ class PikaServer : public pstd::noncopyable { bool SlotsMigrateBatch(const std::string &ip, int64_t port, int64_t time_out, int64_t slots, int64_t keys_num, const std::shared_ptr& db); void GetSlotsMgrtSenderStatus(std::string *ip, int64_t* port, int64_t *slot, bool *migrating, int64_t *moved, int64_t *remained); bool SlotsMigrateAsyncCancel(); - std::shared_mutex bgsave_protector_; - BgSaveInfo bgsave_info_; + std::shared_mutex bgslots_protector_; /* * BGSlotsReload used @@ -337,28 +336,28 @@ class PikaServer : public pstd::noncopyable { BGSlotsReload bgslots_reload_; BGSlotsReload bgslots_reload() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); return bgslots_reload_; } bool GetSlotsreloading() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); return bgslots_reload_.reloading; } void SetSlotsreloading(bool reloading) { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_reload_.reloading = reloading; } void SetSlotsreloadingCursor(int64_t cursor) { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_reload_.cursor = cursor; } int64_t GetSlotsreloadingCursor() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); return bgslots_reload_.cursor; } void SetSlotsreloadingEndTime() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_reload_.end_time = time(nullptr); } void Bgslotsreload(const std::shared_ptr& db); @@ -399,33 +398,33 @@ class PikaServer : public pstd::noncopyable { net::BGThread bgslots_cleanup_thread_; BGSlotsCleanup bgslots_cleanup() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); return bgslots_cleanup_; } bool GetSlotscleaningup() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); return bgslots_cleanup_.cleaningup; } void SetSlotscleaningup(bool cleaningup) { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_cleanup_.cleaningup = cleaningup; } void SetSlotscleaningupCursor(int64_t cursor) { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_cleanup_.cursor = cursor; } void SetCleanupSlots(std::vector cleanup_slots) { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_cleanup_.cleanup_slots.swap(cleanup_slots); } std::vector GetCleanupSlots() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); return bgslots_cleanup_.cleanup_slots; } void Bgslotscleanup(std::vector cleanup_slots, const std::shared_ptr& db); void StopBgslotscleanup() { - std::lock_guard ml(bgsave_protector_); + std::lock_guard ml(bgslots_protector_); bgslots_cleanup_.cleaningup = false; std::vector cleanup_slots; bgslots_cleanup_.cleanup_slots.swap(cleanup_slots); diff --git a/src/pika_server.cc b/src/pika_server.cc index 5c3aae16df..a3c254251a 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -1433,9 +1433,9 @@ bool PikaServer::SlotsMigrateAsyncCancel() { void PikaServer::Bgslotsreload(const std::shared_ptr& db) { // Only one thread can go through + std::lock_guard ml(bgslots_protector_); { - std::lock_guard ml(bgsave_protector_); - if (bgslots_reload_.reloading || bgsave_info_.bgsaving) { + if (bgslots_reload_.reloading || db->IsBgSaving()) { return; } bgslots_reload_.reloading = true; @@ -1498,8 +1498,8 @@ void DoBgslotsreload(void* arg) { void PikaServer::Bgslotscleanup(std::vector cleanupSlots, const std::shared_ptr& db) { // Only one thread can go through { - std::lock_guard ml(bgsave_protector_); - if (bgslots_cleanup_.cleaningup || bgslots_reload_.reloading || bgsave_info_.bgsaving) { + std::lock_guard ml(bgslots_protector_); + if (bgslots_cleanup_.cleaningup || bgslots_reload_.reloading || db->IsBgSaving()) { return; } bgslots_cleanup_.cleaningup = true; From 6577b75f5bb4286d6411edcbec982f24b26c3eb7 Mon Sep 17 00:00:00 2001 From: chejinge Date: Thu, 20 Jun 2024 14:42:42 +0800 Subject: [PATCH 2/2] fix:not correct used bgsave_info_ --- src/pika_server.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pika_server.cc b/src/pika_server.cc index a3c254251a..be12b76d51 100644 --- a/src/pika_server.cc +++ b/src/pika_server.cc @@ -1433,8 +1433,8 @@ bool PikaServer::SlotsMigrateAsyncCancel() { void PikaServer::Bgslotsreload(const std::shared_ptr& db) { // Only one thread can go through - std::lock_guard ml(bgslots_protector_); { + std::lock_guard ml(bgslots_protector_); if (bgslots_reload_.reloading || db->IsBgSaving()) { return; }