]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/logs_with_prep_tracker.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / db / logs_with_prep_tracker.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 <cassert>
10 #include <cstdlib>
11 #include <mutex>
12 #include <unordered_map>
13 #include <vector>
14
15 namespace rocksdb {
16
17 // This class is used to track the log files with outstanding prepare entries.
18 class LogsWithPrepTracker {
19 public:
20 // Called when a transaction prepared in `log` has been committed or aborted.
21 void MarkLogAsHavingPrepSectionFlushed(uint64_t log);
22 // Called when a transaction is prepared in `log`.
23 void MarkLogAsContainingPrepSection(uint64_t log);
24 // Return the earliest log file with outstanding prepare entries.
25 uint64_t FindMinLogContainingOutstandingPrep();
26 size_t TEST_PreparedSectionCompletedSize() {
27 return prepared_section_completed_.size();
28 }
29 size_t TEST_LogsWithPrepSize() { return logs_with_prep_.size(); }
30
31 private:
32 // REQUIRES: logs_with_prep_mutex_ held
33 //
34 // sorted list of log numbers still containing prepared data.
35 // this is used by FindObsoleteFiles to determine which
36 // flushed logs we must keep around because they still
37 // contain prepared data which has not been committed or rolled back
38 struct LogCnt {
39 uint64_t log; // the log number
40 uint64_t cnt; // number of prepared sections in the log
41 };
42 std::vector<LogCnt> logs_with_prep_;
43 std::mutex logs_with_prep_mutex_;
44
45 // REQUIRES: prepared_section_completed_mutex_ held
46 //
47 // to be used in conjunction with logs_with_prep_.
48 // once a transaction with data in log L is committed or rolled back
49 // rather than updating logs_with_prep_ directly we keep track of that
50 // in prepared_section_completed_ which maps LOG -> instance_count. This helps
51 // avoiding contention between a commit thread and the prepare threads.
52 //
53 // when trying to determine the minimum log still active we first
54 // consult logs_with_prep_. while that root value maps to
55 // an equal value in prepared_section_completed_ we erase the log from
56 // both logs_with_prep_ and prepared_section_completed_.
57 std::unordered_map<uint64_t, uint64_t> prepared_section_completed_;
58 std::mutex prepared_section_completed_mutex_;
59
60 };
61 } // namespace rocksdb