From 1a595a13e750e56468d61577d1bc6217f3af9796 Mon Sep 17 00:00:00 2001 From: chejinge Date: Mon, 19 Feb 2024 19:35:23 +0800 Subject: [PATCH 1/2] fix slave instance apply db not used lock --- src/pika_repl_bgworker.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pika_repl_bgworker.cc b/src/pika_repl_bgworker.cc index 308e3e14fa..9b8613bcad 100644 --- a/src/pika_repl_bgworker.cc +++ b/src/pika_repl_bgworker.cc @@ -12,6 +12,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" extern PikaServer* g_pika_server; extern std::unique_ptr g_pika_rm; @@ -223,6 +224,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) { && PIKA_CACHE_NONE != g_pika_conf->cache_model() && c_ptr->GetDB()->cache()->CacheStatus() == PIKA_CACHE_STATUS_OK) { if (c_ptr->is_write()) { + pstd::lock::MultiScopeRecordLock record_lock(c_ptr->GetDB()->LockMgr(), c_ptr->current_key()); c_ptr->DoThroughDB(); if (c_ptr->IsNeedUpdateCache()) { c_ptr->DoUpdateCache(); From 478c6bcefa4bb852d7e1267d8f96bcc0040a27ac Mon Sep 17 00:00:00 2001 From: chejinge Date: Tue, 20 Feb 2024 15:36:08 +0800 Subject: [PATCH 2/2] fix --- src/pika_repl_bgworker.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pika_repl_bgworker.cc b/src/pika_repl_bgworker.cc index 9b8613bcad..5aba94ec2f 100644 --- a/src/pika_repl_bgworker.cc +++ b/src/pika_repl_bgworker.cc @@ -217,6 +217,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(); } @@ -224,7 +226,6 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) { && PIKA_CACHE_NONE != g_pika_conf->cache_model() && c_ptr->GetDB()->cache()->CacheStatus() == PIKA_CACHE_STATUS_OK) { if (c_ptr->is_write()) { - pstd::lock::MultiScopeRecordLock record_lock(c_ptr->GetDB()->LockMgr(), c_ptr->current_key()); c_ptr->DoThroughDB(); if (c_ptr->IsNeedUpdateCache()) { c_ptr->DoUpdateCache(); @@ -238,7 +239,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(start_us / 1000000); auto duration = static_cast(pstd::NowMicros() - start_us);