/Users/deen/code/yugabyte-db/src/yb/rocksdb/utilities/stackable_db.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
2 | | // Use of this source code is governed by a BSD-style license that can be |
3 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
4 | | // |
5 | | // The following only applies to changes made to this file as part of YugaByte development. |
6 | | // |
7 | | // Portions Copyright (c) YugaByte, Inc. |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
10 | | // in compliance with the License. You may obtain a copy of the License at |
11 | | // |
12 | | // http://www.apache.org/licenses/LICENSE-2.0 |
13 | | // |
14 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
15 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
16 | | // or implied. See the License for the specific language governing permissions and limitations |
17 | | // under the License. |
18 | | // |
19 | | #ifndef YB_ROCKSDB_UTILITIES_STACKABLE_DB_H |
20 | | #define YB_ROCKSDB_UTILITIES_STACKABLE_DB_H |
21 | | |
22 | | #pragma once |
23 | | #include <string> |
24 | | #include "yb/rocksdb/db.h" |
25 | | |
26 | | #include "yb/util/result.h" |
27 | | |
28 | | #ifdef _WIN32 |
29 | | // Windows API macro interference |
30 | | #undef DeleteFile |
31 | | #endif |
32 | | |
33 | | |
34 | | namespace rocksdb { |
35 | | |
36 | | // This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d |
37 | | class StackableDB : public DB { |
38 | | public: |
39 | | // StackableDB is the owner of db now! |
40 | 89 | explicit StackableDB(DB* db) : db_(db) {} |
41 | | |
42 | 89 | ~StackableDB() { |
43 | 89 | delete db_; |
44 | 89 | } |
45 | | |
46 | 3.19k | virtual DB* GetBaseDB() { |
47 | 3.19k | return db_; |
48 | 3.19k | } |
49 | | |
50 | 0 | virtual DB* GetRootDB() override { return db_->GetRootDB(); } |
51 | | |
52 | | virtual Status CreateColumnFamily(const ColumnFamilyOptions& options, |
53 | | const std::string& column_family_name, |
54 | 5 | ColumnFamilyHandle** handle) override { |
55 | 5 | return db_->CreateColumnFamily(options, column_family_name, handle); |
56 | 5 | } |
57 | | |
58 | 1 | virtual Status DropColumnFamily(ColumnFamilyHandle* column_family) override { |
59 | 1 | return db_->DropColumnFamily(column_family); |
60 | 1 | } |
61 | | |
62 | | using DB::Put; |
63 | | virtual Status Put(const WriteOptions& options, |
64 | | ColumnFamilyHandle* column_family, const Slice& key, |
65 | 0 | const Slice& val) override { |
66 | 0 | return db_->Put(options, column_family, key, val); |
67 | 0 | } |
68 | | |
69 | | using DB::Get; |
70 | | virtual Status Get(const ReadOptions& options, |
71 | | ColumnFamilyHandle* column_family, const Slice& key, |
72 | 91 | std::string* value) override { |
73 | 91 | return db_->Get(options, column_family, key, value); |
74 | 91 | } |
75 | | |
76 | | using DB::MultiGet; |
77 | | virtual std::vector<Status> MultiGet( |
78 | | const ReadOptions& options, |
79 | | const std::vector<ColumnFamilyHandle*>& column_family, |
80 | | const std::vector<Slice>& keys, |
81 | 0 | std::vector<std::string>* values) override { |
82 | 0 | return db_->MultiGet(options, column_family, keys, values); |
83 | 0 | } |
84 | | |
85 | | using DB::AddFile; |
86 | | virtual Status AddFile(ColumnFamilyHandle* column_family, |
87 | | const ExternalSstFileInfo* file_info, |
88 | 0 | bool move_file) override { |
89 | 0 | return db_->AddFile(column_family, file_info, move_file); |
90 | 0 | } |
91 | | virtual Status AddFile(ColumnFamilyHandle* column_family, |
92 | | const std::string& file_path, |
93 | 0 | bool move_file) override { |
94 | 0 | return db_->AddFile(column_family, file_path, move_file); |
95 | 0 | } |
96 | | |
97 | | using DB::KeyMayExist; |
98 | | virtual bool KeyMayExist(const ReadOptions& options, |
99 | | ColumnFamilyHandle* column_family, const Slice& key, |
100 | | std::string* value, |
101 | 0 | bool* value_found = nullptr) override { |
102 | 0 | return db_->KeyMayExist(options, column_family, key, value, value_found); |
103 | 0 | } |
104 | | |
105 | | using DB::Delete; |
106 | | virtual Status Delete(const WriteOptions& wopts, |
107 | | ColumnFamilyHandle* column_family, |
108 | 4 | const Slice& key) override { |
109 | 4 | return db_->Delete(wopts, column_family, key); |
110 | 4 | } |
111 | | |
112 | | using DB::SingleDelete; |
113 | | virtual Status SingleDelete(const WriteOptions& wopts, |
114 | | ColumnFamilyHandle* column_family, |
115 | 3 | const Slice& key) override { |
116 | 3 | return db_->SingleDelete(wopts, column_family, key); |
117 | 3 | } |
118 | | |
119 | | using DB::Merge; |
120 | | virtual Status Merge(const WriteOptions& options, |
121 | | ColumnFamilyHandle* column_family, const Slice& key, |
122 | 0 | const Slice& value) override { |
123 | 0 | return db_->Merge(options, column_family, key, value); |
124 | 0 | } |
125 | | |
126 | | |
127 | | virtual Status Write(const WriteOptions& opts, WriteBatch* updates) |
128 | 26 | override { |
129 | 26 | return db_->Write(opts, updates); |
130 | 26 | } |
131 | | |
132 | | using DB::NewIterator; |
133 | | virtual Iterator* NewIterator(const ReadOptions& opts, |
134 | 9 | ColumnFamilyHandle* column_family) override { |
135 | 9 | return db_->NewIterator(opts, column_family); |
136 | 9 | } |
137 | | |
138 | | virtual Status NewIterators( |
139 | | const ReadOptions& options, |
140 | | const std::vector<ColumnFamilyHandle*>& column_families, |
141 | 15 | std::vector<Iterator*>* iterators) override { |
142 | 15 | return db_->NewIterators(options, column_families, iterators); |
143 | 15 | } |
144 | | |
145 | | |
146 | 0 | virtual const Snapshot* GetSnapshot() override { |
147 | 0 | return db_->GetSnapshot(); |
148 | 0 | } |
149 | | |
150 | 0 | virtual void ReleaseSnapshot(const Snapshot* snapshot) override { |
151 | 0 | return db_->ReleaseSnapshot(snapshot); |
152 | 0 | } |
153 | | |
154 | | using DB::GetProperty; |
155 | | virtual bool GetProperty(ColumnFamilyHandle* column_family, |
156 | 0 | const Slice& property, std::string* value) override { |
157 | 0 | return db_->GetProperty(column_family, property, value); |
158 | 0 | } |
159 | | |
160 | | using DB::GetIntProperty; |
161 | | virtual bool GetIntProperty(ColumnFamilyHandle* column_family, |
162 | 0 | const Slice& property, uint64_t* value) override { |
163 | 0 | return db_->GetIntProperty(column_family, property, value); |
164 | 0 | } |
165 | | |
166 | | using DB::GetAggregatedIntProperty; |
167 | | virtual bool GetAggregatedIntProperty(const Slice& property, |
168 | 0 | uint64_t* value) override { |
169 | 0 | return db_->GetAggregatedIntProperty(property, value); |
170 | 0 | } |
171 | | |
172 | | using DB::GetApproximateSizes; |
173 | | virtual void GetApproximateSizes(ColumnFamilyHandle* column_family, |
174 | | const Range* r, int n, uint64_t* sizes, |
175 | 0 | bool include_memtable = false) override { |
176 | 0 | return db_->GetApproximateSizes(column_family, r, n, sizes, |
177 | 0 | include_memtable); |
178 | 0 | } |
179 | | |
180 | | using DB::CompactRange; |
181 | | virtual Status CompactRange(const CompactRangeOptions& options, |
182 | | ColumnFamilyHandle* column_family, |
183 | 31 | const Slice* begin, const Slice* end) override { |
184 | 31 | return db_->CompactRange(options, column_family, begin, end); |
185 | 31 | } |
186 | | |
187 | | using DB::CompactFiles; |
188 | | virtual Status CompactFiles( |
189 | | const CompactionOptions& compact_options, |
190 | | ColumnFamilyHandle* column_family, |
191 | | const std::vector<std::string>& input_file_names, |
192 | 0 | const int output_level, const int output_path_id = -1) override { |
193 | 0 | return db_->CompactFiles( |
194 | 0 | compact_options, column_family, input_file_names, |
195 | 0 | output_level, output_path_id); |
196 | 0 | } |
197 | | |
198 | 0 | virtual Status PauseBackgroundWork() override { |
199 | 0 | return db_->PauseBackgroundWork(); |
200 | 0 | } |
201 | 0 | virtual Status ContinueBackgroundWork() override { |
202 | 0 | return db_->ContinueBackgroundWork(); |
203 | 0 | } |
204 | | |
205 | | virtual Status EnableAutoCompaction( |
206 | 47 | const std::vector<ColumnFamilyHandle*>& column_family_handles) override { |
207 | 47 | return db_->EnableAutoCompaction(column_family_handles); |
208 | 47 | } |
209 | | |
210 | | using DB::NumberLevels; |
211 | 0 | virtual int NumberLevels(ColumnFamilyHandle* column_family) override { |
212 | 0 | return db_->NumberLevels(column_family); |
213 | 0 | } |
214 | | |
215 | | using DB::MaxMemCompactionLevel; |
216 | | virtual int MaxMemCompactionLevel(ColumnFamilyHandle* column_family) |
217 | 0 | override { |
218 | 0 | return db_->MaxMemCompactionLevel(column_family); |
219 | 0 | } |
220 | | |
221 | | using DB::Level0StopWriteTrigger; |
222 | | virtual int Level0StopWriteTrigger(ColumnFamilyHandle* column_family) |
223 | 0 | override { |
224 | 0 | return db_->Level0StopWriteTrigger(column_family); |
225 | 0 | } |
226 | | |
227 | 0 | virtual const std::string& GetName() const override { |
228 | 0 | return db_->GetName(); |
229 | 0 | } |
230 | | |
231 | 12.2k | virtual Env* GetEnv() const override { |
232 | 12.2k | return db_->GetEnv(); |
233 | 12.2k | } |
234 | | |
235 | 0 | Env* GetCheckpointEnv() const override { |
236 | 0 | return db_->GetCheckpointEnv(); |
237 | 0 | } |
238 | | |
239 | | using DB::GetOptions; |
240 | | virtual const Options& GetOptions(ColumnFamilyHandle* column_family) const |
241 | 37 | override { |
242 | 37 | return db_->GetOptions(column_family); |
243 | 37 | } |
244 | | |
245 | | using DB::GetDBOptions; |
246 | 0 | virtual const DBOptions& GetDBOptions() const override { |
247 | 0 | return db_->GetDBOptions(); |
248 | 0 | } |
249 | | |
250 | | using DB::Flush; |
251 | | virtual Status Flush(const FlushOptions& fopts, |
252 | 24 | ColumnFamilyHandle* column_family) override { |
253 | 24 | return db_->Flush(fopts, column_family); |
254 | 24 | } |
255 | | |
256 | | using DB::WaitForFlush; |
257 | 0 | virtual Status WaitForFlush(ColumnFamilyHandle* column_family) override { |
258 | 0 | return db_->WaitForFlush(column_family); |
259 | 0 | } |
260 | | |
261 | 0 | virtual Status SyncWAL() override { |
262 | 0 | return db_->SyncWAL(); |
263 | 0 | } |
264 | | |
265 | | #ifndef ROCKSDB_LITE |
266 | | |
267 | 0 | virtual Status DisableFileDeletions() override { |
268 | 0 | return db_->DisableFileDeletions(); |
269 | 0 | } |
270 | | |
271 | 0 | virtual Status EnableFileDeletions(bool force) override { |
272 | 0 | return db_->EnableFileDeletions(force); |
273 | 0 | } |
274 | | |
275 | 0 | void GetLiveFilesMetaData(std::vector<LiveFileMetaData>* metadata) override { |
276 | 0 | db_->GetLiveFilesMetaData(metadata); |
277 | 0 | } |
278 | | |
279 | 0 | UserFrontierPtr GetFlushedFrontier() override { |
280 | 0 | return db_->GetFlushedFrontier(); |
281 | 0 | } |
282 | | |
283 | | CHECKED_STATUS ModifyFlushedFrontier( |
284 | | UserFrontierPtr values, |
285 | 0 | FrontierModificationMode mode) override { |
286 | 0 | return db_->ModifyFlushedFrontier(std::move(values), mode); |
287 | 0 | } |
288 | | |
289 | 0 | yb::Result<std::string> GetMiddleKey() override { |
290 | 0 | return db_->GetMiddleKey(); |
291 | 0 | }; |
292 | | |
293 | | virtual void GetColumnFamilyMetaData( |
294 | | ColumnFamilyHandle *column_family, |
295 | 0 | ColumnFamilyMetaData* cf_meta) override { |
296 | 0 | db_->GetColumnFamilyMetaData(column_family, cf_meta); |
297 | 0 | } |
298 | | |
299 | | virtual void GetColumnFamiliesOptions( |
300 | | std::vector<std::string>* column_family_names, |
301 | 0 | std::vector<ColumnFamilyOptions>* column_family_options) override { |
302 | 0 | db_->GetColumnFamiliesOptions(column_family_names, column_family_options); |
303 | 0 | } |
304 | | |
305 | | #endif // ROCKSDB_LITE |
306 | | |
307 | | virtual Status GetLiveFiles(std::vector<std::string>& vec, uint64_t* mfs, |
308 | 0 | bool flush_memtable = true) override { |
309 | 0 | return db_->GetLiveFiles(vec, mfs, flush_memtable); |
310 | 0 | } |
311 | | |
312 | 0 | virtual SequenceNumber GetLatestSequenceNumber() const override { |
313 | 0 | return db_->GetLatestSequenceNumber(); |
314 | 0 | } |
315 | | |
316 | 0 | virtual Status GetSortedWalFiles(VectorLogPtr* files) override { |
317 | 0 | return db_->GetSortedWalFiles(files); |
318 | 0 | } |
319 | | |
320 | 0 | virtual Status DeleteFile(std::string name) override { |
321 | 0 | return db_->DeleteFile(name); |
322 | 0 | } |
323 | | |
324 | 0 | virtual Status GetDbIdentity(std::string* identity) const override { |
325 | 0 | return db_->GetDbIdentity(identity); |
326 | 0 | } |
327 | | |
328 | | using DB::SetOptions; |
329 | | virtual Status SetOptions(ColumnFamilyHandle* column_family_handle, |
330 | | const std::unordered_map<std::string, std::string>& new_options, |
331 | 0 | bool dump_options) override { |
332 | 0 | return db_->SetOptions(column_family_handle, new_options, dump_options); |
333 | 0 | } |
334 | | |
335 | | using DB::GetPropertiesOfAllTables; |
336 | | virtual Status GetPropertiesOfAllTables( |
337 | | ColumnFamilyHandle* column_family, |
338 | 0 | TablePropertiesCollection* props) override { |
339 | 0 | return db_->GetPropertiesOfAllTables(column_family, props); |
340 | 0 | } |
341 | | |
342 | | using DB::GetPropertiesOfTablesInRange; |
343 | | virtual Status GetPropertiesOfTablesInRange( |
344 | | ColumnFamilyHandle* column_family, const Range* range, std::size_t n, |
345 | 0 | TablePropertiesCollection* props) override { |
346 | 0 | return db_->GetPropertiesOfTablesInRange(column_family, range, n, props); |
347 | 0 | } |
348 | | |
349 | | virtual Status GetUpdatesSince( |
350 | | SequenceNumber seq_number, unique_ptr<TransactionLogIterator>* iter, |
351 | 0 | const TransactionLogIterator::ReadOptions& read_options) override { |
352 | 0 | return db_->GetUpdatesSince(seq_number, iter, read_options); |
353 | 0 | } |
354 | | |
355 | 7.43k | virtual ColumnFamilyHandle* DefaultColumnFamily() const override { |
356 | 7.43k | return db_->DefaultColumnFamily(); |
357 | 7.43k | } |
358 | | |
359 | | protected: |
360 | | DB* db_; |
361 | | }; |
362 | | |
363 | | } // namespace rocksdb |
364 | | |
365 | | #endif // YB_ROCKSDB_UTILITIES_STACKABLE_DB_H |