github.com/m3db/m3@v1.5.0/src/dbnode/network/server/tchannelthrift/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 tchannelthrift 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/storage/limits" 25 "github.com/m3db/m3/src/dbnode/storage/limits/permits" 26 "github.com/m3db/m3/src/dbnode/topology" 27 "github.com/m3db/m3/src/dbnode/x/xpool" 28 "github.com/m3db/m3/src/x/clock" 29 "github.com/m3db/m3/src/x/ident" 30 "github.com/m3db/m3/src/x/instrument" 31 "github.com/m3db/m3/src/x/pool" 32 "github.com/m3db/m3/src/x/serialize" 33 ) 34 35 type options struct { 36 clockOpts clock.Options 37 instrumentOpts instrument.Options 38 topologyInitializer topology.Initializer 39 idPool ident.Pool 40 blockMetadataV2Pool BlockMetadataV2Pool 41 blockMetadataV2SlicePool BlockMetadataV2SlicePool 42 tagEncoderPool serialize.TagEncoderPool 43 tagDecoderPool serialize.TagDecoderPool 44 checkedBytesWrapperPool xpool.CheckedBytesWrapperPool 45 maxOutstandingWriteRequests int 46 maxOutstandingReadRequests int 47 queryLimits limits.QueryLimits 48 permitsOptions permits.Options 49 seriesBlocksPerBatch int 50 } 51 52 // NewOptions creates new options. 53 func NewOptions() Options { 54 // Use a zero size pool by default, override from config. 55 poolOptions := pool.NewObjectPoolOptions(). 56 SetSize(0) 57 58 bytesPool := pool.NewCheckedBytesPool(nil, nil, func(s []pool.Bucket) pool.BytesPool { 59 return pool.NewBytesPool(s, nil) 60 }) 61 bytesPool.Init() 62 63 idPool := ident.NewPool(bytesPool, ident.PoolOptions{ 64 IDPoolOptions: poolOptions, 65 TagsPoolOptions: poolOptions, 66 TagsIteratorPoolOptions: poolOptions, 67 }) 68 69 tagEncoderPool := serialize.NewTagEncoderPool( 70 serialize.NewTagEncoderOptions(), 71 poolOptions) 72 tagEncoderPool.Init() 73 74 bytesWrapperPool := xpool.NewCheckedBytesWrapperPool(poolOptions) 75 bytesWrapperPool.Init() 76 77 return &options{ 78 clockOpts: clock.NewOptions(), 79 instrumentOpts: instrument.NewOptions(), 80 idPool: idPool, 81 blockMetadataV2Pool: NewBlockMetadataV2Pool(nil), 82 blockMetadataV2SlicePool: NewBlockMetadataV2SlicePool(nil, 0), 83 tagEncoderPool: tagEncoderPool, 84 checkedBytesWrapperPool: bytesWrapperPool, 85 queryLimits: limits.NoOpQueryLimits(), 86 permitsOptions: permits.NewOptions(), 87 } 88 } 89 90 func (o *options) SetClockOptions(value clock.Options) Options { 91 opts := *o 92 opts.clockOpts = value 93 return &opts 94 } 95 96 func (o *options) ClockOptions() clock.Options { 97 return o.clockOpts 98 } 99 100 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 101 opts := *o 102 opts.instrumentOpts = value 103 return &opts 104 } 105 106 func (o *options) InstrumentOptions() instrument.Options { 107 return o.instrumentOpts 108 } 109 110 func (o *options) SetTopologyInitializer(value topology.Initializer) Options { 111 opts := *o 112 opts.topologyInitializer = value 113 return &opts 114 } 115 116 func (o *options) TopologyInitializer() topology.Initializer { 117 return o.topologyInitializer 118 } 119 120 func (o *options) SetIdentifierPool(value ident.Pool) Options { 121 opts := *o 122 opts.idPool = value 123 return &opts 124 } 125 126 func (o *options) IdentifierPool() ident.Pool { 127 return o.idPool 128 } 129 130 func (o *options) SetBlockMetadataV2Pool(value BlockMetadataV2Pool) Options { 131 opts := *o 132 opts.blockMetadataV2Pool = value 133 return &opts 134 } 135 136 func (o *options) BlockMetadataV2Pool() BlockMetadataV2Pool { 137 return o.blockMetadataV2Pool 138 } 139 140 func (o *options) SetBlockMetadataV2SlicePool(value BlockMetadataV2SlicePool) Options { 141 opts := *o 142 opts.blockMetadataV2SlicePool = value 143 return &opts 144 } 145 146 func (o *options) BlockMetadataV2SlicePool() BlockMetadataV2SlicePool { 147 return o.blockMetadataV2SlicePool 148 } 149 150 func (o *options) SetTagEncoderPool(value serialize.TagEncoderPool) Options { 151 opts := *o 152 opts.tagEncoderPool = value 153 return &opts 154 } 155 156 func (o *options) TagEncoderPool() serialize.TagEncoderPool { 157 return o.tagEncoderPool 158 } 159 160 func (o *options) SetCheckedBytesWrapperPool(value xpool.CheckedBytesWrapperPool) Options { 161 opts := *o 162 opts.checkedBytesWrapperPool = value 163 return &opts 164 } 165 166 func (o *options) CheckedBytesWrapperPool() xpool.CheckedBytesWrapperPool { 167 return o.checkedBytesWrapperPool 168 } 169 170 func (o *options) SetMaxOutstandingWriteRequests(value int) Options { 171 opts := *o 172 opts.maxOutstandingWriteRequests = value 173 return &opts 174 } 175 176 func (o *options) MaxOutstandingWriteRequests() int { 177 return o.maxOutstandingWriteRequests 178 } 179 180 func (o *options) SetMaxOutstandingReadRequests(value int) Options { 181 opts := *o 182 opts.maxOutstandingReadRequests = value 183 return &opts 184 } 185 186 func (o *options) MaxOutstandingReadRequests() int { 187 return o.maxOutstandingReadRequests 188 } 189 190 func (o *options) SetQueryLimits(value limits.QueryLimits) Options { 191 opts := *o 192 opts.queryLimits = value 193 return &opts 194 } 195 196 func (o *options) QueryLimits() limits.QueryLimits { 197 return o.queryLimits 198 } 199 200 func (o *options) SetPermitsOptions(value permits.Options) Options { 201 opts := *o 202 opts.permitsOptions = value 203 return &opts 204 } 205 206 func (o *options) PermitsOptions() permits.Options { 207 return o.permitsOptions 208 } 209 210 func (o *options) SetFetchTaggedSeriesBlocksPerBatch(value int) Options { 211 opts := *o 212 opts.seriesBlocksPerBatch = value 213 return &opts 214 } 215 216 func (o *options) FetchTaggedSeriesBlocksPerBatch() int { 217 return o.seriesBlocksPerBatch 218 }