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).
12 #include <unordered_map>
17 // This class is used to track the log files with outstanding prepare entries.
18 class LogsWithPrepTracker
{
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();
29 size_t TEST_LogsWithPrepSize() { return logs_with_prep_
.size(); }
32 // REQUIRES: logs_with_prep_mutex_ held
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
39 uint64_t log
; // the log number
40 uint64_t cnt
; // number of prepared sections in the log
42 std::vector
<LogCnt
> logs_with_prep_
;
43 std::mutex logs_with_prep_mutex_
;
45 // REQUIRES: prepared_section_completed_mutex_ held
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.
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_
;
61 } // namespace rocksdb