Skip to content

Commit

Permalink
Support executing INFO command during restoring database (#375)
Browse files Browse the repository at this point in the history
Currently, we can't execute INFO command during restoring database on kvrocks,
but redis can. Kvrocks returns error messages directly, it is not easy for some
SDK/proxy/tools to check loading or other status, so this commit implements.
  • Loading branch information
ShooterIT committed Jan 28, 2022
1 parent 425adeb commit 726d98d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4434,7 +4434,7 @@ CommandAttributes redisCommandTable[] = {
ADD_CMD("auth", 2, "read-only ok-loading", 0, 0, 0, CommandAuth),
ADD_CMD("ping", 1, "read-only", 0, 0, 0, CommandPing),
ADD_CMD("select", 2, "read-only", 0, 0, 0, CommandSelect),
ADD_CMD("info", -1, "read-only", 0, 0, 0, CommandInfo),
ADD_CMD("info", -1, "read-only ok-loading", 0, 0, 0, CommandInfo),
ADD_CMD("role", 1, "read-only", 0, 0, 0, CommandRole),
ADD_CMD("config", -2, "read-only", 0, 0, 0, CommandConfig),
ADD_CMD("namespace", -3, "read-only", 0, 0, 0, CommandNamespace),
Expand Down
17 changes: 14 additions & 3 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,11 @@ void Server::GetCommandsStatsInfo(std::string *info) {
*info = string_stream.str();
}

// WARNING: we must not access DB(i.e.RocksDB) when server is loading since
// DB is closed and the pointer is invalid. Server may crash if we access DB
// during loading.
// If you add new fields which access DB into INFO command output, make sure
// this section cant't be shown when loading(i.e. !is_loading_).
void Server::GetInfo(const std::string &ns, const std::string &section, std::string *info) {
info->clear();
std::ostringstream string_stream;
Expand Down Expand Up @@ -868,7 +873,9 @@ void Server::GetInfo(const std::string &ns, const std::string &section, std::str
GetStatsInfo(&stats_info);
string_stream << stats_info;
}
if (all || section == "replication") {

// In replication section, we access DB, so we can't do that when loading
if (!is_loading_ && (all || section == "replication")) {
std::string replication_info;
GetReplicationInfo(&replication_info);
string_stream << replication_info;
Expand All @@ -889,7 +896,9 @@ void Server::GetInfo(const std::string &ns, const std::string &section, std::str
GetCommandsStatsInfo(&commands_stats_info);
string_stream << commands_stats_info;
}
if (all || section == "keyspace") {

// In keyspace section, we access DB, so we can't do that when loading
if (!is_loading_ && (all || section == "keyspace")) {
KeyNumStats stats;
GetLastestKeyNumStats(ns, &stats);
time_t last_scan_time = GetLastScanTime(ns);
Expand All @@ -913,7 +922,9 @@ void Server::GetInfo(const std::string &ns, const std::string &section, std::str
string_stream << "used_disk_percent: " << used_disk_percent << "%\r\n";
}
}
if (all || section == "rocksdb") {

// In rocksdb section, we access DB, so we can't do that when loading
if (!is_loading_ && (all || section == "rocksdb")) {
std::string rocksdb_info;
GetRocksDBInfo(&rocksdb_info);
string_stream << rocksdb_info;
Expand Down

0 comments on commit 726d98d

Please sign in to comment.