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 struct ImmutableCFOptions;
20 class TableCache;
21 class VersionStorageInfo;
22 class VersionEdit;
23 struct FileMetaData;
24 class InternalStats;
25 class Version;
26 class VersionSet;
27 class ColumnFamilyData;
28 
29 // A helper class so we can efficiently apply a whole sequence
30 // of edits to a particular state without creating intermediate
31 // Versions that contain full copies of the intermediate state.
32 class VersionBuilder {
33  public:
34   VersionBuilder(const FileOptions& file_options,
35                  const ImmutableCFOptions* ioptions, TableCache* table_cache,
36                  VersionStorageInfo* base_vstorage, VersionSet* version_set);
37   ~VersionBuilder();
38 
39   bool CheckConsistencyForNumLevels();
40   Status Apply(VersionEdit* edit);
41   Status SaveTo(VersionStorageInfo* vstorage);
42   Status LoadTableHandlers(InternalStats* internal_stats, int max_threads,
43                            bool prefetch_index_and_filter_in_cache,
44                            bool is_initial_load,
45                            const SliceTransform* prefix_extractor,
46                            size_t max_file_size_for_l0_meta_pin);
47   uint64_t GetMinOldestBlobFileNumber() const;
48 
49  private:
50   class Rep;
51   std::unique_ptr<Rep> rep_;
52 };
53 
54 // A wrapper of version builder which references the current version in
55 // constructor and unref it in the destructor.
56 // Both of the constructor and destructor need to be called inside DB Mutex.
57 class BaseReferencedVersionBuilder {
58  public:
59   explicit BaseReferencedVersionBuilder(ColumnFamilyData* cfd);
60   BaseReferencedVersionBuilder(ColumnFamilyData* cfd, Version* v);
61   ~BaseReferencedVersionBuilder();
version_builder()62   VersionBuilder* version_builder() const { return version_builder_.get(); }
63 
64  private:
65   std::unique_ptr<VersionBuilder> version_builder_;
66   Version* version_;
67 };
68 
69 extern bool NewestFirstBySeqNo(FileMetaData* a, FileMetaData* b);
70 }  // namespace ROCKSDB_NAMESPACE
71