/src/rocksdb/db/trim_history_scheduler.h
Line | Count | Source |
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 | | |
6 | | #pragma once |
7 | | |
8 | | #include <stdint.h> |
9 | | |
10 | | #include <atomic> |
11 | | #include <mutex> |
12 | | |
13 | | #include "util/autovector.h" |
14 | | |
15 | | namespace ROCKSDB_NAMESPACE { |
16 | | |
17 | | class ColumnFamilyData; |
18 | | |
19 | | // Similar to FlushScheduler, TrimHistoryScheduler is a FIFO queue that keeps |
20 | | // track of column families whose flushed immutable memtables may need to be |
21 | | // removed (aka trimmed). The actual trimming may be slightly delayed. Due to |
22 | | // the use of the mutex and atomic variable, ScheduleWork, |
23 | | // TakeNextColumnFamily, and, Empty can be called concurrently. |
24 | | class TrimHistoryScheduler { |
25 | | public: |
26 | 44.8k | TrimHistoryScheduler() : is_empty_(true) {} |
27 | | |
28 | | // When a column family needs history trimming, add cfd to the FIFO queue |
29 | | void ScheduleWork(ColumnFamilyData* cfd); |
30 | | |
31 | | // Remove the column family from the queue, the caller is responsible for |
32 | | // calling `MemtableList::TrimHistory` |
33 | | ColumnFamilyData* TakeNextColumnFamily(); |
34 | | |
35 | | bool Empty(); |
36 | | |
37 | | void Clear(); |
38 | | |
39 | | // Not on critical path, use mutex to ensure thread safety |
40 | | private: |
41 | | std::atomic<bool> is_empty_; |
42 | | autovector<ColumnFamilyData*> cfds_; |
43 | | std::mutex checking_mutex_; |
44 | | }; |
45 | | |
46 | | } // namespace ROCKSDB_NAMESPACE |