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).
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.
16 #include "db/dbformat.h"
17 #include "options/options_helper.h"
18 #include "options/options_parser.h"
19 #include "rocksdb/flush_block_policy.h"
20 #include "rocksdb/table.h"
26 using std::unique_ptr
;
27 class BlockBasedTableBuilder
;
29 // A class used to track actual bytes written from the tail in the recent SST
30 // file opens, and provide a suggestion for following open.
31 class TailPrefetchStats
{
33 void RecordEffectiveSize(size_t len
);
34 // 0 indicates no information to determine.
35 size_t GetSuggestedPrefetchSize();
38 const static size_t kNumTracked
= 32;
39 size_t records_
[kNumTracked
];
42 size_t num_records_
= 0;
45 class BlockBasedTableFactory
: public TableFactory
{
47 explicit BlockBasedTableFactory(
48 const BlockBasedTableOptions
& table_options
= BlockBasedTableOptions());
50 ~BlockBasedTableFactory() {}
52 const char* Name() const override
{ return kName
.c_str(); }
54 Status
NewTableReader(
55 const TableReaderOptions
& table_reader_options
,
56 unique_ptr
<RandomAccessFileReader
>&& file
, uint64_t file_size
,
57 unique_ptr
<TableReader
>* table_reader
,
58 bool prefetch_index_and_filter_in_cache
= true) const override
;
60 TableBuilder
* NewTableBuilder(
61 const TableBuilderOptions
& table_builder_options
,
62 uint32_t column_family_id
, WritableFileWriter
* file
) const override
;
64 // Sanitizes the specified DB Options.
65 Status
SanitizeOptions(const DBOptions
& db_opts
,
66 const ColumnFamilyOptions
& cf_opts
) const override
;
68 std::string
GetPrintableTableOptions() const override
;
70 Status
GetOptionString(std::string
* opt_string
,
71 const std::string
& delimiter
) const override
;
73 const BlockBasedTableOptions
& table_options() const;
75 void* GetOptions() override
{ return &table_options_
; }
77 bool IsDeleteRangeSupported() const override
{ return true; }
79 static const std::string kName
;
82 BlockBasedTableOptions table_options_
;
83 mutable TailPrefetchStats tail_prefetch_stats_
;
86 extern const std::string kHashIndexPrefixesBlock
;
87 extern const std::string kHashIndexPrefixesMetadataBlock
;
88 extern const std::string kPropTrue
;
89 extern const std::string kPropFalse
;
92 extern Status
VerifyBlockBasedTableFactory(
93 const BlockBasedTableFactory
* base_tf
,
94 const BlockBasedTableFactory
* file_tf
,
95 OptionsSanityCheckLevel sanity_check_level
);
97 static std::unordered_map
<std::string
, OptionTypeInfo
>
98 block_based_table_type_info
= {
99 /* currently not supported
100 std::shared_ptr<Cache> block_cache = nullptr;
101 std::shared_ptr<Cache> block_cache_compressed = nullptr;
103 {"flush_block_policy_factory",
104 {offsetof(struct BlockBasedTableOptions
, flush_block_policy_factory
),
105 OptionType::kFlushBlockPolicyFactory
, OptionVerificationType::kByName
,
107 {"cache_index_and_filter_blocks",
108 {offsetof(struct BlockBasedTableOptions
,
109 cache_index_and_filter_blocks
),
110 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
111 {"cache_index_and_filter_blocks_with_high_priority",
112 {offsetof(struct BlockBasedTableOptions
,
113 cache_index_and_filter_blocks_with_high_priority
),
114 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
115 {"pin_l0_filter_and_index_blocks_in_cache",
116 {offsetof(struct BlockBasedTableOptions
,
117 pin_l0_filter_and_index_blocks_in_cache
),
118 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
120 {offsetof(struct BlockBasedTableOptions
, index_type
),
121 OptionType::kBlockBasedTableIndexType
,
122 OptionVerificationType::kNormal
, false, 0}},
123 {"hash_index_allow_collision",
124 {offsetof(struct BlockBasedTableOptions
, hash_index_allow_collision
),
125 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
126 {"data_block_index_type",
127 {offsetof(struct BlockBasedTableOptions
, data_block_index_type
),
128 OptionType::kBlockBasedTableDataBlockIndexType
,
129 OptionVerificationType::kNormal
, false, 0}},
130 {"data_block_hash_table_util_ratio",
131 {offsetof(struct BlockBasedTableOptions
,
132 data_block_hash_table_util_ratio
),
133 OptionType::kDouble
, OptionVerificationType::kNormal
, false, 0}},
135 {offsetof(struct BlockBasedTableOptions
, checksum
),
136 OptionType::kChecksumType
, OptionVerificationType::kNormal
, false,
139 {offsetof(struct BlockBasedTableOptions
, no_block_cache
),
140 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
142 {offsetof(struct BlockBasedTableOptions
, block_size
),
143 OptionType::kSizeT
, OptionVerificationType::kNormal
, false, 0}},
144 {"block_size_deviation",
145 {offsetof(struct BlockBasedTableOptions
, block_size_deviation
),
146 OptionType::kInt
, OptionVerificationType::kNormal
, false, 0}},
147 {"block_restart_interval",
148 {offsetof(struct BlockBasedTableOptions
, block_restart_interval
),
149 OptionType::kInt
, OptionVerificationType::kNormal
, false, 0}},
150 {"index_block_restart_interval",
151 {offsetof(struct BlockBasedTableOptions
, index_block_restart_interval
),
152 OptionType::kInt
, OptionVerificationType::kNormal
, false, 0}},
153 {"index_per_partition",
154 {0, OptionType::kUInt64T
, OptionVerificationType::kDeprecated
, false,
156 {"metadata_block_size",
157 {offsetof(struct BlockBasedTableOptions
, metadata_block_size
),
158 OptionType::kUInt64T
, OptionVerificationType::kNormal
, false, 0}},
159 {"partition_filters",
160 {offsetof(struct BlockBasedTableOptions
, partition_filters
),
161 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
163 {offsetof(struct BlockBasedTableOptions
, filter_policy
),
164 OptionType::kFilterPolicy
, OptionVerificationType::kByName
, false,
166 {"whole_key_filtering",
167 {offsetof(struct BlockBasedTableOptions
, whole_key_filtering
),
168 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
169 {"skip_table_builder_flush",
170 {0, OptionType::kBoolean
, OptionVerificationType::kDeprecated
, false,
173 {offsetof(struct BlockBasedTableOptions
, format_version
),
174 OptionType::kUInt32T
, OptionVerificationType::kNormal
, false, 0}},
175 {"verify_compression",
176 {offsetof(struct BlockBasedTableOptions
, verify_compression
),
177 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
178 {"read_amp_bytes_per_bit",
179 {offsetof(struct BlockBasedTableOptions
, read_amp_bytes_per_bit
),
180 OptionType::kSizeT
, OptionVerificationType::kNormal
, false, 0}},
181 {"enable_index_compression",
182 {offsetof(struct BlockBasedTableOptions
, enable_index_compression
),
183 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
185 {offsetof(struct BlockBasedTableOptions
, block_align
),
186 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}},
187 {"pin_top_level_index_and_filter",
188 {offsetof(struct BlockBasedTableOptions
,
189 pin_top_level_index_and_filter
),
190 OptionType::kBoolean
, OptionVerificationType::kNormal
, false, 0}}};
191 #endif // !ROCKSDB_LITE
192 } // namespace rocksdb