github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/persist/fs/retriever_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 fs 22 23 import ( 24 "errors" 25 "runtime" 26 27 "github.com/m3db/m3/src/dbnode/storage/block" 28 "github.com/m3db/m3/src/dbnode/storage/limits" 29 "github.com/m3db/m3/src/dbnode/x/xio" 30 "github.com/m3db/m3/src/x/ident" 31 "github.com/m3db/m3/src/x/pool" 32 ) 33 34 var ( 35 // Allow max concurrency to match available CPUs. 36 defaultFetchConcurrency = runtime.GOMAXPROCS(0) 37 defaultCacheOnRetrieve = false 38 39 errBlockLeaseManagerNotSet = errors.New("block lease manager is not set") 40 ) 41 42 type blockRetrieverOptions struct { 43 requestPool RetrieveRequestPool 44 bytesPool pool.CheckedBytesPool 45 fetchConcurrency int 46 cacheOnRetrieve bool 47 identifierPool ident.Pool 48 blockLeaseManager block.LeaseManager 49 queryLimits limits.QueryLimits 50 } 51 52 // NewBlockRetrieverOptions creates a new set of block retriever options 53 func NewBlockRetrieverOptions() BlockRetrieverOptions { 54 bytesPool := pool.NewCheckedBytesPool([]pool.Bucket{ 55 {Count: 4096, Capacity: 128}, 56 }, nil, func(s []pool.Bucket) pool.BytesPool { 57 return pool.NewBytesPool(s, nil) 58 }) 59 bytesPool.Init() 60 61 segmentReaderPool := xio.NewSegmentReaderPool(nil) 62 segmentReaderPool.Init() 63 64 requestPool := NewRetrieveRequestPool(segmentReaderPool, nil) 65 requestPool.Init() 66 67 o := &blockRetrieverOptions{ 68 requestPool: requestPool, 69 bytesPool: bytesPool, 70 fetchConcurrency: defaultFetchConcurrency, 71 cacheOnRetrieve: defaultCacheOnRetrieve, 72 identifierPool: ident.NewPool(bytesPool, ident.PoolOptions{}), 73 queryLimits: limits.NoOpQueryLimits(), 74 } 75 76 return o 77 } 78 79 func (o *blockRetrieverOptions) Validate() error { 80 if o.blockLeaseManager == nil { 81 return errBlockLeaseManagerNotSet 82 } 83 return nil 84 } 85 86 func (o *blockRetrieverOptions) SetRetrieveRequestPool(value RetrieveRequestPool) BlockRetrieverOptions { 87 opts := *o 88 opts.requestPool = value 89 return &opts 90 } 91 92 func (o *blockRetrieverOptions) RetrieveRequestPool() RetrieveRequestPool { 93 return o.requestPool 94 } 95 96 func (o *blockRetrieverOptions) SetBytesPool(value pool.CheckedBytesPool) BlockRetrieverOptions { 97 opts := *o 98 opts.bytesPool = value 99 return &opts 100 } 101 102 func (o *blockRetrieverOptions) BytesPool() pool.CheckedBytesPool { 103 return o.bytesPool 104 } 105 106 func (o *blockRetrieverOptions) SetFetchConcurrency(value int) BlockRetrieverOptions { 107 opts := *o 108 opts.fetchConcurrency = value 109 return &opts 110 } 111 112 func (o *blockRetrieverOptions) FetchConcurrency() int { 113 return o.fetchConcurrency 114 } 115 116 func (o *blockRetrieverOptions) SetCacheBlocksOnRetrieve(value bool) BlockRetrieverOptions { 117 opts := *o 118 opts.cacheOnRetrieve = value 119 return &opts 120 } 121 122 func (o *blockRetrieverOptions) CacheBlocksOnRetrieve() bool { 123 return o.cacheOnRetrieve 124 } 125 126 func (o *blockRetrieverOptions) SetIdentifierPool(value ident.Pool) BlockRetrieverOptions { 127 opts := *o 128 opts.identifierPool = value 129 return &opts 130 } 131 132 func (o *blockRetrieverOptions) IdentifierPool() ident.Pool { 133 return o.identifierPool 134 } 135 136 func (o *blockRetrieverOptions) SetBlockLeaseManager(leaseMgr block.LeaseManager) BlockRetrieverOptions { 137 opts := *o 138 opts.blockLeaseManager = leaseMgr 139 return &opts 140 } 141 142 func (o *blockRetrieverOptions) BlockLeaseManager() block.LeaseManager { 143 return o.blockLeaseManager 144 } 145 146 func (o *blockRetrieverOptions) SetQueryLimits(value limits.QueryLimits) BlockRetrieverOptions { 147 opts := *o 148 opts.queryLimits = value 149 return &opts 150 } 151 152 func (o *blockRetrieverOptions) QueryLimits() limits.QueryLimits { 153 return o.queryLimits 154 }