Skip to content

Commit

Permalink
fix:not correct used bgsave_info_ (OpenAtomFoundation#2745)
Browse files Browse the repository at this point in the history
* fix:not correct used bgsave_info_

* fix:not correct used bgsave_info_

---------

Co-authored-by: chejinge <[email protected]>
  • Loading branch information
chejinge and brother-jin authored Jun 20, 2024
1 parent 9f52765 commit 779d3a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
29 changes: 14 additions & 15 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>& 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
Expand All @@ -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>& db);
Expand Down Expand Up @@ -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<int> cleanup_slots) {
std::lock_guard ml(bgsave_protector_);
std::lock_guard ml(bgslots_protector_);
bgslots_cleanup_.cleanup_slots.swap(cleanup_slots);
}
std::vector<int> GetCleanupSlots() {
std::lock_guard ml(bgsave_protector_);
std::lock_guard ml(bgslots_protector_);
return bgslots_cleanup_.cleanup_slots;
}

void Bgslotscleanup(std::vector<int> cleanup_slots, const std::shared_ptr<DB>& db);
void StopBgslotscleanup() {
std::lock_guard ml(bgsave_protector_);
std::lock_guard ml(bgslots_protector_);
bgslots_cleanup_.cleaningup = false;
std::vector<int> cleanup_slots;
bgslots_cleanup_.cleanup_slots.swap(cleanup_slots);
Expand Down
8 changes: 4 additions & 4 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,8 @@ bool PikaServer::SlotsMigrateAsyncCancel() {
void PikaServer::Bgslotsreload(const std::shared_ptr<DB>& db) {
// Only one thread can go through
{
std::lock_guard ml(bgsave_protector_);
if (bgslots_reload_.reloading || bgsave_info_.bgsaving) {
std::lock_guard ml(bgslots_protector_);
if (bgslots_reload_.reloading || db->IsBgSaving()) {
return;
}
bgslots_reload_.reloading = true;
Expand Down Expand Up @@ -1514,8 +1514,8 @@ void DoBgslotsreload(void* arg) {
void PikaServer::Bgslotscleanup(std::vector<int> cleanupSlots, const std::shared_ptr<DB>& 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;
Expand Down

0 comments on commit 779d3a2

Please sign in to comment.