github.com/m3db/m3@v1.5.0/src/dbnode/storage/series/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 series 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/encoding" 25 "github.com/m3db/m3/src/dbnode/retention" 26 m3dbruntime "github.com/m3db/m3/src/dbnode/runtime" 27 "github.com/m3db/m3/src/dbnode/storage/block" 28 "github.com/m3db/m3/src/x/clock" 29 "github.com/m3db/m3/src/x/context" 30 "github.com/m3db/m3/src/x/ident" 31 "github.com/m3db/m3/src/x/instrument" 32 "github.com/m3db/m3/src/x/pool" 33 ) 34 35 type options struct { 36 clockOpts clock.Options 37 instrumentOpts instrument.Options 38 retentionOpts retention.Options 39 blockOpts block.Options 40 cachePolicy CachePolicy 41 contextPool context.Pool 42 encoderPool encoding.EncoderPool 43 multiReaderIteratorPool encoding.MultiReaderIteratorPool 44 fetchBlockMetadataResultsPool block.FetchBlockMetadataResultsPool 45 identifierPool ident.Pool 46 stats Stats 47 coldWritesEnabled bool 48 bufferBucketPool *BufferBucketPool 49 bufferBucketVersionsPool *BufferBucketVersionsPool 50 runtimeOptsMgr m3dbruntime.OptionsManager 51 } 52 53 // NewOptions creates new database series options 54 func NewOptions() Options { 55 bytesPool := pool.NewCheckedBytesPool([]pool.Bucket{ 56 {Count: 4096, Capacity: 128}, 57 }, nil, func(s []pool.Bucket) pool.BytesPool { 58 return pool.NewBytesPool(s, nil) 59 }) 60 bytesPool.Init() 61 iopts := instrument.NewOptions() 62 return &options{ 63 clockOpts: clock.NewOptions(), 64 instrumentOpts: iopts, 65 retentionOpts: retention.NewOptions(), 66 blockOpts: block.NewOptions(), 67 cachePolicy: DefaultCachePolicy, 68 contextPool: context.NewPool(context.NewOptions()), 69 encoderPool: encoding.NewEncoderPool(nil), 70 multiReaderIteratorPool: encoding.NewMultiReaderIteratorPool(nil), 71 fetchBlockMetadataResultsPool: block.NewFetchBlockMetadataResultsPool(nil, 0), 72 identifierPool: ident.NewPool(bytesPool, ident.PoolOptions{}), 73 stats: NewStats(iopts.MetricsScope()), 74 } 75 } 76 77 func (o *options) Validate() error { 78 if err := o.retentionOpts.Validate(); err != nil { 79 return err 80 } 81 return ValidateCachePolicy(o.cachePolicy) 82 } 83 84 func (o *options) SetClockOptions(value clock.Options) Options { 85 opts := *o 86 opts.clockOpts = value 87 return &opts 88 } 89 90 func (o *options) ClockOptions() clock.Options { 91 return o.clockOpts 92 } 93 94 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 95 opts := *o 96 opts.instrumentOpts = value 97 return &opts 98 } 99 100 func (o *options) InstrumentOptions() instrument.Options { 101 return o.instrumentOpts 102 } 103 104 func (o *options) SetRetentionOptions(value retention.Options) Options { 105 opts := *o 106 opts.retentionOpts = value 107 return &opts 108 } 109 110 func (o *options) RetentionOptions() retention.Options { 111 return o.retentionOpts 112 } 113 114 func (o *options) SetDatabaseBlockOptions(value block.Options) Options { 115 opts := *o 116 opts.blockOpts = value 117 return &opts 118 } 119 120 func (o *options) DatabaseBlockOptions() block.Options { 121 return o.blockOpts 122 } 123 124 func (o *options) SetCachePolicy(value CachePolicy) Options { 125 opts := *o 126 opts.cachePolicy = value 127 return &opts 128 } 129 130 func (o *options) CachePolicy() CachePolicy { 131 return o.cachePolicy 132 } 133 134 func (o *options) SetContextPool(value context.Pool) Options { 135 opts := *o 136 opts.contextPool = value 137 return &opts 138 } 139 140 func (o *options) ContextPool() context.Pool { 141 return o.contextPool 142 } 143 144 func (o *options) SetEncoderPool(value encoding.EncoderPool) Options { 145 opts := *o 146 opts.encoderPool = value 147 return &opts 148 } 149 150 func (o *options) EncoderPool() encoding.EncoderPool { 151 return o.encoderPool 152 } 153 154 func (o *options) SetMultiReaderIteratorPool(value encoding.MultiReaderIteratorPool) Options { 155 opts := *o 156 opts.multiReaderIteratorPool = value 157 return &opts 158 } 159 160 func (o *options) MultiReaderIteratorPool() encoding.MultiReaderIteratorPool { 161 return o.multiReaderIteratorPool 162 } 163 164 func (o *options) SetFetchBlockMetadataResultsPool(value block.FetchBlockMetadataResultsPool) Options { 165 opts := *o 166 opts.fetchBlockMetadataResultsPool = value 167 return &opts 168 } 169 170 func (o *options) FetchBlockMetadataResultsPool() block.FetchBlockMetadataResultsPool { 171 return o.fetchBlockMetadataResultsPool 172 } 173 174 func (o *options) SetIdentifierPool(value ident.Pool) Options { 175 opts := *o 176 opts.identifierPool = value 177 return &opts 178 } 179 180 func (o *options) IdentifierPool() ident.Pool { 181 return o.identifierPool 182 } 183 184 func (o *options) SetStats(value Stats) Options { 185 opts := *o 186 opts.stats = value 187 return &opts 188 } 189 190 func (o *options) Stats() Stats { 191 return o.stats 192 } 193 194 func (o *options) SetColdWritesEnabled(value bool) Options { 195 opts := *o 196 opts.coldWritesEnabled = value 197 return &opts 198 } 199 200 func (o *options) ColdWritesEnabled() bool { 201 return o.coldWritesEnabled 202 } 203 204 func (o *options) SetBufferBucketVersionsPool(value *BufferBucketVersionsPool) Options { 205 opts := *o 206 opts.bufferBucketVersionsPool = value 207 return &opts 208 } 209 210 func (o *options) BufferBucketVersionsPool() *BufferBucketVersionsPool { 211 return o.bufferBucketVersionsPool 212 } 213 214 func (o *options) SetBufferBucketPool(value *BufferBucketPool) Options { 215 opts := *o 216 opts.bufferBucketPool = value 217 return &opts 218 } 219 220 func (o *options) BufferBucketPool() *BufferBucketPool { 221 return o.bufferBucketPool 222 } 223 224 func (o *options) SetRuntimeOptionsManager(value m3dbruntime.OptionsManager) Options { 225 opts := *o 226 opts.runtimeOptsMgr = value 227 return &opts 228 } 229 230 func (o *options) RuntimeOptionsManager() m3dbruntime.OptionsManager { 231 return o.runtimeOptsMgr 232 }