Skip to content

Commit 5bea5e6

Browse files
authored
feat:check repl state to response immediately if full sync not finished (OpenAtomFoundation#2197)
* check repl state to response immediately if full sync not finished Signed-off-by: lizhen <lizhen@outlook.jp>
1 parent 5cba081 commit 5bea5e6

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

include/pika_command.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,11 @@ struct UnblockTaskArgs {
474474
: key(std::move(key_)), db(db_), dispatchThread(dispatchThread_) {}
475475
};
476476

477+
class PikaClientConn;
478+
477479
class Cmd : public std::enable_shared_from_this<Cmd> {
478480
public:
481+
friend class PikaClientConn;
479482
enum CmdStage { kNone, kBinlogStage, kExecuteStage };
480483
struct HintKeys {
481484
HintKeys() = default;

src/cache/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ project (cache)
66
aux_source_directory(./src DIR_SRCS)
77
include_directories(include)
88
add_library(cache STATIC ${DIR_SRCS})
9-
add_dependencies(cache net protobuf glog gflags ${LIBUNWIND_NAME})
9+
add_dependencies(cache net protobuf glog gflags rediscache ${LIBUNWIND_NAME})
1010

1111
target_link_libraries(cache
1212
PUBLIC ${GTEST_LIBRARY}

src/pika_client_conn.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "include/pika_cmd_table_manager.h"
1717
#include "include/pika_command.h"
1818
#include "include/pika_conf.h"
19+
#include "include/pika_define.h"
1920
#include "include/pika_rm.h"
2021
#include "include/pika_server.h"
2122
#include "net/src/dispatch_thread.h"
@@ -164,6 +165,23 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st
164165
c_ptr->res().SetRes(CmdRes::kErrOther, "Server in read-only");
165166
return c_ptr;
166167
}
168+
} else if (c_ptr->is_read() && c_ptr->flag_ == 0) {
169+
const auto& server_guard = std::lock_guard(g_pika_server->GetDBLock());
170+
int role = 0;
171+
auto status = g_pika_rm->CheckDBRole(current_db_, &role);
172+
if (!status.ok()) {
173+
c_ptr->res().SetRes(CmdRes::kErrOther, "Internal ERROR");
174+
return c_ptr;
175+
} else if ((role & PIKA_ROLE_SLAVE) == PIKA_ROLE_SLAVE) {
176+
const auto& slave_db = g_pika_rm->GetSyncSlaveDBByName(DBInfo(current_db_));
177+
if (!slave_db) {
178+
c_ptr->res().SetRes(CmdRes::kErrOther, "Internal ERROR");
179+
return c_ptr;
180+
} else if (slave_db->State() != ReplState::kConnected) {
181+
c_ptr->res().SetRes(CmdRes::kErrOther, "Full sync not completed");
182+
return c_ptr;
183+
}
184+
}
167185
}
168186

169187
// Process Command

0 commit comments

Comments
 (0)