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

Method AsyncCompactDB

src/server/server.cc:1648–1673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1646}
1647
1648Status Server::AsyncCompactDB(const std::string &begin_key, const std::string &end_key) {
1649 if (is_loading_) {
1650 return {Status::NotOK, "loading in-progress"};
1651 }
1652
1653 std::lock_guard<std::mutex> lg(db_job_mu_);
1654 if (db_compacting_) {
1655 return {Status::NotOK, "compact in-progress"};
1656 }
1657
1658 db_compacting_ = true;
1659
1660 return task_runner_.TryPublish([begin_key, end_key, this] {
1661 std::unique_ptr<Slice> begin = nullptr, end = nullptr;
1662 if (!begin_key.empty()) begin = std::make_unique<Slice>(begin_key);
1663 if (!end_key.empty()) end = std::make_unique<Slice>(end_key);
1664
1665 auto s = storage->Compact(nullptr, begin.get(), end.get());
1666 if (!s.ok()) {
1667 ERROR("[task runner] Failed to do compaction: {}", s.ToString());
1668 }
1669
1670 std::lock_guard<std::mutex> lg(db_job_mu_);
1671 db_compacting_ = false;
1672 });
1673}
1674
1675Status Server::AsyncBgSaveDB() {
1676 std::lock_guard<std::mutex> lg(db_job_mu_);

Callers 1

ExecuteMethod · 0.80

Calls 4

TryPublishMethod · 0.80
CompactMethod · 0.80
getMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected