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

Method GetKeyspaceInfo

src/server/server.cc:1504–1534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1502}
1503
1504Server::InfoEntries Server::GetKeyspaceInfo(const std::string &ns) {
1505 InfoEntries entries;
1506 if (is_loading_) return entries;
1507
1508 KeyNumStats stats;
1509 GetLatestKeyNumStats(ns, &stats);
1510 auto last_dbsize_scan_timestamp = static_cast<time_t>(GetLastScanTime(ns));
1511
1512 entries.emplace_back("last_dbsize_scan_timestamp", last_dbsize_scan_timestamp);
1513 entries.emplace_back("db0", fmt::format("keys={},expires={},avg_ttl={},expired={}", stats.n_key, stats.n_expires,
1514 stats.avg_ttl, stats.n_expired));
1515 entries.emplace_back("sequence", storage->GetDB()->GetLatestSequenceNumber());
1516 entries.emplace_back("used_db_size", storage->GetTotalSize(ns));
1517 entries.emplace_back("max_db_size", config_->max_db_size * GiB);
1518 double used_percent = config_->max_db_size ? static_cast<double>(storage->GetTotalSize() * 100) /
1519 static_cast<double>(config_->max_db_size * GiB)
1520 : 0;
1521 entries.emplace_back("used_percent", fmt::format("{}%", used_percent));
1522
1523 struct statvfs stat;
1524 if (statvfs(config_->db_dir.c_str(), &stat) == 0) {
1525 auto disk_capacity = stat.f_blocks * stat.f_frsize;
1526 auto used_disk_size = (stat.f_blocks - stat.f_bavail) * stat.f_frsize;
1527 entries.emplace_back("disk_capacity", disk_capacity);
1528 entries.emplace_back("used_disk_size", used_disk_size);
1529 double used_disk_percent = static_cast<double>(used_disk_size * 100) / static_cast<double>(disk_capacity);
1530 entries.emplace_back("used_disk_percent", fmt::format("{}%", used_disk_percent));
1531 }
1532
1533 return entries;
1534}
1535
1536// WARNING: we must not access DB(i.e. RocksDB) when server is loading since
1537// DB is closed and the pointer is invalid. Server may crash if we access DB during loading.

Callers 1

GetInfoMethod · 0.80

Calls 3

statvfsClass · 0.85
GetDBMethod · 0.80
GetTotalSizeMethod · 0.80

Tested by

no test coverage detected