db_impl.h 20.8 KB
Newer Older
1 2 3 4 5
//  Copyright (c) 2013, Facebook, Inc.  All rights reserved.
//  This source code is licensed under the BSD-style license found in the
//  LICENSE file in the root directory of this source tree. An additional grant
//  of patent rights can be found in the PATENTS file in the same directory.
//
J
jorlow@chromium.org 已提交
6 7 8
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
#pragma once
K
Kai Liu 已提交
10

H
Haobo Xu 已提交
11
#include <atomic>
12
#include <deque>
J
jorlow@chromium.org 已提交
13
#include <set>
T
Tomislav Novak 已提交
14
#include <utility>
15
#include <vector>
K
kailiu 已提交
16

J
jorlow@chromium.org 已提交
17 18 19
#include "db/dbformat.h"
#include "db/log_writer.h"
#include "db/snapshot.h"
20
#include "db/version_edit.h"
K
Kai Liu 已提交
21 22
#include "memtable_list.h"
#include "port/port.h"
23 24 25 26
#include "rocksdb/db.h"
#include "rocksdb/env.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/transaction_log.h"
K
Kai Liu 已提交
27
#include "util/autovector.h"
28
#include "util/stats_logger.h"
29
#include "util/thread_local.h"
I
Igor Canadi 已提交
30
#include "db/internal_stats.h"
31

32
namespace rocksdb {
J
jorlow@chromium.org 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46

class MemTable;
class TableCache;
class Version;
class VersionEdit;
class VersionSet;

class DBImpl : public DB {
 public:
  DBImpl(const Options& options, const std::string& dbname);
  virtual ~DBImpl();

  // Implementations of the DB interface
  virtual Status Put(const WriteOptions&, const Slice& key, const Slice& value);
47 48
  virtual Status Merge(const WriteOptions&, const Slice& key,
                       const Slice& value);
J
jorlow@chromium.org 已提交
49 50 51 52 53
  virtual Status Delete(const WriteOptions&, const Slice& key);
  virtual Status Write(const WriteOptions& options, WriteBatch* updates);
  virtual Status Get(const ReadOptions& options,
                     const Slice& key,
                     std::string* value);
54 55 56
  virtual std::vector<Status> MultiGet(const ReadOptions& options,
                                       const std::vector<Slice>& keys,
                                       std::vector<std::string>* values);
57

58 59 60 61 62 63 64 65
  // Returns false if key doesn't exist in the database and true if it may.
  // If value_found is not passed in as null, then return the value if found in
  // memory. On return, if value was found, then value_found will be set to true
  // , otherwise false.
  virtual bool KeyMayExist(const ReadOptions& options,
                           const Slice& key,
                           std::string* value,
                           bool* value_found = nullptr);
J
jorlow@chromium.org 已提交
66 67 68
  virtual Iterator* NewIterator(const ReadOptions&);
  virtual const Snapshot* GetSnapshot();
  virtual void ReleaseSnapshot(const Snapshot* snapshot);
69
  virtual bool GetProperty(const Slice& property, std::string* value);
J
jorlow@chromium.org 已提交
70
  virtual void GetApproximateSizes(const Range* range, int n, uint64_t* sizes);
L
Lei Jin 已提交
71 72
  virtual Status CompactRange(const Slice* begin, const Slice* end,
                              bool reduce_level = false, int target_level = -1);
73 74 75
  virtual int NumberLevels();
  virtual int MaxMemCompactionLevel();
  virtual int Level0StopWriteTrigger();
I
Igor Canadi 已提交
76
  virtual const std::string& GetName() const;
77
  virtual Env* GetEnv() const;
I
Igor Canadi 已提交
78
  virtual const Options& GetOptions() const;
H
heyongqiang 已提交
79
  virtual Status Flush(const FlushOptions& options);
80
  virtual Status DisableFileDeletions();
81
  virtual Status EnableFileDeletions(bool force);
I
Igor Canadi 已提交
82
  // All the returned filenames start with "/"
83
  virtual Status GetLiveFiles(std::vector<std::string>&,
84 85
                              uint64_t* manifest_file_size,
                              bool flush_memtable = true);
86
  virtual Status GetSortedWalFiles(VectorLogPtr& files);
87
  virtual SequenceNumber GetLatestSequenceNumber() const;
88
  virtual Status GetUpdatesSince(SequenceNumber seq_number,
89
                                 unique_ptr<TransactionLogIterator>* iter);
90 91 92 93
  virtual Status DeleteFile(std::string name);

  virtual void GetLiveFilesMetaData(
    std::vector<LiveFileMetaData> *metadata);
94

95 96
  virtual Status GetDbIdentity(std::string& identity);

L
Lei Jin 已提交
97 98 99 100
  Status RunManualCompaction(int input_level,
                             int output_level,
                             const Slice* begin,
                             const Slice* end);
101

J
jorlow@chromium.org 已提交
102 103
  // Extra methods (for testing) that are not in the public DB interface

104
  // Compact any files in the named level that overlap [*begin, *end]
L
Lei Jin 已提交
105 106 107
  Status TEST_CompactRange(int level,
                           const Slice* begin,
                           const Slice* end);
J
jorlow@chromium.org 已提交
108

109 110
  // Force current memtable contents to be flushed.
  Status TEST_FlushMemTable();
J
jorlow@chromium.org 已提交
111

112
  // Wait for memtable compaction
113
  Status TEST_WaitForFlushMemTable();
114 115 116 117

  // Wait for any compaction
  Status TEST_WaitForCompact();

J
jorlow@chromium.org 已提交
118 119 120 121 122
  // Return an internal iterator over the current state of the database.
  // The keys of this iterator are internal keys (see format.h).
  // The returned iterator should be deleted when no longer needed.
  Iterator* TEST_NewInternalIterator();

123 124
  // Return the maximum overlapping data (in bytes) at next level for any
  // file at a level >= 1.
J
jorlow@chromium.org 已提交
125
  int64_t TEST_MaxNextLevelOverlappingBytes();
126

127 128 129
  // Simulate a db crash, no elegant closing of database.
  void TEST_Destroy_DBImpl();

A
Abhishek Kona 已提交
130 131
  // Return the current manifest file no.
  uint64_t TEST_Current_Manifest_FileNo();
132 133 134 135

  // Trigger's a background call for testing.
  void TEST_PurgeObsoleteteWAL();

136
  // get total level0 file size. Only for testing.
137
  uint64_t TEST_GetLevel0TotalSize();
138

139 140 141 142 143
  void TEST_SetDefaultTimeToCheck(uint64_t default_interval_to_delete_obsolete_WAL)
  {
    default_interval_to_delete_obsolete_WAL_ = default_interval_to_delete_obsolete_WAL;
  }

144 145
  void TEST_GetFilesMetaData(std::vector<std::vector<FileMetaData>>* metadata);

I
Igor Canadi 已提交
146 147 148
  // holds references to memtable, all immutable memtables and version
  struct SuperVersion {
    MemTable* mem;
I
Igor Canadi 已提交
149
    MemTableListVersion* imm;
I
Igor Canadi 已提交
150 151
    Version* current;
    std::atomic<uint32_t> refs;
I
Igor Canadi 已提交
152
    // We need to_delete because during Cleanup(), imm->Unref() returns
I
Igor Canadi 已提交
153 154
    // all memtables that we need to free through this vector. We then
    // delete all those memtables outside of mutex, during destruction
K
Kai Liu 已提交
155
    autovector<MemTable*> to_delete;
156 157 158
    // Version number of the current SuperVersion
    uint64_t version_number;
    DBImpl* db;
I
Igor Canadi 已提交
159 160

    // should be called outside the mutex
K
Kai Liu 已提交
161
    SuperVersion() = default;
I
Igor Canadi 已提交
162 163 164 165 166 167 168 169 170 171 172
    ~SuperVersion();
    SuperVersion* Ref();
    // Returns true if this was the last reference and caller should
    // call Clenaup() and delete the object
    bool Unref();

    // call these two methods with db mutex held
    // Cleanup unrefs mem, imm and current. Also, it stores all memtables
    // that needs to be deleted in to_delete vector. Unrefing those
    // objects needs to be done in the mutex
    void Cleanup();
I
Igor Canadi 已提交
173
    void Init(MemTable* new_mem, MemTableListVersion* new_imm,
I
Igor Canadi 已提交
174 175
              Version* new_current);
  };
I
Igor Canadi 已提交
176

177 178 179 180 181 182 183 184 185 186
  static void SuperVersionUnrefHandle(void* ptr) {
    DBImpl::SuperVersion* sv = static_cast<DBImpl::SuperVersion*>(ptr);
    if (sv->Unref()) {
      sv->db->mutex_.Lock();
      sv->Cleanup();
      sv->db->mutex_.Unlock();
      delete sv;
    }
  }

I
Igor Canadi 已提交
187
  // needed for CleanupIteratorState
I
Igor Canadi 已提交
188 189
  struct DeletionState {
    inline bool HaveSomethingToDelete() const {
K
kailiu 已提交
190
      return  candidate_files.size() ||
I
Igor Canadi 已提交
191 192 193
        sst_delete_files.size() ||
        log_delete_files.size();
    }
194

I
Igor Canadi 已提交
195 196 197
    // a list of all files that we'll consider deleting
    // (every once in a while this is filled up with all files
    // in the DB directory)
K
kailiu 已提交
198
    std::vector<std::string> candidate_files;
I
Igor Canadi 已提交
199 200 201 202 203 204 205 206 207 208

    // the list of all live sst files that cannot be deleted
    std::vector<uint64_t> sst_live;

    // a list of sst files that we need to delete
    std::vector<FileMetaData*> sst_delete_files;

    // a list of log files that we need to delete
    std::vector<uint64_t> log_delete_files;

209
    // a list of memtables to be free
K
Kai Liu 已提交
210
    autovector<MemTable*> memtables_to_free;
211

212
    autovector<SuperVersion*> superversions_to_free;
I
Igor Canadi 已提交
213 214 215

    SuperVersion* new_superversion; // if nullptr no new superversion

I
Igor Canadi 已提交
216 217 218 219
    // the current manifest_file_number, log_number and prev_log_number
    // that corresponds to the set of files in 'live'.
    uint64_t manifest_file_number, log_number, prev_log_number;

K
Kai Liu 已提交
220
    explicit DeletionState(bool create_superversion = false) {
I
Igor Canadi 已提交
221 222 223
      manifest_file_number = 0;
      log_number = 0;
      prev_log_number = 0;
I
Igor Canadi 已提交
224
      new_superversion =
K
Kai Liu 已提交
225
          create_superversion ? new SuperVersion() : nullptr;
I
Igor Canadi 已提交
226 227 228 229 230 231 232
    }

    ~DeletionState() {
      // free pending memtables
      for (auto m : memtables_to_free) {
        delete m;
      }
233 234 235 236
      // free superversions
      for (auto s : superversions_to_free) {
        delete s;
      }
I
Igor Canadi 已提交
237 238 239
      // if new_superversion was not used, it will be non-nullptr and needs
      // to be freed here
      delete new_superversion;
I
Igor Canadi 已提交
240 241 242 243
    }
  };

  // Returns the list of live files in 'live' and the list
K
kailiu 已提交
244
  // of all files in the filesystem in 'candidate_files'.
I
Igor Canadi 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257
  // If force == false and the last call was less than
  // options_.delete_obsolete_files_period_micros microseconds ago,
  // it will not fill up the deletion_state
  void FindObsoleteFiles(DeletionState& deletion_state,
                         bool force,
                         bool no_full_scan = false);

  // Diffs the files listed in filenames and those that do not
  // belong to live files are posibly removed. Also, removes all the
  // files in sst_delete_files and log_delete_files.
  // It is not necessary to hold the mutex when invoking this method.
  void PurgeObsoleteFiles(DeletionState& deletion_state);

258
 protected:
H
heyongqiang 已提交
259 260
  Env* const env_;
  const std::string dbname_;
261
  unique_ptr<VersionSet> versions_;
H
heyongqiang 已提交
262 263 264 265 266 267
  const InternalKeyComparator internal_comparator_;
  const Options options_;  // options_.comparator == &internal_comparator_

  const Comparator* user_comparator() const {
    return internal_comparator_.user_comparator();
  }
268

269 270
  SuperVersion* GetSuperVersion() {
    return super_version_;
A
Abhishek Kona 已提交
271
  }
H
heyongqiang 已提交
272

273 274 275
  Iterator* NewInternalIterator(const ReadOptions&,
                                SequenceNumber* latest_snapshot);

J
jorlow@chromium.org 已提交
276 277
 private:
  friend class DB;
T
Tomislav Novak 已提交
278
  friend class TailingIterator;
279 280
  struct CompactionState;
  struct Writer;
J
jorlow@chromium.org 已提交
281 282 283 284

  Status NewDB();

  // Recover the descriptor from persistent storage.  May do a significant
I
Igor Canadi 已提交
285 286
  // amount of work to recover recently logged updates.
  Status Recover(bool read_only = false, bool error_if_log_file_exist = false);
J
jorlow@chromium.org 已提交
287 288 289

  void MaybeIgnoreError(Status* s) const;

290 291
  const Status CreateArchivalDirectory();

J
jorlow@chromium.org 已提交
292 293 294
  // Delete any unneeded files and stale in-memory entries.
  void DeleteObsoleteFiles();

295
  // Flush the in-memory write buffer to storage.  Switches to a new
J
jorlow@chromium.org 已提交
296
  // log-file/memtable and writes a new descriptor iff successful.
I
Igor Canadi 已提交
297 298
  Status FlushMemTableToOutputFile(bool* madeProgress,
                                   DeletionState& deletion_state);
J
jorlow@chromium.org 已提交
299

I
Igor Canadi 已提交
300 301
  Status RecoverLogFile(uint64_t log_number, SequenceNumber* max_sequence,
                        bool read_only);
J
jorlow@chromium.org 已提交
302

303 304 305 306 307 308
  // The following two methods are used to flush a memtable to
  // storage. The first one is used atdatabase RecoveryTime (when the
  // database is opened) and is heavyweight because it holds the mutex
  // for the entire period. The second method WriteLevel0Table supports
  // concurrent flush memtables to storage.
  Status WriteLevel0TableForRecovery(MemTable* mem, VersionEdit* edit);
K
Kai Liu 已提交
309
  Status WriteLevel0Table(autovector<MemTable*>& mems, VersionEdit* edit,
310
                                uint64_t* filenumber);
J
jorlow@chromium.org 已提交
311

M
Mark Callaghan 已提交
312
  uint64_t SlowdownAmount(int n, double bottom, double top);
I
Igor Canadi 已提交
313 314 315 316 317
  // MakeRoomForWrite will return superversion_to_free through an arugment,
  // which the caller needs to delete. We do it because caller can delete
  // the superversion outside of mutex
  Status MakeRoomForWrite(bool force /* compact even if there is room? */,
                          SuperVersion** superversion_to_free);
318 319
  void BuildBatchGroup(Writer** last_writer,
                       autovector<WriteBatch*>* write_batch_group);
J
jorlow@chromium.org 已提交
320

H
heyongqiang 已提交
321 322 323
  // Force current memtable contents to be flushed.
  Status FlushMemTable(const FlushOptions& options);

324 325
  // Wait for memtable flushed
  Status WaitForFlushMemTable();
H
heyongqiang 已提交
326

327
  void MaybeScheduleLogDBDeployStats();
328 329
  static void BGLogDBDeployStats(void* db);
  void LogDBDeployStats();
330

331
  void MaybeScheduleFlushOrCompaction();
332 333 334 335
  static void BGWorkCompaction(void* db);
  static void BGWorkFlush(void* db);
  void BackgroundCallCompaction();
  void BackgroundCallFlush();
336
  Status BackgroundCompaction(bool* madeProgress,DeletionState& deletion_state);
I
Igor Canadi 已提交
337
  Status BackgroundFlush(bool* madeProgress, DeletionState& deletion_state);
338
  void CleanupCompaction(CompactionState* compact, Status status);
I
Igor Canadi 已提交
339 340
  Status DoCompactionWork(CompactionState* compact,
                          DeletionState& deletion_state);
J
jorlow@chromium.org 已提交
341 342 343 344

  Status OpenCompactionOutputFile(CompactionState* compact);
  Status FinishCompactionOutputFile(CompactionState* compact, Iterator* input);
  Status InstallCompactionResults(CompactionState* compact);
345 346
  void AllocateCompactionOutputFileNumbers(CompactionState* compact);
  void ReleaseCompactionUnusedFileNumbers(CompactionState* compact);
A
Abhishek Kona 已提交
347

348
  void PurgeObsoleteWALFiles();
349

350 351 352
  Status AppendSortedWalsOfType(const std::string& path,
                                VectorLogPtr& log_files,
                                WalFileType type);
353

354 355 356 357 358
  // Requires: all_logs should be sorted with earliest log file first
  // Retains all log files in all_logs which contain updates with seq no.
  // Greater Than or Equal to the requested SequenceNumber.
  Status RetainProbableWalFiles(VectorLogPtr& all_logs,
                                const SequenceNumber target);
359
  //  return true if
360 361
  bool CheckWalFileExistsAndEmpty(const WalFileType type,
                                  const uint64_t number);
362

363 364
  Status ReadFirstRecord(const WalFileType type, const uint64_t number,
                         WriteBatch* const result);
365 366

  Status ReadFirstLine(const std::string& fname, WriteBatch* const batch);
367

368 369
  void PrintStatistics();

370
  // dump rocksdb.stats to LOG
371 372
  void MaybeDumpStats();

373 374 375 376
  // Return the minimum empty level that could hold the total data in the
  // input level. Return the input level, if such level could not be found.
  int FindMinimumEmptyLevelFitting(int level);

377 378 379
  // Move the files in the input level to the target level.
  // If target_level < 0, automatically calculate the minimum level that could
  // hold the data set.
L
Lei Jin 已提交
380
  Status ReFitLevel(int level, int target_level = -1);
381

T
Tomislav Novak 已提交
382 383 384 385 386 387 388 389 390 391
  // Returns the current SuperVersion number.
  uint64_t CurrentVersionNumber() const;

  // Returns a pair of iterators (mutable-only and immutable-only) used
  // internally by TailingIterator and stores CurrentVersionNumber() in
  // *superversion_number. These iterators are always up-to-date, i.e. can
  // be used to read new data.
  std::pair<Iterator*, Iterator*> GetTailingIteratorPair(
    const ReadOptions& options,
    uint64_t* superversion_number);
392

J
jorlow@chromium.org 已提交
393
  // Constant after construction
S
Sanjay Ghemawat 已提交
394
  const InternalFilterPolicy internal_filter_policy_;
J
jorlow@chromium.org 已提交
395 396 397
  bool owns_info_log_;

  // table_cache_ provides its own synchronization
398
  unique_ptr<TableCache> table_cache_;
J
jorlow@chromium.org 已提交
399

400
  // Lock over the persistent DB state.  Non-nullptr iff successfully acquired.
J
jorlow@chromium.org 已提交
401 402 403 404 405
  FileLock* db_lock_;

  // State below is protected by mutex_
  port::Mutex mutex_;
  port::AtomicPointer shutting_down_;
H
hans@chromium.org 已提交
406
  port::CondVar bg_cv_;          // Signalled when background work finishes
J
jorlow@chromium.org 已提交
407
  MemTable* mem_;
408
  MemTableList imm_;             // Memtable that are not changing
409
  uint64_t logfile_number_;
410
  unique_ptr<log::Writer> log_;
411

I
Igor Canadi 已提交
412 413
  SuperVersion* super_version_;

T
Tomislav Novak 已提交
414 415 416 417
  // An ordinal representing the current SuperVersion. Updated by
  // InstallSuperVersion(), i.e. incremented every time super_version_
  // changes.
  std::atomic<uint64_t> super_version_number_;
418 419 420
  // Thread's local copy of SuperVersion pointer
  // This needs to be destructed after mutex_
  ThreadLocalPtr* local_sv_;
T
Tomislav Novak 已提交
421

422 423
  std::string host_name_;

424 425
  std::unique_ptr<Directory> db_directory_;

426 427
  // Queue of writers.
  std::deque<Writer*> writers_;
428
  WriteBatch tmp_batch_;
429

J
jorlow@chromium.org 已提交
430 431 432 433 434 435
  SnapshotList snapshots_;

  // Set of table files to protect from deletion because they are
  // part of ongoing compactions.
  std::set<uint64_t> pending_outputs_;

436
  // count how many background compactions are running or have been scheduled
437
  int bg_compaction_scheduled_;
J
jorlow@chromium.org 已提交
438

439 440 441 442 443
  // If non-zero, MaybeScheduleFlushOrCompaction() will only schedule manual
  // compactions (if manual_compaction_ is not null). This mechanism enables
  // manual compactions to wait until all other compactions are finished.
  int bg_manual_only_;

444 445 446
  // number of background memtable flush jobs, submitted to the HIGH pool
  int bg_flush_scheduled_;

447 448 449
  // Has a background stats log thread scheduled?
  bool bg_logstats_scheduled_;

H
hans@chromium.org 已提交
450 451
  // Information for a manual compaction
  struct ManualCompaction {
452 453
    int input_level;
    int output_level;
G
Gabor Cselle 已提交
454
    bool done;
L
Lei Jin 已提交
455
    Status status;
456
    bool in_progress;           // compaction request being processed?
457 458
    const InternalKey* begin;   // nullptr means beginning of key range
    const InternalKey* end;     // nullptr means end of key range
G
Gabor Cselle 已提交
459
    InternalKey tmp_storage;    // Used to keep track of compaction progress
H
hans@chromium.org 已提交
460 461
  };
  ManualCompaction* manual_compaction_;
J
jorlow@chromium.org 已提交
462 463 464 465

  // Have we encountered a background error in paranoid mode?
  Status bg_error_;

466
  std::unique_ptr<StatsLogger> logger_;
467

468
  int64_t volatile last_log_ts;
469

470
  // shall we disable deletion of obsolete files
471 472 473 474 475 476
  // if 0 the deletion is enabled.
  // if non-zero, files will not be getting deleted
  // This enables two different threads to call
  // EnableFileDeletions() and DisableFileDeletions()
  // without any synchronization
  int disable_delete_obsolete_files_;
477

478 479 480
  // last time when DeleteObsoleteFiles was invoked
  uint64_t delete_obsolete_files_last_run_;

481 482 483
  // last time when PurgeObsoleteWALFiles ran.
  uint64_t purge_wal_files_last_run_;

484
  // last time stats were dumped to LOG
H
Haobo Xu 已提交
485
  std::atomic<uint64_t> last_stats_dump_time_microsec_;
486

487 488 489 490
  // obsolete files will be deleted every this seconds if ttl deletion is
  // enabled and archive size_limit is disabled.
  uint64_t default_interval_to_delete_obsolete_WAL_;

491 492
  bool flush_on_destroy_; // Used when disableWAL is true.

I
Igor Canadi 已提交
493
  InternalStats internal_stats_;
494

H
heyongqiang 已提交
495
  static const int KEEP_LOG_FILE_NUM = 1000;
H
heyongqiang 已提交
496
  std::string db_absolute_path_;
H
heyongqiang 已提交
497

498 499 500
  // count of the number of contiguous delaying writes
  int delayed_writes_;

501
  // The options to access storage files
H
Haobo Xu 已提交
502
  const EnvOptions storage_options_;
503

504 505 506 507 508 509
  // A value of true temporarily disables scheduling of background work
  bool bg_work_gate_closed_;

  // Guard against multiple concurrent refitting
  bool refitting_level_;

510 511 512
  // Indicate DB was opened successfully
  bool opened_successfully_;

J
jorlow@chromium.org 已提交
513 514 515 516
  // No copying allowed
  DBImpl(const DBImpl&);
  void operator=(const DBImpl&);

517 518
  // dump the delayed_writes_ to the log file and reset counter.
  void DelayLoggingAndReset();
519

520 521 522 523 524 525
  // Return the earliest snapshot where seqno is visible.
  // Store the snapshot right before that, if any, in prev_snapshot
  inline SequenceNumber findEarliestVisibleSnapshot(
    SequenceNumber in,
    std::vector<SequenceNumber>& snapshots,
    SequenceNumber* prev_snapshot);
526

I
Igor Canadi 已提交
527 528 529 530 531 532 533 534 535 536 537 538
  // will return a pointer to SuperVersion* if previous SuperVersion
  // if its reference count is zero and needs deletion or nullptr if not
  // As argument takes a pointer to allocated SuperVersion
  // Foreground threads call this function directly (they don't carry
  // deletion state and have to handle their own creation and deletion
  // of SuperVersion)
  SuperVersion* InstallSuperVersion(SuperVersion* new_superversion);
  // Background threads call this function, which is just a wrapper around
  // the InstallSuperVersion() function above. Background threads carry
  // deletion_state which can have new_superversion already allocated.
  void InstallSuperVersion(DeletionState& deletion_state);

539 540
  void ResetThreadLocalSuperVersions(DeletionState* deletion_state);

541 542 543
  virtual Status GetPropertiesOfAllTables(TablePropertiesCollection* props)
      override;

544 545
  // Function that Get and KeyMayExist call with no_io true or false
  // Note: 'value_found' from KeyMayExist propagates here
546 547 548
  Status GetImpl(const ReadOptions& options,
                 const Slice& key,
                 std::string* value,
549
                 bool* value_found = nullptr);
J
jorlow@chromium.org 已提交
550 551 552 553 554 555
};

// Sanitize db options.  The caller should delete result.info_log if
// it is not equal to src.info_log.
extern Options SanitizeOptions(const std::string& db,
                               const InternalKeyComparator* icmp,
S
Sanjay Ghemawat 已提交
556
                               const InternalFilterPolicy* ipolicy,
J
jorlow@chromium.org 已提交
557 558
                               const Options& src);

S
Siying Dong 已提交
559 560 561 562 563 564 565 566 567

// Determine compression type, based on user options, level of the output
// file and whether compression is disabled.
// If enable_compression is false, then compression is always disabled no
// matter what the values of the other two parameters are.
// Otherwise, the compression type is determined based on options and level.
CompressionType GetCompressionType(const Options& options, int level,
                                   const bool enable_compression);

568 569 570
// Determine compression type for L0 file written by memtable flush.
CompressionType GetCompressionFlush(const Options& options);

571
}  // namespace rocksdb