| 1646 | } |
| 1647 | |
| 1648 | Status 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 | |
| 1675 | Status Server::AsyncBgSaveDB() { |
| 1676 | std::lock_guard<std::mutex> lg(db_job_mu_); |
no test coverage detected