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

fix:not correct used bgsave_info_ #2745

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -1434,8 +1434,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 @@ -1498,8 +1498,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
Loading