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_).
| 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_). |
| 1540 | std::string Server::GetInfo(const std::string &ns, const std::vector<std::string> §ions) { |
| 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 | |
| 1573 | std::string Server::GetRocksDBStatsJson() const { |
| 1574 | jsoncons::json stats_json; |
no test coverage detected