github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/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 pebble 6 7 import "github.com/petermattis/pebble/internal/base" 8 9 // Compression exports the base.Compression type. 10 type Compression = base.Compression 11 12 // Exported Compression constants. 13 const ( 14 DefaultCompression = base.DefaultCompression 15 NoCompression = base.NoCompression 16 SnappyCompression = base.SnappyCompression 17 ) 18 19 // FilterType exports the base.FilterType type. 20 type FilterType = base.FilterType 21 22 // Exported TableFilter constants. 23 const ( 24 TableFilter = base.TableFilter 25 ) 26 27 // FilterWriter exports the base.FilterWriter type. 28 type FilterWriter = base.FilterWriter 29 30 // FilterPolicy exports the base.FilterPolicy type. 31 type FilterPolicy = base.FilterPolicy 32 33 // TableFormat exports the base.TableFormat type. 34 type TableFormat = base.TableFormat 35 36 // Exported TableFormat constants. 37 const ( 38 TableFormatRocksDBv2 = base.TableFormatRocksDBv2 39 TableFormatLevelDB = base.TableFormatLevelDB 40 ) 41 42 // TablePropertyCollector exports the base.TablePropertyCollector type. 43 type TablePropertyCollector = base.TablePropertyCollector 44 45 // LevelOptions exports the base.LevelOptions type. 46 type LevelOptions = base.LevelOptions 47 48 // Options exports the base.Options type. 49 type Options = base.Options 50 51 // IterOptions hold the optional per-query parameters for NewIter. 52 // 53 // Like Options, a nil *IterOptions is valid and means to use the default 54 // values. 55 type IterOptions struct { 56 // LowerBound specifies the smallest key (inclusive) that the iterator will 57 // return during iteration. If the iterator is seeked or iterated past this 58 // boundary the iterator will return Valid()==false. Setting LowerBound 59 // effectively truncates the key space visible to the iterator. 60 LowerBound []byte 61 // UpperBound specifies the largest key (exclusive) that the iterator will 62 // return during iteration. If the iterator is seeked or iterated past this 63 // boundary the iterator will return Valid()==false. Setting UpperBound 64 // effectively truncates the key space visible to the iterator. 65 UpperBound []byte 66 // TableFilter can be used to filter the tables that are scanned during 67 // iteration based on the user properties. Return true to scan the table and 68 // false to skip scanning. 69 TableFilter func(userProps map[string]string) bool 70 } 71 72 // GetLowerBound returns the LowerBound or nil if the receiver is nil. 73 func (o *IterOptions) GetLowerBound() []byte { 74 if o == nil { 75 return nil 76 } 77 return o.LowerBound 78 } 79 80 // GetUpperBound returns the UpperBound or nil if the receiver is nil. 81 func (o *IterOptions) GetUpperBound() []byte { 82 if o == nil { 83 return nil 84 } 85 return o.UpperBound 86 } 87 88 // WriteOptions hold the optional per-query parameters for Set and Delete 89 // operations. 90 // 91 // Like Options, a nil *WriteOptions is valid and means to use the default 92 // values. 93 type WriteOptions struct { 94 // Sync is whether to sync underlying writes from the OS buffer cache 95 // through to actual disk, if applicable. Setting Sync can result in 96 // slower writes. 97 // 98 // If false, and the machine crashes, then some recent writes may be lost. 99 // Note that if it is just the process that crashes (and the machine does 100 // not) then no writes will be lost. 101 // 102 // In other words, Sync being false has the same semantics as a write 103 // system call. Sync being true means write followed by fsync. 104 // 105 // The default value is true. 106 Sync bool 107 } 108 109 // Sync specifies the default write options for writes which synchronize to 110 // disk. 111 var Sync = &WriteOptions{Sync: true} 112 113 // NoSync specifies the default write options for writes which do not 114 // synchronize to disk. 115 var NoSync = &WriteOptions{Sync: false} 116 117 // GetSync returns the Sync value or true if the receiver is nil. 118 func (o *WriteOptions) GetSync() bool { 119 return o == nil || o.Sync 120 }