trim_history_scheduler.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #pragma once
  6. #include <stdint.h>
  7. #include <atomic>
  8. #include <mutex>
  9. #include "util/autovector.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. class ColumnFamilyData;
  12. // Similar to FlushScheduler, TrimHistoryScheduler is a FIFO queue that keeps
  13. // track of column families whose flushed immutable memtables may need to be
  14. // removed (aka trimmed). The actual trimming may be slightly delayed. Due to
  15. // the use of the mutex and atomic variable, ScheduleWork,
  16. // TakeNextColumnFamily, and, Empty can be called concurrently.
  17. class TrimHistoryScheduler {
  18. public:
  19. TrimHistoryScheduler() : is_empty_(true) {}
  20. // When a column family needs history trimming, add cfd to the FIFO queue
  21. void ScheduleWork(ColumnFamilyData* cfd);
  22. // Remove the column family from the queue, the caller is responsible for
  23. // calling `MemtableList::TrimHistory`
  24. ColumnFamilyData* TakeNextColumnFamily();
  25. bool Empty();
  26. void Clear();
  27. // Not on critical path, use mutex to ensure thread safety
  28. private:
  29. std::atomic<bool> is_empty_;
  30. autovector<ColumnFamilyData*> cfds_;
  31. std::mutex checking_mutex_;
  32. };
  33. } // namespace ROCKSDB_NAMESPACE