github.com/m3db/m3@v1.5.0/src/m3ninx/index/segment/fst/options.go (about) 1 // Copyright (c) 2018 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 fst 22 23 import ( 24 "github.com/m3db/m3/src/m3ninx/postings" 25 "github.com/m3db/m3/src/m3ninx/postings/roaring" 26 "github.com/m3db/m3/src/m3ninx/x/bytes" 27 "github.com/m3db/m3/src/x/context" 28 "github.com/m3db/m3/src/x/instrument" 29 "github.com/m3db/m3/src/x/pool" 30 ) 31 32 const ( 33 defaultBytesArrayPoolCapacity = 128 34 ) 35 36 // Options is a collection of knobs for a fs segment. 37 type Options interface { 38 // SetInstrumentOptions sets the instrument options. 39 SetInstrumentOptions(value instrument.Options) Options 40 41 // InstrumentOptions returns the instrument options. 42 InstrumentOptions() instrument.Options 43 44 // SetBytesPool sets the bytes pool. 45 SetBytesPool(value pool.BytesPool) Options 46 47 // BytesPool returns the bytes pool. 48 BytesPool() pool.BytesPool 49 50 // SetPostingsListPool sets the postings list pool. 51 SetPostingsListPool(value postings.Pool) Options 52 53 // PostingsListPool returns the postings list pool. 54 PostingsListPool() postings.Pool 55 56 // SetContextPool sets the contextPool. 57 SetContextPool(value context.Pool) Options 58 59 // ContextPool returns the contextPool. 60 ContextPool() context.Pool 61 } 62 63 type opts struct { 64 iopts instrument.Options 65 bytesSliceArrPool bytes.SliceArrayPool 66 bytesPool pool.BytesPool 67 postingsPool postings.Pool 68 contextPool context.Pool 69 } 70 71 // NewOptions returns new options. 72 func NewOptions() Options { 73 arrPool := bytes.NewSliceArrayPool(bytes.SliceArrayPoolOpts{ 74 Capacity: defaultBytesArrayPoolCapacity, 75 Options: pool.NewObjectPoolOptions(), 76 }) 77 arrPool.Init() 78 79 bytesPool := pool.NewBytesPool([]pool.Bucket{ 80 {Capacity: 256, Count: 1024}, 81 }, nil) 82 bytesPool.Init() 83 84 return &opts{ 85 iopts: instrument.NewOptions(), 86 bytesSliceArrPool: arrPool, 87 bytesPool: bytesPool, 88 postingsPool: postings.NewPool(nil, roaring.NewPostingsList), 89 // Use a zero pool, this should be overriden at config time. 90 contextPool: context.NewPool(context.NewOptions(). 91 SetContextPoolOptions(pool.NewObjectPoolOptions().SetSize(0)). 92 SetFinalizerPoolOptions(pool.NewObjectPoolOptions().SetSize(0))), 93 } 94 } 95 96 func (o *opts) SetInstrumentOptions(v instrument.Options) Options { 97 opts := *o 98 opts.iopts = v 99 return &opts 100 } 101 102 func (o *opts) InstrumentOptions() instrument.Options { 103 return o.iopts 104 } 105 106 func (o *opts) SetBytesPool(value pool.BytesPool) Options { 107 opts := *o 108 opts.bytesPool = value 109 return &opts 110 } 111 112 func (o *opts) BytesPool() pool.BytesPool { 113 return o.bytesPool 114 } 115 116 func (o *opts) SetPostingsListPool(v postings.Pool) Options { 117 opts := *o 118 opts.postingsPool = v 119 return &opts 120 } 121 122 func (o *opts) PostingsListPool() postings.Pool { 123 return o.postingsPool 124 } 125 126 func (o *opts) SetContextPool(value context.Pool) Options { 127 opts := *o 128 opts.contextPool = value 129 return &opts 130 } 131 132 func (o *opts) ContextPool() context.Pool { 133 return o.contextPool 134 }