]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/db.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / include / rocksdb / db.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 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file. See the AUTHORS file for names of contributors.
8
9 #pragma once
10
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <unordered_map>
17 #include <vector>
18 #include "rocksdb/iterator.h"
19 #include "rocksdb/listener.h"
20 #include "rocksdb/metadata.h"
21 #include "rocksdb/options.h"
22 #include "rocksdb/snapshot.h"
23 #include "rocksdb/sst_file_writer.h"
24 #include "rocksdb/thread_status.h"
25 #include "rocksdb/transaction_log.h"
26 #include "rocksdb/types.h"
27 #include "rocksdb/version.h"
28
29 #ifdef _WIN32
30 // Windows API macro interference
31 #undef DeleteFile
32 #endif
33
34 #if defined(__GNUC__) || defined(__clang__)
35 #define ROCKSDB_DEPRECATED_FUNC __attribute__((__deprecated__))
36 #elif _WIN32
37 #define ROCKSDB_DEPRECATED_FUNC __declspec(deprecated)
38 #endif
39
40 namespace rocksdb {
41
42 struct Options;
43 struct DBOptions;
44 struct ColumnFamilyOptions;
45 struct ReadOptions;
46 struct WriteOptions;
47 struct FlushOptions;
48 struct CompactionOptions;
49 struct CompactRangeOptions;
50 struct TableProperties;
51 struct ExternalSstFileInfo;
52 class WriteBatch;
53 class Env;
54 class EventListener;
55 class TraceWriter;
56
57 using std::unique_ptr;
58
59 extern const std::string kDefaultColumnFamilyName;
60 struct ColumnFamilyDescriptor {
61 std::string name;
62 ColumnFamilyOptions options;
63 ColumnFamilyDescriptor()
64 : name(kDefaultColumnFamilyName), options(ColumnFamilyOptions()) {}
65 ColumnFamilyDescriptor(const std::string& _name,
66 const ColumnFamilyOptions& _options)
67 : name(_name), options(_options) {}
68 };
69
70 class ColumnFamilyHandle {
71 public:
72 virtual ~ColumnFamilyHandle() {}
73 // Returns the name of the column family associated with the current handle.
74 virtual const std::string& GetName() const = 0;
75 // Returns the ID of the column family associated with the current handle.
76 virtual uint32_t GetID() const = 0;
77 // Fills "*desc" with the up-to-date descriptor of the column family
78 // associated with this handle. Since it fills "*desc" with the up-to-date
79 // information, this call might internally lock and release DB mutex to
80 // access the up-to-date CF options. In addition, all the pointer-typed
81 // options cannot be referenced any longer than the original options exist.
82 //
83 // Note that this function is not supported in RocksDBLite.
84 virtual Status GetDescriptor(ColumnFamilyDescriptor* desc) = 0;
85 // Returns the comparator of the column family associated with the
86 // current handle.
87 virtual const Comparator* GetComparator() const = 0;
88 };
89
90 static const int kMajorVersion = __ROCKSDB_MAJOR__;
91 static const int kMinorVersion = __ROCKSDB_MINOR__;
92
93 // A range of keys
94 struct Range {
95 Slice start;
96 Slice limit;
97
98 Range() { }
99 Range(const Slice& s, const Slice& l) : start(s), limit(l) { }
100 };
101
102 struct RangePtr {
103 const Slice* start;
104 const Slice* limit;
105
106 RangePtr() : start(nullptr), limit(nullptr) { }
107 RangePtr(const Slice* s, const Slice* l) : start(s), limit(l) { }
108 };
109
110 // A collections of table properties objects, where
111 // key: is the table's file name.
112 // value: the table properties object of the given table.
113 typedef std::unordered_map<std::string, std::shared_ptr<const TableProperties>>
114 TablePropertiesCollection;
115
116 // A DB is a persistent ordered map from keys to values.
117 // A DB is safe for concurrent access from multiple threads without
118 // any external synchronization.
119 class DB {
120 public:
121 // Open the database with the specified "name".
122 // Stores a pointer to a heap-allocated database in *dbptr and returns
123 // OK on success.
124 // Stores nullptr in *dbptr and returns a non-OK status on error.
125 // Caller should delete *dbptr when it is no longer needed.
126 static Status Open(const Options& options,
127 const std::string& name,
128 DB** dbptr);
129
130 // Open the database for read only. All DB interfaces
131 // that modify data, like put/delete, will return error.
132 // If the db is opened in read only mode, then no compactions
133 // will happen.
134 //
135 // Not supported in ROCKSDB_LITE, in which case the function will
136 // return Status::NotSupported.
137 static Status OpenForReadOnly(const Options& options,
138 const std::string& name, DB** dbptr,
139 bool error_if_log_file_exist = false);
140
141 // Open the database for read only with column families. When opening DB with
142 // read only, you can specify only a subset of column families in the
143 // database that should be opened. However, you always need to specify default
144 // column family. The default column family name is 'default' and it's stored
145 // in rocksdb::kDefaultColumnFamilyName
146 //
147 // Not supported in ROCKSDB_LITE, in which case the function will
148 // return Status::NotSupported.
149 static Status OpenForReadOnly(
150 const DBOptions& db_options, const std::string& name,
151 const std::vector<ColumnFamilyDescriptor>& column_families,
152 std::vector<ColumnFamilyHandle*>* handles, DB** dbptr,
153 bool error_if_log_file_exist = false);
154
155 // Open DB with column families.
156 // db_options specify database specific options
157 // column_families is the vector of all column families in the database,
158 // containing column family name and options. You need to open ALL column
159 // families in the database. To get the list of column families, you can use
160 // ListColumnFamilies(). Also, you can open only a subset of column families
161 // for read-only access.
162 // The default column family name is 'default' and it's stored
163 // in rocksdb::kDefaultColumnFamilyName.
164 // If everything is OK, handles will on return be the same size
165 // as column_families --- handles[i] will be a handle that you
166 // will use to operate on column family column_family[i].
167 // Before delete DB, you have to close All column families by calling
168 // DestroyColumnFamilyHandle() with all the handles.
169 static Status Open(const DBOptions& db_options, const std::string& name,
170 const std::vector<ColumnFamilyDescriptor>& column_families,
171 std::vector<ColumnFamilyHandle*>* handles, DB** dbptr);
172
173 virtual Status Resume() { return Status::NotSupported(); }
174
175 // Close the DB by releasing resources, closing files etc. This should be
176 // called before calling the destructor so that the caller can get back a
177 // status in case there are any errors. This will not fsync the WAL files.
178 // If syncing is required, the caller must first call SyncWAL(), or Write()
179 // using an empty write batch with WriteOptions.sync=true.
180 // Regardless of the return status, the DB must be freed. If the return
181 // status is NotSupported(), then the DB implementation does cleanup in the
182 // destructor
183 virtual Status Close() { return Status::NotSupported(); }
184
185 // ListColumnFamilies will open the DB specified by argument name
186 // and return the list of all column families in that DB
187 // through column_families argument. The ordering of
188 // column families in column_families is unspecified.
189 static Status ListColumnFamilies(const DBOptions& db_options,
190 const std::string& name,
191 std::vector<std::string>* column_families);
192
193 DB() { }
194 virtual ~DB();
195
196 // Create a column_family and return the handle of column family
197 // through the argument handle.
198 virtual Status CreateColumnFamily(const ColumnFamilyOptions& options,
199 const std::string& column_family_name,
200 ColumnFamilyHandle** handle);
201
202 // Bulk create column families with the same column family options.
203 // Return the handles of the column families through the argument handles.
204 // In case of error, the request may succeed partially, and handles will
205 // contain column family handles that it managed to create, and have size
206 // equal to the number of created column families.
207 virtual Status CreateColumnFamilies(
208 const ColumnFamilyOptions& options,
209 const std::vector<std::string>& column_family_names,
210 std::vector<ColumnFamilyHandle*>* handles);
211
212 // Bulk create column families.
213 // Return the handles of the column families through the argument handles.
214 // In case of error, the request may succeed partially, and handles will
215 // contain column family handles that it managed to create, and have size
216 // equal to the number of created column families.
217 virtual Status CreateColumnFamilies(
218 const std::vector<ColumnFamilyDescriptor>& column_families,
219 std::vector<ColumnFamilyHandle*>* handles);
220
221 // Drop a column family specified by column_family handle. This call
222 // only records a drop record in the manifest and prevents the column
223 // family from flushing and compacting.
224 virtual Status DropColumnFamily(ColumnFamilyHandle* column_family);
225
226 // Bulk drop column families. This call only records drop records in the
227 // manifest and prevents the column families from flushing and compacting.
228 // In case of error, the request may succeed partially. User may call
229 // ListColumnFamilies to check the result.
230 virtual Status DropColumnFamilies(
231 const std::vector<ColumnFamilyHandle*>& column_families);
232
233 // Close a column family specified by column_family handle and destroy
234 // the column family handle specified to avoid double deletion. This call
235 // deletes the column family handle by default. Use this method to
236 // close column family instead of deleting column family handle directly
237 virtual Status DestroyColumnFamilyHandle(ColumnFamilyHandle* column_family);
238
239 // Set the database entry for "key" to "value".
240 // If "key" already exists, it will be overwritten.
241 // Returns OK on success, and a non-OK status on error.
242 // Note: consider setting options.sync = true.
243 virtual Status Put(const WriteOptions& options,
244 ColumnFamilyHandle* column_family, const Slice& key,
245 const Slice& value) = 0;
246 virtual Status Put(const WriteOptions& options, const Slice& key,
247 const Slice& value) {
248 return Put(options, DefaultColumnFamily(), key, value);
249 }
250
251 // Remove the database entry (if any) for "key". Returns OK on
252 // success, and a non-OK status on error. It is not an error if "key"
253 // did not exist in the database.
254 // Note: consider setting options.sync = true.
255 virtual Status Delete(const WriteOptions& options,
256 ColumnFamilyHandle* column_family,
257 const Slice& key) = 0;
258 virtual Status Delete(const WriteOptions& options, const Slice& key) {
259 return Delete(options, DefaultColumnFamily(), key);
260 }
261
262 // Remove the database entry for "key". Requires that the key exists
263 // and was not overwritten. Returns OK on success, and a non-OK status
264 // on error. It is not an error if "key" did not exist in the database.
265 //
266 // If a key is overwritten (by calling Put() multiple times), then the result
267 // of calling SingleDelete() on this key is undefined. SingleDelete() only
268 // behaves correctly if there has been only one Put() for this key since the
269 // previous call to SingleDelete() for this key.
270 //
271 // This feature is currently an experimental performance optimization
272 // for a very specific workload. It is up to the caller to ensure that
273 // SingleDelete is only used for a key that is not deleted using Delete() or
274 // written using Merge(). Mixing SingleDelete operations with Deletes and
275 // Merges can result in undefined behavior.
276 //
277 // Note: consider setting options.sync = true.
278 virtual Status SingleDelete(const WriteOptions& options,
279 ColumnFamilyHandle* column_family,
280 const Slice& key) = 0;
281 virtual Status SingleDelete(const WriteOptions& options, const Slice& key) {
282 return SingleDelete(options, DefaultColumnFamily(), key);
283 }
284
285 // Removes the database entries in the range ["begin_key", "end_key"), i.e.,
286 // including "begin_key" and excluding "end_key". Returns OK on success, and
287 // a non-OK status on error. It is not an error if no keys exist in the range
288 // ["begin_key", "end_key").
289 //
290 // This feature is currently an experimental performance optimization for
291 // deleting very large ranges of contiguous keys. Invoking it many times or on
292 // small ranges may severely degrade read performance; in particular, the
293 // resulting performance can be worse than calling Delete() for each key in
294 // the range. Note also the degraded read performance affects keys outside the
295 // deleted ranges, and affects database operations involving scans, like flush
296 // and compaction.
297 //
298 // Consider setting ReadOptions::ignore_range_deletions = true to speed
299 // up reads for key(s) that are known to be unaffected by range deletions.
300 virtual Status DeleteRange(const WriteOptions& options,
301 ColumnFamilyHandle* column_family,
302 const Slice& begin_key, const Slice& end_key);
303
304 // Merge the database entry for "key" with "value". Returns OK on success,
305 // and a non-OK status on error. The semantics of this operation is
306 // determined by the user provided merge_operator when opening DB.
307 // Note: consider setting options.sync = true.
308 virtual Status Merge(const WriteOptions& options,
309 ColumnFamilyHandle* column_family, const Slice& key,
310 const Slice& value) = 0;
311 virtual Status Merge(const WriteOptions& options, const Slice& key,
312 const Slice& value) {
313 return Merge(options, DefaultColumnFamily(), key, value);
314 }
315
316 // Apply the specified updates to the database.
317 // If `updates` contains no update, WAL will still be synced if
318 // options.sync=true.
319 // Returns OK on success, non-OK on failure.
320 // Note: consider setting options.sync = true.
321 virtual Status Write(const WriteOptions& options, WriteBatch* updates) = 0;
322
323 // If the database contains an entry for "key" store the
324 // corresponding value in *value and return OK.
325 //
326 // If there is no entry for "key" leave *value unchanged and return
327 // a status for which Status::IsNotFound() returns true.
328 //
329 // May return some other Status on an error.
330 virtual inline Status Get(const ReadOptions& options,
331 ColumnFamilyHandle* column_family, const Slice& key,
332 std::string* value) {
333 assert(value != nullptr);
334 PinnableSlice pinnable_val(value);
335 assert(!pinnable_val.IsPinned());
336 auto s = Get(options, column_family, key, &pinnable_val);
337 if (s.ok() && pinnable_val.IsPinned()) {
338 value->assign(pinnable_val.data(), pinnable_val.size());
339 } // else value is already assigned
340 return s;
341 }
342 virtual Status Get(const ReadOptions& options,
343 ColumnFamilyHandle* column_family, const Slice& key,
344 PinnableSlice* value) = 0;
345 virtual Status Get(const ReadOptions& options, const Slice& key, std::string* value) {
346 return Get(options, DefaultColumnFamily(), key, value);
347 }
348
349 // If keys[i] does not exist in the database, then the i'th returned
350 // status will be one for which Status::IsNotFound() is true, and
351 // (*values)[i] will be set to some arbitrary value (often ""). Otherwise,
352 // the i'th returned status will have Status::ok() true, and (*values)[i]
353 // will store the value associated with keys[i].
354 //
355 // (*values) will always be resized to be the same size as (keys).
356 // Similarly, the number of returned statuses will be the number of keys.
357 // Note: keys will not be "de-duplicated". Duplicate keys will return
358 // duplicate values in order.
359 virtual std::vector<Status> MultiGet(
360 const ReadOptions& options,
361 const std::vector<ColumnFamilyHandle*>& column_family,
362 const std::vector<Slice>& keys, std::vector<std::string>* values) = 0;
363 virtual std::vector<Status> MultiGet(const ReadOptions& options,
364 const std::vector<Slice>& keys,
365 std::vector<std::string>* values) {
366 return MultiGet(options, std::vector<ColumnFamilyHandle*>(
367 keys.size(), DefaultColumnFamily()),
368 keys, values);
369 }
370
371 // If the key definitely does not exist in the database, then this method
372 // returns false, else true. If the caller wants to obtain value when the key
373 // is found in memory, a bool for 'value_found' must be passed. 'value_found'
374 // will be true on return if value has been set properly.
375 // This check is potentially lighter-weight than invoking DB::Get(). One way
376 // to make this lighter weight is to avoid doing any IOs.
377 // Default implementation here returns true and sets 'value_found' to false
378 virtual bool KeyMayExist(const ReadOptions& /*options*/,
379 ColumnFamilyHandle* /*column_family*/,
380 const Slice& /*key*/, std::string* /*value*/,
381 bool* value_found = nullptr) {
382 if (value_found != nullptr) {
383 *value_found = false;
384 }
385 return true;
386 }
387 virtual bool KeyMayExist(const ReadOptions& options, const Slice& key,
388 std::string* value, bool* value_found = nullptr) {
389 return KeyMayExist(options, DefaultColumnFamily(), key, value, value_found);
390 }
391
392 // Return a heap-allocated iterator over the contents of the database.
393 // The result of NewIterator() is initially invalid (caller must
394 // call one of the Seek methods on the iterator before using it).
395 //
396 // Caller should delete the iterator when it is no longer needed.
397 // The returned iterator should be deleted before this db is deleted.
398 virtual Iterator* NewIterator(const ReadOptions& options,
399 ColumnFamilyHandle* column_family) = 0;
400 virtual Iterator* NewIterator(const ReadOptions& options) {
401 return NewIterator(options, DefaultColumnFamily());
402 }
403 // Returns iterators from a consistent database state across multiple
404 // column families. Iterators are heap allocated and need to be deleted
405 // before the db is deleted
406 virtual Status NewIterators(
407 const ReadOptions& options,
408 const std::vector<ColumnFamilyHandle*>& column_families,
409 std::vector<Iterator*>* iterators) = 0;
410
411 // Return a handle to the current DB state. Iterators created with
412 // this handle will all observe a stable snapshot of the current DB
413 // state. The caller must call ReleaseSnapshot(result) when the
414 // snapshot is no longer needed.
415 //
416 // nullptr will be returned if the DB fails to take a snapshot or does
417 // not support snapshot.
418 virtual const Snapshot* GetSnapshot() = 0;
419
420 // Release a previously acquired snapshot. The caller must not
421 // use "snapshot" after this call.
422 virtual void ReleaseSnapshot(const Snapshot* snapshot) = 0;
423
424 #ifndef ROCKSDB_LITE
425 // Contains all valid property arguments for GetProperty().
426 //
427 // NOTE: Property names cannot end in numbers since those are interpreted as
428 // arguments, e.g., see kNumFilesAtLevelPrefix.
429 struct Properties {
430 // "rocksdb.num-files-at-level<N>" - returns string containing the number
431 // of files at level <N>, where <N> is an ASCII representation of a
432 // level number (e.g., "0").
433 static const std::string kNumFilesAtLevelPrefix;
434
435 // "rocksdb.compression-ratio-at-level<N>" - returns string containing the
436 // compression ratio of data at level <N>, where <N> is an ASCII
437 // representation of a level number (e.g., "0"). Here, compression
438 // ratio is defined as uncompressed data size / compressed file size.
439 // Returns "-1.0" if no open files at level <N>.
440 static const std::string kCompressionRatioAtLevelPrefix;
441
442 // "rocksdb.stats" - returns a multi-line string containing the data
443 // described by kCFStats followed by the data described by kDBStats.
444 static const std::string kStats;
445
446 // "rocksdb.sstables" - returns a multi-line string summarizing current
447 // SST files.
448 static const std::string kSSTables;
449
450 // "rocksdb.cfstats" - Both of "rocksdb.cfstats-no-file-histogram" and
451 // "rocksdb.cf-file-histogram" together. See below for description
452 // of the two.
453 static const std::string kCFStats;
454
455 // "rocksdb.cfstats-no-file-histogram" - returns a multi-line string with
456 // general columm family stats per-level over db's lifetime ("L<n>"),
457 // aggregated over db's lifetime ("Sum"), and aggregated over the
458 // interval since the last retrieval ("Int").
459 // It could also be used to return the stats in the format of the map.
460 // In this case there will a pair of string to array of double for
461 // each level as well as for "Sum". "Int" stats will not be affected
462 // when this form of stats are retrieved.
463 static const std::string kCFStatsNoFileHistogram;
464
465 // "rocksdb.cf-file-histogram" - print out how many file reads to every
466 // level, as well as the histogram of latency of single requests.
467 static const std::string kCFFileHistogram;
468
469 // "rocksdb.dbstats" - returns a multi-line string with general database
470 // stats, both cumulative (over the db's lifetime) and interval (since
471 // the last retrieval of kDBStats).
472 static const std::string kDBStats;
473
474 // "rocksdb.levelstats" - returns multi-line string containing the number
475 // of files per level and total size of each level (MB).
476 static const std::string kLevelStats;
477
478 // "rocksdb.num-immutable-mem-table" - returns number of immutable
479 // memtables that have not yet been flushed.
480 static const std::string kNumImmutableMemTable;
481
482 // "rocksdb.num-immutable-mem-table-flushed" - returns number of immutable
483 // memtables that have already been flushed.
484 static const std::string kNumImmutableMemTableFlushed;
485
486 // "rocksdb.mem-table-flush-pending" - returns 1 if a memtable flush is
487 // pending; otherwise, returns 0.
488 static const std::string kMemTableFlushPending;
489
490 // "rocksdb.num-running-flushes" - returns the number of currently running
491 // flushes.
492 static const std::string kNumRunningFlushes;
493
494 // "rocksdb.compaction-pending" - returns 1 if at least one compaction is
495 // pending; otherwise, returns 0.
496 static const std::string kCompactionPending;
497
498 // "rocksdb.num-running-compactions" - returns the number of currently
499 // running compactions.
500 static const std::string kNumRunningCompactions;
501
502 // "rocksdb.background-errors" - returns accumulated number of background
503 // errors.
504 static const std::string kBackgroundErrors;
505
506 // "rocksdb.cur-size-active-mem-table" - returns approximate size of active
507 // memtable (bytes).
508 static const std::string kCurSizeActiveMemTable;
509
510 // "rocksdb.cur-size-all-mem-tables" - returns approximate size of active
511 // and unflushed immutable memtables (bytes).
512 static const std::string kCurSizeAllMemTables;
513
514 // "rocksdb.size-all-mem-tables" - returns approximate size of active,
515 // unflushed immutable, and pinned immutable memtables (bytes).
516 static const std::string kSizeAllMemTables;
517
518 // "rocksdb.num-entries-active-mem-table" - returns total number of entries
519 // in the active memtable.
520 static const std::string kNumEntriesActiveMemTable;
521
522 // "rocksdb.num-entries-imm-mem-tables" - returns total number of entries
523 // in the unflushed immutable memtables.
524 static const std::string kNumEntriesImmMemTables;
525
526 // "rocksdb.num-deletes-active-mem-table" - returns total number of delete
527 // entries in the active memtable.
528 static const std::string kNumDeletesActiveMemTable;
529
530 // "rocksdb.num-deletes-imm-mem-tables" - returns total number of delete
531 // entries in the unflushed immutable memtables.
532 static const std::string kNumDeletesImmMemTables;
533
534 // "rocksdb.estimate-num-keys" - returns estimated number of total keys in
535 // the active and unflushed immutable memtables and storage.
536 static const std::string kEstimateNumKeys;
537
538 // "rocksdb.estimate-table-readers-mem" - returns estimated memory used for
539 // reading SST tables, excluding memory used in block cache (e.g.,
540 // filter and index blocks).
541 static const std::string kEstimateTableReadersMem;
542
543 // "rocksdb.is-file-deletions-enabled" - returns 0 if deletion of obsolete
544 // files is enabled; otherwise, returns a non-zero number.
545 static const std::string kIsFileDeletionsEnabled;
546
547 // "rocksdb.num-snapshots" - returns number of unreleased snapshots of the
548 // database.
549 static const std::string kNumSnapshots;
550
551 // "rocksdb.oldest-snapshot-time" - returns number representing unix
552 // timestamp of oldest unreleased snapshot.
553 static const std::string kOldestSnapshotTime;
554
555 // "rocksdb.num-live-versions" - returns number of live versions. `Version`
556 // is an internal data structure. See version_set.h for details. More
557 // live versions often mean more SST files are held from being deleted,
558 // by iterators or unfinished compactions.
559 static const std::string kNumLiveVersions;
560
561 // "rocksdb.current-super-version-number" - returns number of current LSM
562 // version. It is a uint64_t integer number, incremented after there is
563 // any change to the LSM tree. The number is not preserved after restarting
564 // the DB. After DB restart, it will start from 0 again.
565 static const std::string kCurrentSuperVersionNumber;
566
567 // "rocksdb.estimate-live-data-size" - returns an estimate of the amount of
568 // live data in bytes.
569 static const std::string kEstimateLiveDataSize;
570
571 // "rocksdb.min-log-number-to-keep" - return the minimum log number of the
572 // log files that should be kept.
573 static const std::string kMinLogNumberToKeep;
574
575 // "rocksdb.total-sst-files-size" - returns total size (bytes) of all SST
576 // files.
577 // WARNING: may slow down online queries if there are too many files.
578 static const std::string kTotalSstFilesSize;
579
580 // "rocksdb.live-sst-files-size" - returns total size (bytes) of all SST
581 // files belong to the latest LSM tree.
582 static const std::string kLiveSstFilesSize;
583
584 // "rocksdb.base-level" - returns number of level to which L0 data will be
585 // compacted.
586 static const std::string kBaseLevel;
587
588 // "rocksdb.estimate-pending-compaction-bytes" - returns estimated total
589 // number of bytes compaction needs to rewrite to get all levels down
590 // to under target size. Not valid for other compactions than level-
591 // based.
592 static const std::string kEstimatePendingCompactionBytes;
593
594 // "rocksdb.aggregated-table-properties" - returns a string representation
595 // of the aggregated table properties of the target column family.
596 static const std::string kAggregatedTableProperties;
597
598 // "rocksdb.aggregated-table-properties-at-level<N>", same as the previous
599 // one but only returns the aggregated table properties of the
600 // specified level "N" at the target column family.
601 static const std::string kAggregatedTablePropertiesAtLevel;
602
603 // "rocksdb.actual-delayed-write-rate" - returns the current actual delayed
604 // write rate. 0 means no delay.
605 static const std::string kActualDelayedWriteRate;
606
607 // "rocksdb.is-write-stopped" - Return 1 if write has been stopped.
608 static const std::string kIsWriteStopped;
609
610 // "rocksdb.estimate-oldest-key-time" - returns an estimation of
611 // oldest key timestamp in the DB. Currently only available for
612 // FIFO compaction with
613 // compaction_options_fifo.allow_compaction = false.
614 static const std::string kEstimateOldestKeyTime;
615
616 // "rocksdb.block-cache-capacity" - returns block cache capacity.
617 static const std::string kBlockCacheCapacity;
618
619 // "rocksdb.block-cache-usage" - returns the memory size for the entries
620 // residing in block cache.
621 static const std::string kBlockCacheUsage;
622
623 // "rocksdb.block-cache-pinned-usage" - returns the memory size for the
624 // entries being pinned.
625 static const std::string kBlockCachePinnedUsage;
626
627 // "rocksdb.options-statistics" - returns multi-line string
628 // of options.statistics
629 static const std::string kOptionsStatistics;
630 };
631 #endif /* ROCKSDB_LITE */
632
633 // DB implementations can export properties about their state via this method.
634 // If "property" is a valid property understood by this DB implementation (see
635 // Properties struct above for valid options), fills "*value" with its current
636 // value and returns true. Otherwise, returns false.
637 virtual bool GetProperty(ColumnFamilyHandle* column_family,
638 const Slice& property, std::string* value) = 0;
639 virtual bool GetProperty(const Slice& property, std::string* value) {
640 return GetProperty(DefaultColumnFamily(), property, value);
641 }
642 virtual bool GetMapProperty(ColumnFamilyHandle* column_family,
643 const Slice& property,
644 std::map<std::string, std::string>* value) = 0;
645 virtual bool GetMapProperty(const Slice& property,
646 std::map<std::string, std::string>* value) {
647 return GetMapProperty(DefaultColumnFamily(), property, value);
648 }
649
650 // Similar to GetProperty(), but only works for a subset of properties whose
651 // return value is an integer. Return the value by integer. Supported
652 // properties:
653 // "rocksdb.num-immutable-mem-table"
654 // "rocksdb.mem-table-flush-pending"
655 // "rocksdb.compaction-pending"
656 // "rocksdb.background-errors"
657 // "rocksdb.cur-size-active-mem-table"
658 // "rocksdb.cur-size-all-mem-tables"
659 // "rocksdb.size-all-mem-tables"
660 // "rocksdb.num-entries-active-mem-table"
661 // "rocksdb.num-entries-imm-mem-tables"
662 // "rocksdb.num-deletes-active-mem-table"
663 // "rocksdb.num-deletes-imm-mem-tables"
664 // "rocksdb.estimate-num-keys"
665 // "rocksdb.estimate-table-readers-mem"
666 // "rocksdb.is-file-deletions-enabled"
667 // "rocksdb.num-snapshots"
668 // "rocksdb.oldest-snapshot-time"
669 // "rocksdb.num-live-versions"
670 // "rocksdb.current-super-version-number"
671 // "rocksdb.estimate-live-data-size"
672 // "rocksdb.min-log-number-to-keep"
673 // "rocksdb.total-sst-files-size"
674 // "rocksdb.live-sst-files-size"
675 // "rocksdb.base-level"
676 // "rocksdb.estimate-pending-compaction-bytes"
677 // "rocksdb.num-running-compactions"
678 // "rocksdb.num-running-flushes"
679 // "rocksdb.actual-delayed-write-rate"
680 // "rocksdb.is-write-stopped"
681 // "rocksdb.estimate-oldest-key-time"
682 // "rocksdb.block-cache-capacity"
683 // "rocksdb.block-cache-usage"
684 // "rocksdb.block-cache-pinned-usage"
685 virtual bool GetIntProperty(ColumnFamilyHandle* column_family,
686 const Slice& property, uint64_t* value) = 0;
687 virtual bool GetIntProperty(const Slice& property, uint64_t* value) {
688 return GetIntProperty(DefaultColumnFamily(), property, value);
689 }
690
691 // Reset internal stats for DB and all column families.
692 // Note this doesn't reset options.statistics as it is not owned by
693 // DB.
694 virtual Status ResetStats() {
695 return Status::NotSupported("Not implemented");
696 }
697
698 // Same as GetIntProperty(), but this one returns the aggregated int
699 // property from all column families.
700 virtual bool GetAggregatedIntProperty(const Slice& property,
701 uint64_t* value) = 0;
702
703 // Flags for DB::GetSizeApproximation that specify whether memtable
704 // stats should be included, or file stats approximation or both
705 enum SizeApproximationFlags : uint8_t {
706 NONE = 0,
707 INCLUDE_MEMTABLES = 1,
708 INCLUDE_FILES = 1 << 1
709 };
710
711 // For each i in [0,n-1], store in "sizes[i]", the approximate
712 // file system space used by keys in "[range[i].start .. range[i].limit)".
713 //
714 // Note that the returned sizes measure file system space usage, so
715 // if the user data compresses by a factor of ten, the returned
716 // sizes will be one-tenth the size of the corresponding user data size.
717 //
718 // If include_flags defines whether the returned size should include
719 // the recently written data in the mem-tables (if
720 // the mem-table type supports it), data serialized to disk, or both.
721 // include_flags should be of type DB::SizeApproximationFlags
722 virtual void GetApproximateSizes(ColumnFamilyHandle* column_family,
723 const Range* range, int n, uint64_t* sizes,
724 uint8_t include_flags
725 = INCLUDE_FILES) = 0;
726 virtual void GetApproximateSizes(const Range* range, int n, uint64_t* sizes,
727 uint8_t include_flags
728 = INCLUDE_FILES) {
729 GetApproximateSizes(DefaultColumnFamily(), range, n, sizes,
730 include_flags);
731 }
732
733 // The method is similar to GetApproximateSizes, except it
734 // returns approximate number of records in memtables.
735 virtual void GetApproximateMemTableStats(ColumnFamilyHandle* column_family,
736 const Range& range,
737 uint64_t* const count,
738 uint64_t* const size) = 0;
739 virtual void GetApproximateMemTableStats(const Range& range,
740 uint64_t* const count,
741 uint64_t* const size) {
742 GetApproximateMemTableStats(DefaultColumnFamily(), range, count, size);
743 }
744
745 // Deprecated versions of GetApproximateSizes
746 ROCKSDB_DEPRECATED_FUNC virtual void GetApproximateSizes(
747 const Range* range, int n, uint64_t* sizes,
748 bool include_memtable) {
749 uint8_t include_flags = SizeApproximationFlags::INCLUDE_FILES;
750 if (include_memtable) {
751 include_flags |= SizeApproximationFlags::INCLUDE_MEMTABLES;
752 }
753 GetApproximateSizes(DefaultColumnFamily(), range, n, sizes, include_flags);
754 }
755 ROCKSDB_DEPRECATED_FUNC virtual void GetApproximateSizes(
756 ColumnFamilyHandle* column_family,
757 const Range* range, int n, uint64_t* sizes,
758 bool include_memtable) {
759 uint8_t include_flags = SizeApproximationFlags::INCLUDE_FILES;
760 if (include_memtable) {
761 include_flags |= SizeApproximationFlags::INCLUDE_MEMTABLES;
762 }
763 GetApproximateSizes(column_family, range, n, sizes, include_flags);
764 }
765
766 // Compact the underlying storage for the key range [*begin,*end].
767 // The actual compaction interval might be superset of [*begin, *end].
768 // In particular, deleted and overwritten versions are discarded,
769 // and the data is rearranged to reduce the cost of operations
770 // needed to access the data. This operation should typically only
771 // be invoked by users who understand the underlying implementation.
772 //
773 // begin==nullptr is treated as a key before all keys in the database.
774 // end==nullptr is treated as a key after all keys in the database.
775 // Therefore the following call will compact the entire database:
776 // db->CompactRange(options, nullptr, nullptr);
777 // Note that after the entire database is compacted, all data are pushed
778 // down to the last level containing any data. If the total data size after
779 // compaction is reduced, that level might not be appropriate for hosting all
780 // the files. In this case, client could set options.change_level to true, to
781 // move the files back to the minimum level capable of holding the data set
782 // or a given level (specified by non-negative options.target_level).
783 virtual Status CompactRange(const CompactRangeOptions& options,
784 ColumnFamilyHandle* column_family,
785 const Slice* begin, const Slice* end) = 0;
786 virtual Status CompactRange(const CompactRangeOptions& options,
787 const Slice* begin, const Slice* end) {
788 return CompactRange(options, DefaultColumnFamily(), begin, end);
789 }
790
791 ROCKSDB_DEPRECATED_FUNC virtual Status CompactRange(
792 ColumnFamilyHandle* column_family, const Slice* begin, const Slice* end,
793 bool change_level = false, int target_level = -1,
794 uint32_t target_path_id = 0) {
795 CompactRangeOptions options;
796 options.change_level = change_level;
797 options.target_level = target_level;
798 options.target_path_id = target_path_id;
799 return CompactRange(options, column_family, begin, end);
800 }
801
802 ROCKSDB_DEPRECATED_FUNC virtual Status CompactRange(
803 const Slice* begin, const Slice* end, bool change_level = false,
804 int target_level = -1, uint32_t target_path_id = 0) {
805 CompactRangeOptions options;
806 options.change_level = change_level;
807 options.target_level = target_level;
808 options.target_path_id = target_path_id;
809 return CompactRange(options, DefaultColumnFamily(), begin, end);
810 }
811
812 virtual Status SetOptions(
813 ColumnFamilyHandle* /*column_family*/,
814 const std::unordered_map<std::string, std::string>& /*new_options*/) {
815 return Status::NotSupported("Not implemented");
816 }
817 virtual Status SetOptions(
818 const std::unordered_map<std::string, std::string>& new_options) {
819 return SetOptions(DefaultColumnFamily(), new_options);
820 }
821
822 virtual Status SetDBOptions(
823 const std::unordered_map<std::string, std::string>& new_options) = 0;
824
825 // CompactFiles() inputs a list of files specified by file numbers and
826 // compacts them to the specified level. Note that the behavior is different
827 // from CompactRange() in that CompactFiles() performs the compaction job
828 // using the CURRENT thread.
829 //
830 // @see GetDataBaseMetaData
831 // @see GetColumnFamilyMetaData
832 virtual Status CompactFiles(
833 const CompactionOptions& compact_options,
834 ColumnFamilyHandle* column_family,
835 const std::vector<std::string>& input_file_names,
836 const int output_level, const int output_path_id = -1,
837 std::vector<std::string>* const output_file_names = nullptr) = 0;
838
839 virtual Status CompactFiles(
840 const CompactionOptions& compact_options,
841 const std::vector<std::string>& input_file_names,
842 const int output_level, const int output_path_id = -1,
843 std::vector<std::string>* const output_file_names = nullptr) {
844 return CompactFiles(compact_options, DefaultColumnFamily(),
845 input_file_names, output_level, output_path_id,
846 output_file_names);
847 }
848
849 // This function will wait until all currently running background processes
850 // finish. After it returns, no background process will be run until
851 // ContinueBackgroundWork is called
852 virtual Status PauseBackgroundWork() = 0;
853 virtual Status ContinueBackgroundWork() = 0;
854
855 // This function will enable automatic compactions for the given column
856 // families if they were previously disabled. The function will first set the
857 // disable_auto_compactions option for each column family to 'false', after
858 // which it will schedule a flush/compaction.
859 //
860 // NOTE: Setting disable_auto_compactions to 'false' through SetOptions() API
861 // does NOT schedule a flush/compaction afterwards, and only changes the
862 // parameter itself within the column family option.
863 //
864 virtual Status EnableAutoCompaction(
865 const std::vector<ColumnFamilyHandle*>& column_family_handles) = 0;
866
867 // Number of levels used for this DB.
868 virtual int NumberLevels(ColumnFamilyHandle* column_family) = 0;
869 virtual int NumberLevels() { return NumberLevels(DefaultColumnFamily()); }
870
871 // Maximum level to which a new compacted memtable is pushed if it
872 // does not create overlap.
873 virtual int MaxMemCompactionLevel(ColumnFamilyHandle* column_family) = 0;
874 virtual int MaxMemCompactionLevel() {
875 return MaxMemCompactionLevel(DefaultColumnFamily());
876 }
877
878 // Number of files in level-0 that would stop writes.
879 virtual int Level0StopWriteTrigger(ColumnFamilyHandle* column_family) = 0;
880 virtual int Level0StopWriteTrigger() {
881 return Level0StopWriteTrigger(DefaultColumnFamily());
882 }
883
884 // Get DB name -- the exact same name that was provided as an argument to
885 // DB::Open()
886 virtual const std::string& GetName() const = 0;
887
888 // Get Env object from the DB
889 virtual Env* GetEnv() const = 0;
890
891 // Get DB Options that we use. During the process of opening the
892 // column family, the options provided when calling DB::Open() or
893 // DB::CreateColumnFamily() will have been "sanitized" and transformed
894 // in an implementation-defined manner.
895 virtual Options GetOptions(ColumnFamilyHandle* column_family) const = 0;
896 virtual Options GetOptions() const {
897 return GetOptions(DefaultColumnFamily());
898 }
899
900 virtual DBOptions GetDBOptions() const = 0;
901
902 // Flush all mem-table data.
903 virtual Status Flush(const FlushOptions& options,
904 ColumnFamilyHandle* column_family) = 0;
905 virtual Status Flush(const FlushOptions& options) {
906 return Flush(options, DefaultColumnFamily());
907 }
908
909 // Flush the WAL memory buffer to the file. If sync is true, it calls SyncWAL
910 // afterwards.
911 virtual Status FlushWAL(bool /*sync*/) {
912 return Status::NotSupported("FlushWAL not implemented");
913 }
914 // Sync the wal. Note that Write() followed by SyncWAL() is not exactly the
915 // same as Write() with sync=true: in the latter case the changes won't be
916 // visible until the sync is done.
917 // Currently only works if allow_mmap_writes = false in Options.
918 virtual Status SyncWAL() = 0;
919
920 // The sequence number of the most recent transaction.
921 virtual SequenceNumber GetLatestSequenceNumber() const = 0;
922
923 // Instructs DB to preserve deletes with sequence numbers >= passed seqnum.
924 // Has no effect if DBOptions.preserve_deletes is set to false.
925 // This function assumes that user calls this function with monotonically
926 // increasing seqnums (otherwise we can't guarantee that a particular delete
927 // hasn't been already processed); returns true if the value was successfully
928 // updated, false if user attempted to call if with seqnum <= current value.
929 virtual bool SetPreserveDeletesSequenceNumber(SequenceNumber seqnum) = 0;
930
931 #ifndef ROCKSDB_LITE
932
933 // Prevent file deletions. Compactions will continue to occur,
934 // but no obsolete files will be deleted. Calling this multiple
935 // times have the same effect as calling it once.
936 virtual Status DisableFileDeletions() = 0;
937
938 // Allow compactions to delete obsolete files.
939 // If force == true, the call to EnableFileDeletions() will guarantee that
940 // file deletions are enabled after the call, even if DisableFileDeletions()
941 // was called multiple times before.
942 // If force == false, EnableFileDeletions will only enable file deletion
943 // after it's been called at least as many times as DisableFileDeletions(),
944 // enabling the two methods to be called by two threads concurrently without
945 // synchronization -- i.e., file deletions will be enabled only after both
946 // threads call EnableFileDeletions()
947 virtual Status EnableFileDeletions(bool force = true) = 0;
948
949 // GetLiveFiles followed by GetSortedWalFiles can generate a lossless backup
950
951 // Retrieve the list of all files in the database. The files are
952 // relative to the dbname and are not absolute paths. Despite being relative
953 // paths, the file names begin with "/". The valid size of the manifest file
954 // is returned in manifest_file_size. The manifest file is an ever growing
955 // file, but only the portion specified by manifest_file_size is valid for
956 // this snapshot. Setting flush_memtable to true does Flush before recording
957 // the live files. Setting flush_memtable to false is useful when we don't
958 // want to wait for flush which may have to wait for compaction to complete
959 // taking an indeterminate time.
960 //
961 // In case you have multiple column families, even if flush_memtable is true,
962 // you still need to call GetSortedWalFiles after GetLiveFiles to compensate
963 // for new data that arrived to already-flushed column families while other
964 // column families were flushing
965 virtual Status GetLiveFiles(std::vector<std::string>&,
966 uint64_t* manifest_file_size,
967 bool flush_memtable = true) = 0;
968
969 // Retrieve the sorted list of all wal files with earliest file first
970 virtual Status GetSortedWalFiles(VectorLogPtr& files) = 0;
971
972 // Note: this API is not yet consistent with WritePrepared transactions.
973 // Sets iter to an iterator that is positioned at a write-batch containing
974 // seq_number. If the sequence number is non existent, it returns an iterator
975 // at the first available seq_no after the requested seq_no
976 // Returns Status::OK if iterator is valid
977 // Must set WAL_ttl_seconds or WAL_size_limit_MB to large values to
978 // use this api, else the WAL files will get
979 // cleared aggressively and the iterator might keep getting invalid before
980 // an update is read.
981 virtual Status GetUpdatesSince(
982 SequenceNumber seq_number, unique_ptr<TransactionLogIterator>* iter,
983 const TransactionLogIterator::ReadOptions&
984 read_options = TransactionLogIterator::ReadOptions()) = 0;
985
986 // Windows API macro interference
987 #undef DeleteFile
988 // Delete the file name from the db directory and update the internal state to
989 // reflect that. Supports deletion of sst and log files only. 'name' must be
990 // path relative to the db directory. eg. 000001.sst, /archive/000003.log
991 virtual Status DeleteFile(std::string name) = 0;
992
993 // Returns a list of all table files with their level, start key
994 // and end key
995 virtual void GetLiveFilesMetaData(
996 std::vector<LiveFileMetaData>* /*metadata*/) {}
997
998 // Obtains the meta data of the specified column family of the DB.
999 virtual void GetColumnFamilyMetaData(ColumnFamilyHandle* /*column_family*/,
1000 ColumnFamilyMetaData* /*metadata*/) {}
1001
1002 // Get the metadata of the default column family.
1003 void GetColumnFamilyMetaData(
1004 ColumnFamilyMetaData* metadata) {
1005 GetColumnFamilyMetaData(DefaultColumnFamily(), metadata);
1006 }
1007
1008 // IngestExternalFile() will load a list of external SST files (1) into the DB
1009 // Two primary modes are supported:
1010 // - Duplicate keys in the new files will overwrite exiting keys (default)
1011 // - Duplicate keys will be skipped (set ingest_behind=true)
1012 // In the first mode we will try to find the lowest possible level that
1013 // the file can fit in, and ingest the file into this level (2). A file that
1014 // have a key range that overlap with the memtable key range will require us
1015 // to Flush the memtable first before ingesting the file.
1016 // In the second mode we will always ingest in the bottom most level (see
1017 // docs to IngestExternalFileOptions::ingest_behind).
1018 //
1019 // (1) External SST files can be created using SstFileWriter
1020 // (2) We will try to ingest the files to the lowest possible level
1021 // even if the file compression doesn't match the level compression
1022 // (3) If IngestExternalFileOptions->ingest_behind is set to true,
1023 // we always ingest at the bottommost level, which should be reserved
1024 // for this purpose (see DBOPtions::allow_ingest_behind flag).
1025 virtual Status IngestExternalFile(
1026 ColumnFamilyHandle* column_family,
1027 const std::vector<std::string>& external_files,
1028 const IngestExternalFileOptions& options) = 0;
1029
1030 virtual Status IngestExternalFile(
1031 const std::vector<std::string>& external_files,
1032 const IngestExternalFileOptions& options) {
1033 return IngestExternalFile(DefaultColumnFamily(), external_files, options);
1034 }
1035
1036 virtual Status VerifyChecksum() = 0;
1037
1038 // AddFile() is deprecated, please use IngestExternalFile()
1039 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1040 ColumnFamilyHandle* column_family,
1041 const std::vector<std::string>& file_path_list, bool move_file = false,
1042 bool skip_snapshot_check = false) {
1043 IngestExternalFileOptions ifo;
1044 ifo.move_files = move_file;
1045 ifo.snapshot_consistency = !skip_snapshot_check;
1046 ifo.allow_global_seqno = false;
1047 ifo.allow_blocking_flush = false;
1048 return IngestExternalFile(column_family, file_path_list, ifo);
1049 }
1050
1051 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1052 const std::vector<std::string>& file_path_list, bool move_file = false,
1053 bool skip_snapshot_check = false) {
1054 IngestExternalFileOptions ifo;
1055 ifo.move_files = move_file;
1056 ifo.snapshot_consistency = !skip_snapshot_check;
1057 ifo.allow_global_seqno = false;
1058 ifo.allow_blocking_flush = false;
1059 return IngestExternalFile(DefaultColumnFamily(), file_path_list, ifo);
1060 }
1061
1062 // AddFile() is deprecated, please use IngestExternalFile()
1063 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1064 ColumnFamilyHandle* column_family, const std::string& file_path,
1065 bool move_file = false, bool skip_snapshot_check = false) {
1066 IngestExternalFileOptions ifo;
1067 ifo.move_files = move_file;
1068 ifo.snapshot_consistency = !skip_snapshot_check;
1069 ifo.allow_global_seqno = false;
1070 ifo.allow_blocking_flush = false;
1071 return IngestExternalFile(column_family, {file_path}, ifo);
1072 }
1073
1074 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1075 const std::string& file_path, bool move_file = false,
1076 bool skip_snapshot_check = false) {
1077 IngestExternalFileOptions ifo;
1078 ifo.move_files = move_file;
1079 ifo.snapshot_consistency = !skip_snapshot_check;
1080 ifo.allow_global_seqno = false;
1081 ifo.allow_blocking_flush = false;
1082 return IngestExternalFile(DefaultColumnFamily(), {file_path}, ifo);
1083 }
1084
1085 // Load table file with information "file_info" into "column_family"
1086 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1087 ColumnFamilyHandle* column_family,
1088 const std::vector<ExternalSstFileInfo>& file_info_list,
1089 bool move_file = false, bool skip_snapshot_check = false) {
1090 std::vector<std::string> external_files;
1091 for (const ExternalSstFileInfo& file_info : file_info_list) {
1092 external_files.push_back(file_info.file_path);
1093 }
1094 IngestExternalFileOptions ifo;
1095 ifo.move_files = move_file;
1096 ifo.snapshot_consistency = !skip_snapshot_check;
1097 ifo.allow_global_seqno = false;
1098 ifo.allow_blocking_flush = false;
1099 return IngestExternalFile(column_family, external_files, ifo);
1100 }
1101
1102 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1103 const std::vector<ExternalSstFileInfo>& file_info_list,
1104 bool move_file = false, bool skip_snapshot_check = false) {
1105 std::vector<std::string> external_files;
1106 for (const ExternalSstFileInfo& file_info : file_info_list) {
1107 external_files.push_back(file_info.file_path);
1108 }
1109 IngestExternalFileOptions ifo;
1110 ifo.move_files = move_file;
1111 ifo.snapshot_consistency = !skip_snapshot_check;
1112 ifo.allow_global_seqno = false;
1113 ifo.allow_blocking_flush = false;
1114 return IngestExternalFile(DefaultColumnFamily(), external_files, ifo);
1115 }
1116
1117 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1118 ColumnFamilyHandle* column_family, const ExternalSstFileInfo* file_info,
1119 bool move_file = false, bool skip_snapshot_check = false) {
1120 IngestExternalFileOptions ifo;
1121 ifo.move_files = move_file;
1122 ifo.snapshot_consistency = !skip_snapshot_check;
1123 ifo.allow_global_seqno = false;
1124 ifo.allow_blocking_flush = false;
1125 return IngestExternalFile(column_family, {file_info->file_path}, ifo);
1126 }
1127
1128 ROCKSDB_DEPRECATED_FUNC virtual Status AddFile(
1129 const ExternalSstFileInfo* file_info, bool move_file = false,
1130 bool skip_snapshot_check = false) {
1131 IngestExternalFileOptions ifo;
1132 ifo.move_files = move_file;
1133 ifo.snapshot_consistency = !skip_snapshot_check;
1134 ifo.allow_global_seqno = false;
1135 ifo.allow_blocking_flush = false;
1136 return IngestExternalFile(DefaultColumnFamily(), {file_info->file_path},
1137 ifo);
1138 }
1139
1140 #endif // ROCKSDB_LITE
1141
1142 // Sets the globally unique ID created at database creation time by invoking
1143 // Env::GenerateUniqueId(), in identity. Returns Status::OK if identity could
1144 // be set properly
1145 virtual Status GetDbIdentity(std::string& identity) const = 0;
1146
1147 // Returns default column family handle
1148 virtual ColumnFamilyHandle* DefaultColumnFamily() const = 0;
1149
1150 #ifndef ROCKSDB_LITE
1151 virtual Status GetPropertiesOfAllTables(ColumnFamilyHandle* column_family,
1152 TablePropertiesCollection* props) = 0;
1153 virtual Status GetPropertiesOfAllTables(TablePropertiesCollection* props) {
1154 return GetPropertiesOfAllTables(DefaultColumnFamily(), props);
1155 }
1156 virtual Status GetPropertiesOfTablesInRange(
1157 ColumnFamilyHandle* column_family, const Range* range, std::size_t n,
1158 TablePropertiesCollection* props) = 0;
1159
1160 virtual Status SuggestCompactRange(ColumnFamilyHandle* /*column_family*/,
1161 const Slice* /*begin*/,
1162 const Slice* /*end*/) {
1163 return Status::NotSupported("SuggestCompactRange() is not implemented.");
1164 }
1165
1166 virtual Status PromoteL0(ColumnFamilyHandle* /*column_family*/,
1167 int /*target_level*/) {
1168 return Status::NotSupported("PromoteL0() is not implemented.");
1169 }
1170
1171 // Trace DB operations. Use EndTrace() to stop tracing.
1172 virtual Status StartTrace(const TraceOptions& /*options*/,
1173 std::unique_ptr<TraceWriter>&& /*trace_writer*/) {
1174 return Status::NotSupported("StartTrace() is not implemented.");
1175 }
1176
1177 virtual Status EndTrace() {
1178 return Status::NotSupported("EndTrace() is not implemented.");
1179 }
1180 #endif // ROCKSDB_LITE
1181
1182 // Needed for StackableDB
1183 virtual DB* GetRootDB() { return this; }
1184
1185 private:
1186 // No copying allowed
1187 DB(const DB&);
1188 void operator=(const DB&);
1189 };
1190
1191 // Destroy the contents of the specified database.
1192 // Be very careful using this method.
1193 Status DestroyDB(const std::string& name, const Options& options,
1194 const std::vector<ColumnFamilyDescriptor>& column_families =
1195 std::vector<ColumnFamilyDescriptor>());
1196
1197 #ifndef ROCKSDB_LITE
1198 // If a DB cannot be opened, you may attempt to call this method to
1199 // resurrect as much of the contents of the database as possible.
1200 // Some data may be lost, so be careful when calling this function
1201 // on a database that contains important information.
1202 //
1203 // With this API, we will warn and skip data associated with column families not
1204 // specified in column_families.
1205 //
1206 // @param column_families Descriptors for known column families
1207 Status RepairDB(const std::string& dbname, const DBOptions& db_options,
1208 const std::vector<ColumnFamilyDescriptor>& column_families);
1209
1210 // @param unknown_cf_opts Options for column families encountered during the
1211 // repair that were not specified in column_families.
1212 Status RepairDB(const std::string& dbname, const DBOptions& db_options,
1213 const std::vector<ColumnFamilyDescriptor>& column_families,
1214 const ColumnFamilyOptions& unknown_cf_opts);
1215
1216 // @param options These options will be used for the database and for ALL column
1217 // families encountered during the repair
1218 Status RepairDB(const std::string& dbname, const Options& options);
1219
1220 #endif
1221
1222 } // namespace rocksdb