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

Method AsyncScanDBSize

src/server/server.cc:1702–1731  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1700}
1701
1702Status Server::AsyncScanDBSize(const std::string &ns) {
1703 std::lock_guard<std::mutex> lg(db_job_mu_);
1704
1705 if (auto iter = db_scan_infos_.find(ns); iter == db_scan_infos_.end()) {
1706 db_scan_infos_[ns] = DBScanInfo{};
1707 }
1708
1709 if (db_scan_infos_[ns].is_scanning) {
1710 return {Status::NotOK, "scanning the db now"};
1711 }
1712
1713 db_scan_infos_[ns].is_scanning = true;
1714
1715 return task_runner_.TryPublish([ns, this] {
1716 redis::Database db(storage, ns);
1717
1718 KeyNumStats stats;
1719 engine::Context ctx(storage);
1720 auto s = db.GetKeyNumStats(ctx, "", &stats);
1721 if (!s.ok()) {
1722 ERROR("failed to retrieve key num stats: {}", s.ToString());
1723 }
1724
1725 std::lock_guard<std::mutex> lg(db_job_mu_);
1726
1727 db_scan_infos_[ns].key_num_stats = stats;
1728 db_scan_infos_[ns].last_scan_time_secs = util::GetTimeStamp();
1729 db_scan_infos_[ns].is_scanning = false;
1730 });
1731}
1732
1733void Server::GetLatestKeyNumStats(const std::string &ns, KeyNumStats *stats) {
1734 std::lock_guard<std::mutex> lg(db_job_mu_);

Callers 1

ExecuteMethod · 0.80

Calls 5

GetTimeStampFunction · 0.85
endMethod · 0.80
TryPublishMethod · 0.80
GetKeyNumStatsMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected