• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

linxGnu / grocksdb / 6067355637

03 Sep 2023 11:32PM UTC coverage: 66.95% (+0.02%) from 66.93%
6067355637

push

github

web-flow
Adapt RocksDB 8.4.4 (#125)

3 of 3 new or added lines in 1 file covered. (100.0%)

3308 of 4941 relevant lines covered (66.95%)

0.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.21
/options_block_based_table.go
1
package grocksdb
2

3
// #include "rocksdb/c.h"
4
// #include "grocksdb.h"
5
import "C"
6

7
// IndexType specifies the index type that will be used for this table.
8
type IndexType uint
9

10
const (
11
        // KBinarySearchIndexType a space efficient index block that is optimized for
12
        // binary-search-based index.
13
        KBinarySearchIndexType IndexType = 0x00
14

15
        // KHashSearchIndexType the hash index, if enabled, will do the hash lookup when
16
        // `Options.prefix_extractor` is provided.
17
        KHashSearchIndexType IndexType = 0x01
18

19
        // KTwoLevelIndexSearchIndexType a two-level index implementation. Both levels are binary search indexes.
20
        KTwoLevelIndexSearchIndexType IndexType = 0x02
21

22
        // KBinarySearchWithFirstKey like KBinarySearchIndexType, but index also contains
23
        // first key of each block.
24
        //
25
        // This allows iterators to defer reading the block until it's actually
26
        // needed. May significantly reduce read amplification of short range scans.
27
        // Without it, iterator seek usually reads one block from each level-0 file
28
        // and from each level, which may be expensive.
29
        // Works best in combination with:
30
        //  - IndexShorteningMode::kNoShortening,
31
        //  - custom FlushBlockPolicy to cut blocks at some meaningful boundaries,
32
        //    e.g. when prefix changes.
33
        // Makes the index significantly bigger (2x or more), especially when keys
34
        // are long.
35
        //
36
        // IO errors are not handled correctly in this mode right now: if an error
37
        // happens when lazily reading a block in value(), value() returns empty
38
        // slice, and you need to call Valid()/status() afterwards.
39
        KBinarySearchWithFirstKey IndexType = 0x03
40
)
41

42
// DataBlockIndexType specifies index type that will be used for the data block.
43
type DataBlockIndexType uint
44

45
const (
46
        // KDataBlockIndexTypeBinarySearch is traditional block type
47
        KDataBlockIndexTypeBinarySearch DataBlockIndexType = 0
48
        // KDataBlockIndexTypeBinarySearchAndHash additional hash index
49
        KDataBlockIndexTypeBinarySearchAndHash DataBlockIndexType = 1
50
)
51

52
// BlockBasedTableOptions represents block-based table options.
53
type BlockBasedTableOptions struct {
54
        c *C.rocksdb_block_based_table_options_t
55

56
        // Hold references for GC.
57
        cache     *Cache
58
        compCache *Cache
59

60
        // We keep these so we can free their memory in Destroy.
61
        cFp *C.rocksdb_filterpolicy_t
62
}
63

64
// NewDefaultBlockBasedTableOptions creates a default BlockBasedTableOptions object.
65
func NewDefaultBlockBasedTableOptions() *BlockBasedTableOptions {
1✔
66
        return newNativeBlockBasedTableOptions(C.rocksdb_block_based_options_create())
1✔
67
}
1✔
68

69
// NewNativeBlockBasedTableOptions creates a BlockBasedTableOptions object.
70
func newNativeBlockBasedTableOptions(c *C.rocksdb_block_based_table_options_t) *BlockBasedTableOptions {
1✔
71
        return &BlockBasedTableOptions{c: c}
1✔
72
}
1✔
73

74
// Destroy deallocates the BlockBasedTableOptions object.
75
func (opts *BlockBasedTableOptions) Destroy() {
1✔
76
        C.rocksdb_block_based_options_destroy(opts.c)
1✔
77
        opts.c = nil
1✔
78
        opts.cache = nil
1✔
79
        opts.compCache = nil
1✔
80
}
1✔
81

82
// SetChecksum sets checksum types.
83
//
84
//        enum ChecksumType : char {
85
//          kNoChecksum = 0x0,
86
//          kCRC32c = 0x1,
87
//          kxxHash = 0x2,
88
//          kxxHash64 = 0x3,
89
//          kXXH3 = 0x4,  // Supported since RocksDB 6.27
90
//        };
91
func (opts *BlockBasedTableOptions) SetChecksum(csType int8) {
×
92
        C.rocksdb_block_based_options_set_checksum(opts.c, C.char(csType))
×
93
}
×
94

95
// SetCacheIndexAndFilterBlocks is indicating if we'd put index/filter blocks to the block cache.
96
// If not specified, each "table reader" object will pre-load index/filter
97
// block during table initialization.
98
// Default: false
99
func (opts *BlockBasedTableOptions) SetCacheIndexAndFilterBlocks(value bool) {
×
100
        C.rocksdb_block_based_options_set_cache_index_and_filter_blocks(opts.c, boolToChar(value))
×
101
}
×
102

103
// SetPinL0FilterAndIndexBlocksInCache sets cache_index_and_filter_blocks.
104
// If is true and the below is true (hash_index_allow_collision), then
105
// filter and index blocks are stored in the cache, but a reference is
106
// held in the "table reader" object so the blocks are pinned and only
107
// evicted from cache when the table reader is freed.
108
func (opts *BlockBasedTableOptions) SetPinL0FilterAndIndexBlocksInCache(value bool) {
×
109
        C.rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache(opts.c, boolToChar(value))
×
110
}
×
111

112
// SetBlockSize sets the approximate size of user data packed per block.
113
// Note that the block size specified here corresponds opts uncompressed data.
114
// The actual size of the unit read from disk may be smaller if
115
// compression is enabled. This parameter can be changed dynamically.
116
// Default: 4K
117
func (opts *BlockBasedTableOptions) SetBlockSize(blockSize int) {
1✔
118
        C.rocksdb_block_based_options_set_block_size(opts.c, C.size_t(blockSize))
1✔
119
}
1✔
120

121
// SetBlockSizeDeviation sets the block size deviation.
122
// This is used opts close a block before it reaches the configured
123
// 'block_size'. If the percentage of free space in the current block is less
124
// than this specified number and adding a new record opts the block will
125
// exceed the configured block size, then this block will be closed and the
126
// new record will be written opts the next block.
127
// Default: 10
128
func (opts *BlockBasedTableOptions) SetBlockSizeDeviation(blockSizeDeviation int) {
×
129
        C.rocksdb_block_based_options_set_block_size_deviation(opts.c, C.int(blockSizeDeviation))
×
130
}
×
131

132
// SetBlockRestartInterval sets the number of keys between
133
// restart points for delta encoding of keys.
134
// This parameter can be changed dynamically. Most clients should
135
// leave this parameter alone.
136
// Default: 16
137
func (opts *BlockBasedTableOptions) SetBlockRestartInterval(blockRestartInterval int) {
×
138
        C.rocksdb_block_based_options_set_block_restart_interval(opts.c, C.int(blockRestartInterval))
×
139
}
×
140

141
// SetFilterPolicy sets the filter policy opts reduce disk reads.
142
// Many applications will benefit from passing the result of
143
// NewBloomFilterPolicy() here.
144
//
145
// Note: this op is `move`, fp is no longer usable.
146
//
147
// Default: nil
148
func (opts *BlockBasedTableOptions) SetFilterPolicy(fp *NativeFilterPolicy) {
×
149
        opts.cFp = fp.c
×
150
        fp.c = nil
×
151
        C.rocksdb_block_based_options_set_filter_policy(opts.c, opts.cFp)
×
152
}
×
153

154
// SetNoBlockCache specify whether block cache should be used or not.
155
// Default: false
156
func (opts *BlockBasedTableOptions) SetNoBlockCache(value bool) {
×
157
        C.rocksdb_block_based_options_set_no_block_cache(opts.c, boolToChar(value))
×
158
}
×
159

160
// SetBlockCache sets the control over blocks (user data is stored in a set of blocks, and
161
// a block is the unit of reading from disk).
162
//
163
// If set, use the specified cache for blocks.
164
// If nil, rocksdb will auoptsmatically create and use an 8MB internal cache.
165
// Default: nil
166
func (opts *BlockBasedTableOptions) SetBlockCache(cache *Cache) {
1✔
167
        opts.cache = cache
1✔
168
        C.rocksdb_block_based_options_set_block_cache(opts.c, cache.c)
1✔
169
}
1✔
170

171
// SetWholeKeyFiltering specify if whole keys in the filter (not just prefixes)
172
// should be placed.
173
// This must generally be true for gets opts be efficient.
174
// Default: true
175
func (opts *BlockBasedTableOptions) SetWholeKeyFiltering(value bool) {
×
176
        C.rocksdb_block_based_options_set_whole_key_filtering(opts.c, boolToChar(value))
×
177
}
×
178

179
// SetIndexType sets the index type used for this table.
180
// kBinarySearch:
181
// A space efficient index block that is optimized for
182
// binary-search-based index.
183
//
184
// kHashSearch:
185
// The hash index, if enabled, will do the hash lookup when
186
// `Options.prefix_extractor` is provided.
187
//
188
// kTwoLevelIndexSearch:
189
// A two-level index implementation. Both levels are binary search indexes.
190
// Default: kBinarySearch
191
func (opts *BlockBasedTableOptions) SetIndexType(value IndexType) {
×
192
        C.rocksdb_block_based_options_set_index_type(opts.c, C.int(value))
×
193
}
×
194

195
// SetDataBlockIndexType sets data block index type
196
func (opts *BlockBasedTableOptions) SetDataBlockIndexType(value DataBlockIndexType) {
×
197
        C.rocksdb_block_based_options_set_data_block_index_type(opts.c, C.int(value))
×
198
}
×
199

200
// SetDataBlockHashRatio is valid only when data_block_hash_index_type is
201
// KDataBlockIndexTypeBinarySearchAndHash.
202
//
203
// Default value: 0.75
204
func (opts *BlockBasedTableOptions) SetDataBlockHashRatio(value float64) {
×
205
        C.rocksdb_block_based_options_set_data_block_hash_ratio(opts.c, C.double(value))
×
206
}
×
207

208
// SetIndexBlockRestartInterval same as block_restart_interval but used for the index block.
209
func (opts *BlockBasedTableOptions) SetIndexBlockRestartInterval(value int) {
×
210
        C.rocksdb_block_based_options_set_index_block_restart_interval(opts.c, C.int(value))
×
211
}
×
212

213
// SetMetadataBlockSize sets block size for partitioned metadata. Currently applied to indexes when
214
// kTwoLevelIndexSearch is used and to filters when partition_filters is used.
215
// Note: Since in the current implementation the filters and index partitions
216
// are aligned, an index/filter block is created when either index or filter
217
// block size reaches the specified limit.
218
// Note: this limit is currently applied to only index blocks; a filter
219
// partition is cut right after an index block is cut.
220
func (opts *BlockBasedTableOptions) SetMetadataBlockSize(value uint64) {
×
221
        C.rocksdb_block_based_options_set_metadata_block_size(opts.c, C.uint64_t(value))
×
222
}
×
223

224
// SetPartitionFilters use partitioned full filters for each SST file. This option is
225
// incompatible with block-based filters.
226
//
227
// Note: currently this option requires kTwoLevelIndexSearch to be set as
228
// well.
229
func (opts *BlockBasedTableOptions) SetPartitionFilters(value bool) {
×
230
        C.rocksdb_block_based_options_set_partition_filters(opts.c, boolToChar(value))
×
231
}
×
232

233
// SetOptimizeFiltersForMemory to generate Bloom/Ribbon filters that minimize memory
234
// internal fragmentation.
235
//
236
// When false, malloc_usable_size is not available, or format_version < 5,
237
// filters are generated without regard to internal fragmentation when
238
// loaded into memory (historical behavior). When true (and
239
// malloc_usable_size is available and format_version >= 5), then
240
// filters are generated to "round up" and "round down" their sizes to
241
// minimize internal fragmentation when loaded into memory, assuming the
242
// reading DB has the same memory allocation characteristics as the
243
// generating DB. This option does not break forward or backward
244
// compatibility.
245
//
246
// While individual filters will vary in bits/key and false positive rate
247
// when setting is true, the implementation attempts to maintain a weighted
248
// average FP rate for filters consistent with this option set to false.
249
//
250
// With Jemalloc for example, this setting is expected to save about 10% of
251
// the memory footprint and block cache charge of filters, while increasing
252
// disk usage of filters by about 1-2% due to encoding efficiency losses
253
// with variance in bits/key.
254
//
255
// NOTE: Because some memory counted by block cache might be unmapped pages
256
// within internal fragmentation, this option can increase observed RSS
257
// memory usage. With cache_index_and_filter_blocks=true, this option makes
258
// the block cache better at using space it is allowed. (These issues
259
// should not arise with partitioned filters.)
260
//
261
// NOTE: Do not set to true if you do not trust malloc_usable_size. With
262
// this option, RocksDB might access an allocated memory object beyond its
263
// original size if malloc_usable_size says it is safe to do so. While this
264
// can be considered bad practice, it should not produce undefined behavior
265
// unless malloc_usable_size is buggy or broken.
266
//
267
// Default: false
268
func (opts *BlockBasedTableOptions) SetOptimizeFiltersForMemory(value bool) {
1✔
269
        C.rocksdb_block_based_options_set_optimize_filters_for_memory(opts.c, boolToChar(value))
1✔
270
}
1✔
271

272
// SetUseDeltaEncoding uses delta encoding to compress keys in blocks.
273
// ReadOptions::pin_data requires this option to be disabled.
274
//
275
// Default: true
276
func (opts *BlockBasedTableOptions) SetUseDeltaEncoding(value bool) {
×
277
        C.rocksdb_block_based_options_set_use_delta_encoding(opts.c, boolToChar(value))
×
278
}
×
279

280
// SetFormatVersion set format version. We currently have five options:
281
// 0 -- This version is currently written out by all RocksDB's versions by
282
// default.  Can be read by really old RocksDB's. Doesn't support changing
283
// checksum (default is CRC32).
284
// 1 -- Can be read by RocksDB's versions since 3.0. Supports non-default
285
// checksum, like xxHash. It is written by RocksDB when
286
// BlockBasedTableOptions::checksum is something other than kCRC32c. (version
287
// 0 is silently upconverted)
288
// 2 -- Can be read by RocksDB's versions since 3.10. Changes the way we
289
// encode compressed blocks with LZ4, BZip2 and Zlib compression. If you
290
// don't plan to run RocksDB before version 3.10, you should probably use
291
// this.
292
// 3 -- Can be read by RocksDB's versions since 5.15. Changes the way we
293
// encode the keys in index blocks. If you don't plan to run RocksDB before
294
// version 5.15, you should probably use this.
295
// This option only affects newly written tables. When reading existing
296
// tables, the information about version is read from the footer.
297
// 4 -- Can be read by RocksDB's versions since 5.16. Changes the way we
298
// encode the values in index blocks. If you don't plan to run RocksDB before
299
// version 5.16 and you are using index_block_restart_interval > 1, you should
300
// probably use this as it would reduce the index size.
301
// This option only affects newly written tables. When reading existing
302
// tables, the information about version is read from the footer.
303
func (opts *BlockBasedTableOptions) SetFormatVersion(value int) {
×
304
        C.rocksdb_block_based_options_set_format_version(opts.c, C.int(value))
×
305
}
×
306

307
// SetCacheIndexAndFilterBlocksWithHighPriority if cache_index_and_filter_blocks is enabled,
308
// cache index and filter blocks with high priority. If set to true, depending on implementation of
309
// block cache, index and filter blocks may be less likely to be evicted
310
// than data blocks.
311
//
312
// Default: true.
313
func (opts *BlockBasedTableOptions) SetCacheIndexAndFilterBlocksWithHighPriority(value bool) {
×
314
        C.rocksdb_block_based_options_set_cache_index_and_filter_blocks_with_high_priority(opts.c, boolToChar(value))
×
315
}
×
316

317
// SetPinTopLevelIndexAndFilter if cache_index_and_filter_blocks is true and the below is true, then
318
// the top-level index of partitioned filter and index blocks are stored in
319
// the cache, but a reference is held in the "table reader" object so the
320
// blocks are pinned and only evicted from cache when the table reader is
321
// freed. This is not limited to l0 in LSM tree.
322
//
323
// Default: true.
324
func (opts *BlockBasedTableOptions) SetPinTopLevelIndexAndFilter(value bool) {
×
325
        C.rocksdb_block_based_options_set_pin_top_level_index_and_filter(opts.c, boolToChar(value))
×
326
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc