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 // 6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 // Use of this source code is governed by a BSD-style license that can be 8 // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 // 10 #pragma once 11 12 #include <memory> 13 14 #include "rocksdb/file_system.h" 15 #include "rocksdb/slice_transform.h" 16 17 namespace ROCKSDB_NAMESPACE { 18 19 class TableCache; 20 class VersionStorageInfo; 21 class VersionEdit; 22 struct FileMetaData; 23 class InternalStats; 24 class Version; 25 class ColumnFamilyData; 26 27 // A helper class so we can efficiently apply a whole sequence 28 // of edits to a particular state without creating intermediate 29 // Versions that contain full copies of the intermediate state. 30 class VersionBuilder { 31 public: 32 VersionBuilder(const FileOptions& file_options, TableCache* table_cache, 33 VersionStorageInfo* base_vstorage, Logger* info_log = nullptr); 34 ~VersionBuilder(); 35 36 bool CheckConsistencyForNumLevels(); 37 Status Apply(VersionEdit* edit); 38 Status SaveTo(VersionStorageInfo* vstorage); 39 Status LoadTableHandlers(InternalStats* internal_stats, int max_threads, 40 bool prefetch_index_and_filter_in_cache, 41 bool is_initial_load, 42 const SliceTransform* prefix_extractor); 43 44 private: 45 class Rep; 46 std::unique_ptr<Rep> rep_; 47 }; 48 49 // A wrapper of version builder which references the current version in 50 // constructor and unref it in the destructor. 51 // Both of the constructor and destructor need to be called inside DB Mutex. 52 class BaseReferencedVersionBuilder { 53 public: 54 explicit BaseReferencedVersionBuilder(ColumnFamilyData* cfd); 55 BaseReferencedVersionBuilder(ColumnFamilyData* cfd, Version* v); 56 ~BaseReferencedVersionBuilder(); version_builder()57 VersionBuilder* version_builder() const { return version_builder_.get(); } 58 59 private: 60 std::unique_ptr<VersionBuilder> version_builder_; 61 Version* version_; 62 }; 63 64 extern bool NewestFirstBySeqNo(FileMetaData* a, FileMetaData* b); 65 } // namespace ROCKSDB_NAMESPACE 66