github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/internal/base/options.go (about)

     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  )
    13  
    14  // FilterType is the level at which to apply a filter: block or table.
    15  type FilterType int
    16  
    17  // The available filter types.
    18  const (
    19  	TableFilter FilterType = iota
    20  )
    21  
    22  func (t FilterType) String() string {
    23  	switch t {
    24  	case TableFilter:
    25  		return "table"
    26  	}
    27  	return "unknown"
    28  }
    29  
    30  // FilterWriter provides an interface for creating filter blocks. See
    31  // FilterPolicy for more details about filters.
    32  type FilterWriter interface {
    33  	// AddKey adds a key to the current filter block.
    34  	AddKey(key []byte)
    35  
    36  	// Finish appends to dst an encoded filter tha holds the current set of
    37  	// keys. The writer state is reset after the call to Finish allowing the
    38  	// writer to be reused for the creation of additional filters.
    39  	Finish(dst []byte) []byte
    40  }
    41  
    42  // FilterPolicy is an algorithm for probabilistically encoding a set of keys.
    43  // The canonical implementation is a Bloom filter.
    44  //
    45  // Every FilterPolicy has a name. This names the algorithm itself, not any one
    46  // particular instance. Aspects specific to a particular instance, such as the
    47  // set of keys or any other parameters, will be encoded in the []byte filter
    48  // returned by NewWriter.
    49  //
    50  // The name may be written to files on disk, along with the filter data. To use
    51  // these filters, the FilterPolicy name at the time of writing must equal the
    52  // name at the time of reading. If they do not match, the filters will be
    53  // ignored, which will not affect correctness but may affect performance.
    54  type FilterPolicy interface {
    55  	// Name names the filter policy.
    56  	Name() string
    57  
    58  	// MayContain returns whether the encoded filter may contain given key.
    59  	// False positives are possible, where it returns true for keys not in the
    60  	// original set.
    61  	MayContain(ftype FilterType, filter, key []byte) bool
    62  
    63  	// NewWriter creates a new FilterWriter.
    64  	NewWriter(ftype FilterType) FilterWriter
    65  }
    66  
    67  // BlockPropertyFilter is used in an Iterator to filter sstables and blocks
    68  // within the sstable. It should not maintain any per-sstable state, and must
    69  // be thread-safe.
    70  type BlockPropertyFilter interface {
    71  	// Name returns the name of the block property collector.
    72  	Name() string
    73  	// Intersects returns true if the set represented by prop intersects with
    74  	// the set in the filter.
    75  	Intersects(prop []byte) (bool, error)
    76  }