MCPcopy Create free account
hub / github.com/apache/kvrocks / GetInfo

Method GetInfo

src/server/server.cc:1540–1571  ·  view source on GitHub ↗

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 can't be shown when loading(i.e. !is_loading_).

Source from the content-addressed store, hash-verified

1538// If you add new fields which access DB into INFO command output, make sure
1539// this section can't be shown when loading(i.e. !is_loading_).
1540std::string Server::GetInfo(const std::string &ns, const std::vector<std::string> &sections) {
1541 std::vector<std::pair<std::string, std::function<InfoEntries(Server *)>>> info_funcs = {
1542 {"Server", &Server::GetServerInfo}, {"Clients", &Server::GetClientsInfo},
1543 {"Memory", &Server::GetMemoryInfo}, {"Persistence", &Server::GetPersistenceInfo},
1544 {"Stats", &Server::GetStatsInfo}, {"Replication", &Server::GetReplicationInfo},
1545 {"CPU", &Server::GetCpuInfo}, {"CommandStats", &Server::GetCommandsStatsInfo},
1546 {"Cluster", &Server::GetClusterInfo}, {"Keyspace", [&ns](Server *srv) { return srv->GetKeyspaceInfo(ns); }},
1547 {"RocksDB", &Server::GetRocksDBInfo},
1548 };
1549
1550 std::string info_str;
1551
1552 bool all = sections.empty() || util::FindICase(sections.begin(), sections.end(), "all") != sections.end();
1553
1554 bool first = true;
1555 for (const auto &[sec, fn] : info_funcs) {
1556 if (all || util::FindICase(sections.begin(), sections.end(), sec) != sections.end()) {
1557 if (first)
1558 first = false;
1559 else
1560 info_str.append("\r\n");
1561
1562 info_str.append("# " + sec + "\r\n");
1563
1564 for (const auto &entry : fn(this)) {
1565 info_str.append(fmt::format("{}:{}\r\n", entry.name, entry.val));
1566 }
1567 }
1568 }
1569
1570 return info_str;
1571}
1572
1573std::string Server::GetRocksDBStatsJson() const {
1574 jsoncons::json stats_json;

Callers 1

ExecuteMethod · 0.80

Calls 4

FindICaseFunction · 0.85
GetKeyspaceInfoMethod · 0.80
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected