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

feat:check repl state to response immediately if full sync not finished #2197

Merged
merged 10 commits into from
Jan 31, 2024
3 changes: 3 additions & 0 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,11 @@ struct UnblockTaskArgs {
: key(std::move(key_)), db(db_), dispatchThread(dispatchThread_) {}
};

class PikaClientConn;

class Cmd : public std::enable_shared_from_this<Cmd> {
public:
friend class PikaClientConn;
enum CmdStage { kNone, kBinlogStage, kExecuteStage };
struct HintKeys {
HintKeys() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project (cache)
aux_source_directory(./src DIR_SRCS)
include_directories(include)
add_library(cache STATIC ${DIR_SRCS})
add_dependencies(cache net protobuf glog gflags ${LIBUNWIND_NAME})
add_dependencies(cache net protobuf glog gflags rediscache ${LIBUNWIND_NAME})

target_link_libraries(cache
PUBLIC ${GTEST_LIBRARY}
Expand Down
18 changes: 18 additions & 0 deletions src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "include/pika_cmd_table_manager.h"
#include "include/pika_command.h"
#include "include/pika_conf.h"
#include "include/pika_define.h"
#include "include/pika_rm.h"
#include "include/pika_server.h"
#include "net/src/dispatch_thread.h"
Expand Down Expand Up @@ -164,6 +165,23 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st
c_ptr->res().SetRes(CmdRes::kErrOther, "Server in read-only");
return c_ptr;
}
} else if (c_ptr->is_read() && c_ptr->flag_ == 0) {
const auto& server_guard = std::lock_guard(g_pika_server->GetDBLock());
int role = 0;
auto status = g_pika_rm->CheckDBRole(current_db_, &role);
if (!status.ok()) {
c_ptr->res().SetRes(CmdRes::kErrOther, "Internal ERROR");
return c_ptr;
} else if ((role & PIKA_ROLE_SLAVE) == PIKA_ROLE_SLAVE) {
tedli marked this conversation as resolved.
Show resolved Hide resolved
const auto& slave_db = g_pika_rm->GetSyncSlaveDBByName(DBInfo(current_db_));
if (!slave_db) {
c_ptr->res().SetRes(CmdRes::kErrOther, "Internal ERROR");
return c_ptr;
} else if (slave_db->State() != ReplState::kConnected) {
c_ptr->res().SetRes(CmdRes::kErrOther, "Full sync not completed");
return c_ptr;
}
}
}

// Process Command
Expand Down
Loading