]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/flush_scheduler.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / db / flush_scheduler.h
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 #include <atomic>
10 #include <mutex>
11 #include <set>
12 #include "util/autovector.h"
13
14 namespace ROCKSDB_NAMESPACE {
15
16 class ColumnFamilyData;
17
18 // FlushScheduler keeps track of all column families whose memtable may
19 // be full and require flushing. Unless otherwise noted, all methods on
20 // FlushScheduler should be called only with the DB mutex held or from
21 // a single-threaded recovery context.
22 class FlushScheduler {
23 public:
24 FlushScheduler() : head_(nullptr) {}
25
26 // May be called from multiple threads at once, but not concurrent with
27 // any other method calls on this instance
28 void ScheduleWork(ColumnFamilyData* cfd);
29
30 // Removes and returns Ref()-ed column family. Client needs to Unref().
31 // Filters column families that have been dropped.
32 ColumnFamilyData* TakeNextColumnFamily();
33
34 // This can be called concurrently with ScheduleWork but it would miss all
35 // the scheduled flushes after the last synchronization. This would result
36 // into less precise enforcement of memtable sizes but should not matter much.
37 bool Empty();
38
39 void Clear();
40
41 private:
42 struct Node {
43 ColumnFamilyData* column_family;
44 Node* next;
45 };
46
47 std::atomic<Node*> head_;
48 #ifndef NDEBUG
49 std::mutex checking_mutex_;
50 std::set<ColumnFamilyData*> checking_set_;
51 #endif // NDEBUG
52 };
53
54 } // namespace ROCKSDB_NAMESPACE