summaryrefslogtreecommitdiffstats
path: root/src/rocksdb/db/trim_history_scheduler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rocksdb/db/trim_history_scheduler.cc')
-rw-r--r--src/rocksdb/db/trim_history_scheduler.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/rocksdb/db/trim_history_scheduler.cc b/src/rocksdb/db/trim_history_scheduler.cc
new file mode 100644
index 000000000..d7ca0899f
--- /dev/null
+++ b/src/rocksdb/db/trim_history_scheduler.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
+// This source code is licensed under both the GPLv2 (found in the
+// COPYING file in the root directory) and Apache 2.0 License
+// (found in the LICENSE.Apache file in the root directory).
+
+#include "db/trim_history_scheduler.h"
+
+#include <cassert>
+
+#include "db/column_family.h"
+
+namespace ROCKSDB_NAMESPACE {
+
+void TrimHistoryScheduler::ScheduleWork(ColumnFamilyData* cfd) {
+ std::lock_guard<std::mutex> lock(checking_mutex_);
+ cfd->Ref();
+ cfds_.push_back(cfd);
+ is_empty_.store(false, std::memory_order_relaxed);
+}
+
+ColumnFamilyData* TrimHistoryScheduler::TakeNextColumnFamily() {
+ std::lock_guard<std::mutex> lock(checking_mutex_);
+ while (true) {
+ if (cfds_.empty()) {
+ return nullptr;
+ }
+ ColumnFamilyData* cfd = cfds_.back();
+ cfds_.pop_back();
+ if (cfds_.empty()) {
+ is_empty_.store(true, std::memory_order_relaxed);
+ }
+
+ if (!cfd->IsDropped()) {
+ // success
+ return cfd;
+ }
+ cfd->UnrefAndTryDelete();
+ }
+}
+
+bool TrimHistoryScheduler::Empty() {
+ bool is_empty = is_empty_.load(std::memory_order_relaxed);
+ return is_empty;
+}
+
+void TrimHistoryScheduler::Clear() {
+ ColumnFamilyData* cfd;
+ while ((cfd = TakeNextColumnFamily()) != nullptr) {
+ cfd->UnrefAndTryDelete();
+ }
+ assert(Empty());
+}
+
+} // namespace ROCKSDB_NAMESPACE