-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathoptions.go
355 lines (296 loc) · 10.9 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package fs
import (
"errors"
"fmt"
"os"
"github.com/m3db/m3/src/dbnode/clock"
"github.com/m3db/m3/src/dbnode/persist/fs/msgpack"
"github.com/m3db/m3/src/dbnode/runtime"
"github.com/m3db/m3/src/m3ninx/index/segment/fst"
"github.com/m3db/m3/src/x/serialize"
"github.com/m3db/m3x/instrument"
"github.com/m3db/m3x/pool"
)
const (
// defaultIndexSummariesPercent is the default percent of series for which an entry will be written into the metadata summary
defaultIndexSummariesPercent = 0.03
// defaultIndexBloomFilterFalsePositivePercent is the false positive percent to use to calculate size for when writing bloom filters
defaultIndexBloomFilterFalsePositivePercent = 0.02
// defaultWriterBufferSize is the default buffer size for writing TSDB files
defaultWriterBufferSize = 65536
// defaultDataReaderBufferSize is the default buffer size for reading TSDB data and index files
defaultDataReaderBufferSize = 65536
// defaultInfoReaderBufferSize is the default buffer size for reading TSDB info, checkpoint and digest files
defaultInfoReaderBufferSize = 64
// defaultSeekReaderBufferSize is the default buffer size for fs seeker's data buffer
defaultSeekReaderBufferSize = 4096
// defaultMmapEnableHugePages is the default setting whether to enable huge pages or not
defaultMmapEnableHugePages = false
// defaultMmapHugePagesThreshold is the default threshold for when to enable huge pages if enabled
defaultMmapHugePagesThreshold = 2 << 14 // 32kb (or when eclipsing 8 pages of default 4096 page size)
// defaultForceIndexSummariesMmapMemory is the default configuration for whether the bytes for the index
// summaries file should be mmap'd as an anonymous region (forced completely into memory) or mmap'd as a file.
defaultForceIndexSummariesMmapMemory = false
// defaultForceIndexBloomFilterMmapMemory is the default configuration for whether the bytes for the bloom filter
// should be mmap'd as an anonymous region (forced completely into memory) or mmap'd as a file.
defaultForceIndexBloomFilterMmapMemory = false
)
var (
defaultFilePathPrefix = os.TempDir()
defaultNewFileMode = os.FileMode(0666)
defaultNewDirectoryMode = os.ModeDir | os.FileMode(0755)
errTagEncoderPoolNotSet = errors.New("tag encoder pool is not set")
errTagDecoderPoolNotSet = errors.New("tag decoder pool is not set")
)
type options struct {
clockOpts clock.Options
instrumentOpts instrument.Options
runtimeOptsMgr runtime.OptionsManager
decodingOpts msgpack.DecodingOptions
filePathPrefix string
newFileMode os.FileMode
newDirectoryMode os.FileMode
indexSummariesPercent float64
indexBloomFilterFalsePositivePercent float64
forceIndexSummariesMmapMemory bool
forceBloomFilterMmapMemory bool
writerBufferSize int
dataReaderBufferSize int
infoReaderBufferSize int
seekReaderBufferSize int
mmapEnableHugePages bool
mmapHugePagesThreshold int64
tagEncoderPool serialize.TagEncoderPool
tagDecoderPool serialize.TagDecoderPool
fstOptions fst.Options
}
// NewOptions creates a new set of fs options
func NewOptions() Options {
tagEncoderPool := serialize.NewTagEncoderPool(
serialize.NewTagEncoderOptions(), pool.NewObjectPoolOptions())
tagEncoderPool.Init()
tagDecoderPool := serialize.NewTagDecoderPool(
serialize.NewTagDecoderOptions(), pool.NewObjectPoolOptions())
tagDecoderPool.Init()
fstOptions := fst.NewOptions()
return &options{
clockOpts: clock.NewOptions(),
instrumentOpts: instrument.NewOptions(),
runtimeOptsMgr: runtime.NewOptionsManager(),
decodingOpts: msgpack.NewDecodingOptions(),
filePathPrefix: defaultFilePathPrefix,
newFileMode: defaultNewFileMode,
newDirectoryMode: defaultNewDirectoryMode,
indexSummariesPercent: defaultIndexSummariesPercent,
indexBloomFilterFalsePositivePercent: defaultIndexBloomFilterFalsePositivePercent,
forceIndexSummariesMmapMemory: defaultForceIndexSummariesMmapMemory,
forceBloomFilterMmapMemory: defaultForceIndexBloomFilterMmapMemory,
writerBufferSize: defaultWriterBufferSize,
dataReaderBufferSize: defaultDataReaderBufferSize,
infoReaderBufferSize: defaultInfoReaderBufferSize,
seekReaderBufferSize: defaultSeekReaderBufferSize,
mmapEnableHugePages: defaultMmapEnableHugePages,
mmapHugePagesThreshold: defaultMmapHugePagesThreshold,
tagEncoderPool: tagEncoderPool,
tagDecoderPool: tagDecoderPool,
fstOptions: fstOptions,
}
}
func (o *options) Validate() error {
if o.indexSummariesPercent < 0 || o.indexSummariesPercent > 1.0 {
return fmt.Errorf(
"invalid index summaries percent, must be >= 0 and <= 1: instead %f",
o.indexSummariesPercent)
}
if o.indexBloomFilterFalsePositivePercent < 0 || o.indexBloomFilterFalsePositivePercent > 1.0 {
return fmt.Errorf(
"invalid index bloom filter false positive percent, must be >= 0 and <= 1: instead %f",
o.indexBloomFilterFalsePositivePercent)
}
if o.tagEncoderPool == nil {
return errTagEncoderPoolNotSet
}
if o.tagDecoderPool == nil {
return errTagDecoderPoolNotSet
}
return nil
}
func (o *options) SetClockOptions(value clock.Options) Options {
opts := *o
opts.clockOpts = value
return &opts
}
func (o *options) ClockOptions() clock.Options {
return o.clockOpts
}
func (o *options) SetInstrumentOptions(value instrument.Options) Options {
opts := *o
opts.instrumentOpts = value
return &opts
}
func (o *options) InstrumentOptions() instrument.Options {
return o.instrumentOpts
}
func (o *options) SetRuntimeOptionsManager(value runtime.OptionsManager) Options {
opts := *o
opts.runtimeOptsMgr = value
return &opts
}
func (o *options) RuntimeOptionsManager() runtime.OptionsManager {
return o.runtimeOptsMgr
}
func (o *options) SetDecodingOptions(value msgpack.DecodingOptions) Options {
opts := *o
opts.decodingOpts = value
return &opts
}
func (o *options) DecodingOptions() msgpack.DecodingOptions {
return o.decodingOpts
}
func (o *options) SetFilePathPrefix(value string) Options {
opts := *o
opts.filePathPrefix = value
return &opts
}
func (o *options) FilePathPrefix() string {
return o.filePathPrefix
}
func (o *options) SetNewFileMode(value os.FileMode) Options {
opts := *o
opts.newFileMode = value
return &opts
}
func (o *options) NewFileMode() os.FileMode {
return o.newFileMode
}
func (o *options) SetNewDirectoryMode(value os.FileMode) Options {
opts := *o
opts.newDirectoryMode = value
return &opts
}
func (o *options) NewDirectoryMode() os.FileMode {
return o.newDirectoryMode
}
func (o *options) SetIndexSummariesPercent(value float64) Options {
opts := *o
opts.indexSummariesPercent = value
return &opts
}
func (o *options) IndexSummariesPercent() float64 {
return o.indexSummariesPercent
}
func (o *options) SetIndexBloomFilterFalsePositivePercent(value float64) Options {
opts := *o
opts.indexBloomFilterFalsePositivePercent = value
return &opts
}
func (o *options) IndexBloomFilterFalsePositivePercent() float64 {
return o.indexBloomFilterFalsePositivePercent
}
func (o *options) SetForceIndexSummariesMmapMemory(value bool) Options {
opts := *o
opts.forceIndexSummariesMmapMemory = value
return &opts
}
func (o *options) ForceIndexSummariesMmapMemory() bool {
return o.forceIndexSummariesMmapMemory
}
func (o *options) SetForceBloomFilterMmapMemory(value bool) Options {
opts := *o
opts.forceBloomFilterMmapMemory = value
return &opts
}
func (o *options) ForceBloomFilterMmapMemory() bool {
return o.forceBloomFilterMmapMemory
}
func (o *options) SetWriterBufferSize(value int) Options {
opts := *o
opts.writerBufferSize = value
return &opts
}
func (o *options) WriterBufferSize() int {
return o.writerBufferSize
}
func (o *options) SetDataReaderBufferSize(value int) Options {
opts := *o
opts.dataReaderBufferSize = value
return &opts
}
func (o *options) DataReaderBufferSize() int {
return o.dataReaderBufferSize
}
func (o *options) SetInfoReaderBufferSize(value int) Options {
opts := *o
opts.infoReaderBufferSize = value
return &opts
}
func (o *options) InfoReaderBufferSize() int {
return o.infoReaderBufferSize
}
func (o *options) SetSeekReaderBufferSize(value int) Options {
opts := *o
opts.seekReaderBufferSize = value
return &opts
}
func (o *options) SeekReaderBufferSize() int {
return o.seekReaderBufferSize
}
func (o *options) SetMmapEnableHugeTLB(value bool) Options {
opts := *o
opts.mmapEnableHugePages = value
return &opts
}
func (o *options) MmapEnableHugeTLB() bool {
return o.mmapEnableHugePages
}
func (o *options) SetMmapHugeTLBThreshold(value int64) Options {
opts := *o
opts.mmapHugePagesThreshold = value
return &opts
}
func (o *options) MmapHugeTLBThreshold() int64 {
return o.mmapHugePagesThreshold
}
func (o *options) SetTagEncoderPool(value serialize.TagEncoderPool) Options {
opts := *o
opts.tagEncoderPool = value
return &opts
}
func (o *options) TagEncoderPool() serialize.TagEncoderPool {
return o.tagEncoderPool
}
func (o *options) SetTagDecoderPool(value serialize.TagDecoderPool) Options {
opts := *o
opts.tagDecoderPool = value
return &opts
}
func (o *options) TagDecoderPool() serialize.TagDecoderPool {
return o.tagDecoderPool
}
func (o *options) SetFSTOptions(value fst.Options) Options {
opts := *o
opts.fstOptions = value
return &opts
}
func (o *options) FSTOptions() fst.Options {
return o.fstOptions
}