Line data Source code
1 : // Copyright 2011 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package base 6 : 7 : // SSTable block defaults. 8 : const ( 9 : DefaultBlockRestartInterval = 16 10 : DefaultBlockSize = 4096 11 : DefaultBlockSizeThreshold = 90 12 : SizeClassAwareBlockSizeThreshold = 60 13 : ) 14 : 15 : // FilterType is the level at which to apply a filter: block or table. 16 : type FilterType int 17 : 18 : // The available filter types. 19 : const ( 20 : TableFilter FilterType = iota 21 : ) 22 : 23 2 : func (t FilterType) String() string { 24 2 : switch t { 25 2 : case TableFilter: 26 2 : return "table" 27 : } 28 0 : return "unknown" 29 : } 30 : 31 : // FilterWriter provides an interface for creating filter blocks. See 32 : // FilterPolicy for more details about filters. 33 : type FilterWriter interface { 34 : // AddKey adds a key to the current filter block. 35 : AddKey(key []byte) 36 : 37 : // Finish appends to dst an encoded filter tha holds the current set of 38 : // keys. The writer state is reset after the call to Finish allowing the 39 : // writer to be reused for the creation of additional filters. 40 : Finish(dst []byte) []byte 41 : } 42 : 43 : // FilterPolicy is an algorithm for probabilistically encoding a set of keys. 44 : // The canonical implementation is a Bloom filter. 45 : // 46 : // Every FilterPolicy has a name. This names the algorithm itself, not any one 47 : // particular instance. Aspects specific to a particular instance, such as the 48 : // set of keys or any other parameters, will be encoded in the []byte filter 49 : // returned by NewWriter. 50 : // 51 : // The name may be written to files on disk, along with the filter data. To use 52 : // these filters, the FilterPolicy name at the time of writing must equal the 53 : // name at the time of reading. If they do not match, the filters will be 54 : // ignored, which will not affect correctness but may affect performance. 55 : type FilterPolicy interface { 56 : // Name names the filter policy. 57 : Name() string 58 : 59 : // MayContain returns whether the encoded filter may contain given key. 60 : // False positives are possible, where it returns true for keys not in the 61 : // original set. 62 : MayContain(ftype FilterType, filter, key []byte) bool 63 : 64 : // NewWriter creates a new FilterWriter. 65 : NewWriter(ftype FilterType) FilterWriter 66 : } 67 : 68 : // BlockPropertyFilter is used in an Iterator to filter sstables and blocks 69 : // within the sstable. It should not maintain any per-sstable state, and must 70 : // be thread-safe. 71 : type BlockPropertyFilter interface { 72 : // Name returns the name of the block property collector. 73 : Name() string 74 : // Intersects returns true if the set represented by prop intersects with 75 : // the set in the filter. 76 : Intersects(prop []byte) (bool, error) 77 : // SyntheticSuffixIntersects runs Intersects, but only after using the passed in 78 : // suffix arg to modify a decoded copy of the passed in prop. This method only 79 : // needs to be implemented for filters which that will be used with suffix 80 : // replacement. 81 : SyntheticSuffixIntersects(prop []byte, suffix []byte) (bool, error) 82 : }