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:slave instance apply db not used lock #2409

Merged
merged 3 commits into from
Feb 26, 2024
Merged
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
5 changes: 4 additions & 1 deletion src/pika_repl_bgworker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "include/pika_rm.h"
#include "include/pika_server.h"
#include "pstd/include/pstd_defer.h"
#include "src/pstd/include/scope_record_lock.h"
#include "include/pika_conf.h"

extern PikaServer* g_pika_server;
Expand Down Expand Up @@ -215,6 +216,8 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) {
start_us = pstd::NowMicros();
}
// Add read lock for no suspend command
pstd::lock::MultiRecordLock record_lock(c_ptr->GetDB()->LockMgr());
record_lock.Lock(c_ptr->current_key());
if (!c_ptr->IsSuspend()) {
c_ptr->GetDB()->DbRWLockReader();
}
Expand All @@ -235,7 +238,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) {
if (!c_ptr->IsSuspend()) {
c_ptr->GetDB()->DbRWUnLock();
}

record_lock.Unlock(c_ptr->current_key());
if (g_pika_conf->slowlog_slower_than() >= 0) {
auto start_time = static_cast<int32_t>(start_us / 1000000);
auto duration = static_cast<int64_t>(pstd::NowMicros() - start_us);
Expand Down
Loading