]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/job_context.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / db / job_context.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5 //
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10 #pragma once
11
12 #include <string>
13 #include <vector>
14
15 #include "db/log_writer.h"
16
17 namespace rocksdb {
18
19 class MemTable;
20
21 struct JobContext {
22 inline bool HaveSomethingToDelete() const {
23 return full_scan_candidate_files.size() || sst_delete_files.size() ||
24 log_delete_files.size() || manifest_delete_files.size() ||
25 new_superversion != nullptr || superversions_to_free.size() > 0 ||
26 memtables_to_free.size() > 0 || logs_to_free.size() > 0;
27 }
28
29 // Structure to store information for candidate files to delete.
30 struct CandidateFileInfo {
31 std::string file_name;
32 uint32_t path_id;
33 CandidateFileInfo(std::string name, uint32_t path)
34 : file_name(std::move(name)), path_id(path) {}
35 bool operator==(const CandidateFileInfo& other) const {
36 return file_name == other.file_name && path_id == other.path_id;
37 }
38 };
39
40 // Unique job id
41 int job_id;
42
43 // a list of all files that we'll consider deleting
44 // (every once in a while this is filled up with all files
45 // in the DB directory)
46 // (filled only if we're doing full scan)
47 std::vector<CandidateFileInfo> full_scan_candidate_files;
48
49 // the list of all live sst files that cannot be deleted
50 std::vector<FileDescriptor> sst_live;
51
52 // a list of sst files that we need to delete
53 std::vector<FileMetaData*> sst_delete_files;
54
55 // a list of log files that we need to delete
56 std::vector<uint64_t> log_delete_files;
57
58 // a list of log files that we need to preserve during full purge since they
59 // will be reused later
60 std::vector<uint64_t> log_recycle_files;
61
62 // a list of manifest files that we need to delete
63 std::vector<std::string> manifest_delete_files;
64
65 // a list of memtables to be free
66 autovector<MemTable*> memtables_to_free;
67
68 autovector<SuperVersion*> superversions_to_free;
69
70 autovector<log::Writer*> logs_to_free;
71
72 SuperVersion* new_superversion; // if nullptr no new superversion
73
74 // the current manifest_file_number, log_number and prev_log_number
75 // that corresponds to the set of files in 'live'.
76 uint64_t manifest_file_number;
77 uint64_t pending_manifest_file_number;
78 uint64_t log_number;
79 uint64_t prev_log_number;
80
81 uint64_t min_pending_output = 0;
82 uint64_t prev_total_log_size = 0;
83 size_t num_alive_log_files = 0;
84 uint64_t size_log_to_delete = 0;
85
86 explicit JobContext(int _job_id, bool create_superversion = false) {
87 job_id = _job_id;
88 manifest_file_number = 0;
89 pending_manifest_file_number = 0;
90 log_number = 0;
91 prev_log_number = 0;
92 new_superversion = create_superversion ? new SuperVersion() : nullptr;
93 }
94
95 // For non-empty JobContext Clean() has to be called at least once before
96 // before destruction (see asserts in ~JobContext()). Should be called with
97 // unlocked DB mutex. Destructor doesn't call Clean() to avoid accidentally
98 // doing potentially slow Clean() with locked DB mutex.
99 void Clean() {
100 // free pending memtables
101 for (auto m : memtables_to_free) {
102 delete m;
103 }
104 // free superversions
105 for (auto s : superversions_to_free) {
106 delete s;
107 }
108 for (auto l : logs_to_free) {
109 delete l;
110 }
111 // if new_superversion was not used, it will be non-nullptr and needs
112 // to be freed here
113 delete new_superversion;
114
115 memtables_to_free.clear();
116 superversions_to_free.clear();
117 logs_to_free.clear();
118 new_superversion = nullptr;
119 }
120
121 ~JobContext() {
122 assert(memtables_to_free.size() == 0);
123 assert(superversions_to_free.size() == 0);
124 assert(new_superversion == nullptr);
125 assert(logs_to_free.size() == 0);
126 }
127 };
128
129 } // namespace rocksdb