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

linxGnu / grocksdb / 4228812372

pending completion
4228812372

push

github

GitHub
Adapt rocksdb 7.9.2 (#102)

3164 of 4872 relevant lines covered (64.94%)

0.67 hits per line

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

12.66
/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() {
×
76
        C.rocksdb_block_based_options_destroy(opts.c)
×
77
        opts.c = nil
×
78
        opts.cache = nil
×
79
        opts.compCache = nil
×
80
}
×
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) {
×
118
        C.rocksdb_block_based_options_set_block_size(opts.c, C.size_t(blockSize))
×
119
}
×
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
// SetBlockCacheCompressed sets the cache for compressed blocks.
172
// If nil, rocksdb will not use a compressed block cache.
173
// Default: nil
174
func (opts *BlockBasedTableOptions) SetBlockCacheCompressed(cache *Cache) {
×
175
        opts.compCache = cache
×
176
        C.rocksdb_block_based_options_set_block_cache_compressed(opts.c, cache.c)
×
177
}
×
178

179
// SetWholeKeyFiltering specify if whole keys in the filter (not just prefixes)
180
// should be placed.
181
// This must generally be true for gets opts be efficient.
182
// Default: true
183
func (opts *BlockBasedTableOptions) SetWholeKeyFiltering(value bool) {
×
184
        C.rocksdb_block_based_options_set_whole_key_filtering(opts.c, boolToChar(value))
×
185
}
×
186

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

203
// SetDataBlockIndexType sets data block index type
204
func (opts *BlockBasedTableOptions) SetDataBlockIndexType(value DataBlockIndexType) {
×
205
        C.rocksdb_block_based_options_set_data_block_index_type(opts.c, C.int(value))
×
206
}
×
207

208
// SetDataBlockHashRatio is valid only when data_block_hash_index_type is
209
// KDataBlockIndexTypeBinarySearchAndHash.
210
//
211
// Default value: 0.75
212
func (opts *BlockBasedTableOptions) SetDataBlockHashRatio(value float64) {
×
213
        C.rocksdb_block_based_options_set_data_block_hash_ratio(opts.c, C.double(value))
×
214
}
×
215

216
// SetIndexBlockRestartInterval same as block_restart_interval but used for the index block.
217
func (opts *BlockBasedTableOptions) SetIndexBlockRestartInterval(value int) {
×
218
        C.rocksdb_block_based_options_set_index_block_restart_interval(opts.c, C.int(value))
×
219
}
×
220

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

232
// SetPartitionFilters use partitioned full filters for each SST file. This option is
233
// incompatible with block-based filters.
234
//
235
// Note: currently this option requires kTwoLevelIndexSearch to be set as
236
// well.
237
func (opts *BlockBasedTableOptions) SetPartitionFilters(value bool) {
×
238
        C.rocksdb_block_based_options_set_partition_filters(opts.c, boolToChar(value))
×
239
}
×
240

241
// SetUseDeltaEncoding uses delta encoding to compress keys in blocks.
242
// ReadOptions::pin_data requires this option to be disabled.
243
//
244
// Default: true
245
func (opts *BlockBasedTableOptions) SetUseDeltaEncoding(value bool) {
×
246
        C.rocksdb_block_based_options_set_use_delta_encoding(opts.c, boolToChar(value))
×
247
}
×
248

249
// SetFormatVersion set format version. We currently have five options:
250
// 0 -- This version is currently written out by all RocksDB's versions by
251
// default.  Can be read by really old RocksDB's. Doesn't support changing
252
// checksum (default is CRC32).
253
// 1 -- Can be read by RocksDB's versions since 3.0. Supports non-default
254
// checksum, like xxHash. It is written by RocksDB when
255
// BlockBasedTableOptions::checksum is something other than kCRC32c. (version
256
// 0 is silently upconverted)
257
// 2 -- Can be read by RocksDB's versions since 3.10. Changes the way we
258
// encode compressed blocks with LZ4, BZip2 and Zlib compression. If you
259
// don't plan to run RocksDB before version 3.10, you should probably use
260
// this.
261
// 3 -- Can be read by RocksDB's versions since 5.15. Changes the way we
262
// encode the keys in index blocks. If you don't plan to run RocksDB before
263
// version 5.15, you should probably use this.
264
// This option only affects newly written tables. When reading existing
265
// tables, the information about version is read from the footer.
266
// 4 -- Can be read by RocksDB's versions since 5.16. Changes the way we
267
// encode the values in index blocks. If you don't plan to run RocksDB before
268
// version 5.16 and you are using index_block_restart_interval > 1, you should
269
// probably use this as it would reduce the index size.
270
// This option only affects newly written tables. When reading existing
271
// tables, the information about version is read from the footer.
272
func (opts *BlockBasedTableOptions) SetFormatVersion(value int) {
×
273
        C.rocksdb_block_based_options_set_format_version(opts.c, C.int(value))
×
274
}
×
275

276
// SetCacheIndexAndFilterBlocksWithHighPriority if cache_index_and_filter_blocks is enabled,
277
// cache index and filter blocks with high priority. If set to true, depending on implementation of
278
// block cache, index and filter blocks may be less likely to be evicted
279
// than data blocks.
280
//
281
// Default: true.
282
func (opts *BlockBasedTableOptions) SetCacheIndexAndFilterBlocksWithHighPriority(value bool) {
×
283
        C.rocksdb_block_based_options_set_cache_index_and_filter_blocks_with_high_priority(opts.c, boolToChar(value))
×
284
}
×
285

286
// SetPinTopLevelIndexAndFilter if cache_index_and_filter_blocks is true and the below is true, then
287
// the top-level index of partitioned filter and index blocks are stored in
288
// the cache, but a reference is held in the "table reader" object so the
289
// blocks are pinned and only evicted from cache when the table reader is
290
// freed. This is not limited to l0 in LSM tree.
291
//
292
// Default: true.
293
func (opts *BlockBasedTableOptions) SetPinTopLevelIndexAndFilter(value bool) {
×
294
        C.rocksdb_block_based_options_set_pin_top_level_index_and_filter(opts.c, boolToChar(value))
×
295
}
×
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