Coverage Report

Created: 2024-07-27 06:53

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