Skip to content

Commit

Permalink
fix:slave instance apply db not used lock (OpenAtomFoundation#2409)
Browse files Browse the repository at this point in the history
* fix slave instance apply db not used lock

---------

Co-authored-by: chejinge <[email protected]>
  • Loading branch information
chejinge and brother-jin authored Feb 26, 2024
1 parent 6b0830f commit 5888cf5
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit 5888cf5

Please sign in to comment.