/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/job_context.h
Line | Count | Source |
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 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
21 | | // Use of this source code is governed by a BSD-style license that can be |
22 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
23 | | |
24 | | #ifndef YB_ROCKSDB_DB_JOB_CONTEXT_H |
25 | | #define YB_ROCKSDB_DB_JOB_CONTEXT_H |
26 | | |
27 | | #pragma once |
28 | | |
29 | | #include <string> |
30 | | #include <vector> |
31 | | |
32 | | #include "yb/rocksdb/db/column_family.h" |
33 | | #include "yb/rocksdb/db/log_writer.h" |
34 | | |
35 | | namespace rocksdb { |
36 | | |
37 | | class MemTable; |
38 | | |
39 | | struct JobContext { |
40 | 2.62M | inline bool HaveSomethingToDelete() const { |
41 | 2.62M | return full_scan_candidate_files.size() || sst_delete_files.size() || |
42 | 1.20M | log_delete_files.size() || manifest_delete_files.size() || |
43 | 660k | new_superversion != nullptr || superversions_to_free.size() > 0 || |
44 | 429k | memtables_to_free.size() > 0 || logs_to_free.size() > 0; |
45 | 2.62M | } |
46 | | |
47 | | // Structure to store information for candidate files to delete. |
48 | | struct CandidateFileInfo { |
49 | | std::string file_name; |
50 | | uint32_t path_id; |
51 | | CandidateFileInfo(std::string name, uint32_t path) |
52 | 5.03M | : file_name(std::move(name)), path_id(path) {} |
53 | 4.06M | bool operator==(const CandidateFileInfo& other) const { |
54 | 4.06M | return file_name == other.file_name && path_id == other.path_id; |
55 | 4.06M | } |
56 | | }; |
57 | | |
58 | | // Unique job id |
59 | | int job_id; |
60 | | |
61 | | // a list of all files that we'll consider deleting |
62 | | // (every once in a while this is filled up with all files |
63 | | // in the DB directory) |
64 | | // (filled only if we're doing full scan) |
65 | | std::vector<CandidateFileInfo> full_scan_candidate_files; |
66 | | |
67 | | // the list of all live sst files that cannot be deleted |
68 | | std::vector<FileDescriptor> sst_live; |
69 | | |
70 | | // a list of sst files that we need to delete |
71 | | std::vector<FileMetaData*> sst_delete_files; |
72 | | |
73 | | // a list of log files that we need to delete |
74 | | std::vector<uint64_t> log_delete_files; |
75 | | |
76 | | // a list of manifest files that we need to delete |
77 | | std::vector<std::string> manifest_delete_files; |
78 | | |
79 | | // a list of memtables to be free |
80 | | autovector<MemTable*> memtables_to_free; |
81 | | |
82 | | autovector<SuperVersion*> superversions_to_free; |
83 | | |
84 | | autovector<log::Writer*> logs_to_free; |
85 | | |
86 | | SuperVersion* new_superversion; // if nullptr no new superversion |
87 | | |
88 | | // the current manifest_file_number, log_number and prev_log_number |
89 | | // that corresponds to the set of files in 'live'. |
90 | | uint64_t manifest_file_number; |
91 | | uint64_t pending_manifest_file_number; |
92 | | uint64_t log_number; |
93 | | uint64_t prev_log_number; |
94 | | |
95 | 1.47M | explicit JobContext(int _job_id, bool create_superversion = false) { |
96 | 1.47M | job_id = _job_id; |
97 | 1.47M | manifest_file_number = 0; |
98 | 1.47M | pending_manifest_file_number = 0; |
99 | 1.47M | log_number = 0; |
100 | 1.47M | prev_log_number = 0; |
101 | 1.35M | new_superversion = create_superversion ? new SuperVersion() : nullptr; |
102 | 1.47M | } |
103 | | |
104 | | // For non-empty JobContext Clean() has to be called at least once before |
105 | | // before destruction (see asserts in ~JobContext()). Should be called with |
106 | | // unlocked DB mutex. Destructor doesn't call Clean() to avoid accidentally |
107 | | // doing potentially slow Clean() with locked DB mutex. |
108 | 1.47M | void Clean() { |
109 | | // free pending memtables |
110 | 2 | for (auto m : memtables_to_free) { |
111 | 2 | delete m; |
112 | 2 | } |
113 | | // free superversions |
114 | 54.8k | for (auto s : superversions_to_free) { |
115 | 54.8k | delete s; |
116 | 54.8k | } |
117 | 20.1k | for (auto l : logs_to_free) { |
118 | 20.1k | delete l; |
119 | 20.1k | } |
120 | | // if new_superversion was not used, it will be non-nullptr and needs |
121 | | // to be freed here |
122 | 1.47M | delete new_superversion; |
123 | | |
124 | 1.47M | memtables_to_free.clear(); |
125 | 1.47M | superversions_to_free.clear(); |
126 | 1.47M | logs_to_free.clear(); |
127 | 1.47M | new_superversion = nullptr; |
128 | 1.47M | } |
129 | | |
130 | 1.47M | ~JobContext() { |
131 | 1.47M | assert(memtables_to_free.size() == 0); |
132 | 1.47M | assert(superversions_to_free.size() == 0); |
133 | 1.47M | assert(new_superversion == nullptr); |
134 | 1.47M | assert(logs_to_free.size() == 0); |
135 | 1.47M | } |
136 | | }; |
137 | | |
138 | | } // namespace rocksdb |
139 | | |
140 | | #endif // YB_ROCKSDB_DB_JOB_CONTEXT_H |