github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/encoding/options.go (about) 1 // Copyright (c) 2016 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package encoding 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/x/xio" 25 "github.com/m3db/m3/src/dbnode/x/xpool" 26 "github.com/m3db/m3/src/x/instrument" 27 "github.com/m3db/m3/src/x/pool" 28 xtime "github.com/m3db/m3/src/x/time" 29 ) 30 31 const ( 32 defaultDefaultTimeUnit = xtime.Second 33 defaultByteFieldDictLRUSize = 4 34 defaultIStreamReaderSizeM3TSZ = 8 * 2 35 defaultIStreamReaderSizeProto = 128 36 ) 37 38 var ( 39 // default encoding options 40 defaultOptions = newOptions() 41 ) 42 43 type options struct { 44 defaultTimeUnit xtime.Unit 45 timeEncodingSchemes TimeEncodingSchemes 46 markerEncodingScheme *MarkerEncodingScheme 47 encoderPool EncoderPool 48 readerIteratorPool ReaderIteratorPool 49 bytesPool pool.CheckedBytesPool 50 segmentReaderPool xio.SegmentReaderPool 51 checkedBytesWrapperPool xpool.CheckedBytesWrapperPool 52 byteFieldDictLRUSize int 53 iStreamReaderSizeM3TSZ int 54 iStreamReaderSizeProto int 55 metrics Metrics 56 } 57 58 func newOptions() Options { 59 return &options{ 60 defaultTimeUnit: defaultDefaultTimeUnit, 61 timeEncodingSchemes: NewTimeEncodingSchemes(defaultTimeEncodingSchemes), 62 markerEncodingScheme: defaultMarkerEncodingScheme, 63 byteFieldDictLRUSize: defaultByteFieldDictLRUSize, 64 iStreamReaderSizeM3TSZ: defaultIStreamReaderSizeM3TSZ, 65 iStreamReaderSizeProto: defaultIStreamReaderSizeProto, 66 metrics: NewMetrics(instrument.NewOptions().MetricsScope()), 67 } 68 } 69 70 // NewOptions creates a new options. 71 func NewOptions() Options { 72 return defaultOptions 73 } 74 75 func (o *options) SetDefaultTimeUnit(value xtime.Unit) Options { 76 opts := *o 77 opts.defaultTimeUnit = value 78 return &opts 79 } 80 81 func (o *options) DefaultTimeUnit() xtime.Unit { 82 return o.defaultTimeUnit 83 } 84 85 func (o *options) SetTimeEncodingSchemes(value map[xtime.Unit]TimeEncodingScheme) Options { 86 opts := *o 87 opts.timeEncodingSchemes = NewTimeEncodingSchemes(value) 88 return &opts 89 } 90 91 func (o *options) TimeEncodingSchemes() TimeEncodingSchemes { 92 return o.timeEncodingSchemes 93 } 94 95 func (o *options) SetMarkerEncodingScheme(value *MarkerEncodingScheme) Options { 96 opts := *o 97 opts.markerEncodingScheme = value 98 return &opts 99 } 100 101 func (o *options) MarkerEncodingScheme() *MarkerEncodingScheme { 102 return o.markerEncodingScheme 103 } 104 105 func (o *options) SetEncoderPool(value EncoderPool) Options { 106 opts := *o 107 opts.encoderPool = value 108 return &opts 109 } 110 111 func (o *options) EncoderPool() EncoderPool { 112 return o.encoderPool 113 } 114 115 func (o *options) SetReaderIteratorPool(value ReaderIteratorPool) Options { 116 opts := *o 117 opts.readerIteratorPool = value 118 return &opts 119 } 120 121 func (o *options) ReaderIteratorPool() ReaderIteratorPool { 122 return o.readerIteratorPool 123 } 124 125 func (o *options) SetBytesPool(value pool.CheckedBytesPool) Options { 126 opts := *o 127 opts.bytesPool = value 128 return &opts 129 } 130 131 func (o *options) BytesPool() pool.CheckedBytesPool { 132 return o.bytesPool 133 } 134 135 func (o *options) SetSegmentReaderPool(value xio.SegmentReaderPool) Options { 136 opts := *o 137 opts.segmentReaderPool = value 138 return &opts 139 } 140 141 func (o *options) SegmentReaderPool() xio.SegmentReaderPool { 142 return o.segmentReaderPool 143 } 144 145 func (o *options) SetCheckedBytesWrapperPool(value xpool.CheckedBytesWrapperPool) Options { 146 opts := *o 147 opts.checkedBytesWrapperPool = value 148 return &opts 149 } 150 151 func (o *options) CheckedBytesWrapperPool() xpool.CheckedBytesWrapperPool { 152 return o.checkedBytesWrapperPool 153 } 154 155 func (o *options) SetByteFieldDictionaryLRUSize(value int) Options { 156 opts := *o 157 opts.byteFieldDictLRUSize = value 158 return &opts 159 } 160 161 func (o *options) ByteFieldDictionaryLRUSize() int { 162 return o.byteFieldDictLRUSize 163 } 164 165 func (o *options) SetIStreamReaderSizeM3TSZ(value int) Options { 166 opts := *o 167 opts.iStreamReaderSizeM3TSZ = value 168 return &opts 169 } 170 171 func (o *options) IStreamReaderSizeM3TSZ() int { 172 return o.iStreamReaderSizeM3TSZ 173 } 174 175 func (o *options) SetIStreamReaderSizeProto(value int) Options { 176 opts := *o 177 opts.iStreamReaderSizeProto = value 178 return &opts 179 } 180 181 func (o *options) IStreamReaderSizeProto() int { 182 return o.iStreamReaderSizeProto 183 } 184 185 func (o *options) SetMetrics(value Metrics) Options { 186 opts := *o 187 opts.metrics = value 188 return &opts 189 } 190 191 func (o *options) Metrics() Metrics { 192 return o.metrics 193 }