-
Notifications
You must be signed in to change notification settings - Fork 451
/
options.go
231 lines (199 loc) · 6.69 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
// 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"
"math"
goruntime "runtime"
"github.com/m3db/m3/src/dbnode/persist"
"github.com/m3db/m3/src/dbnode/persist/fs"
"github.com/m3db/m3/src/dbnode/persist/fs/migration"
"github.com/m3db/m3/src/dbnode/runtime"
"github.com/m3db/m3/src/dbnode/storage"
"github.com/m3db/m3/src/dbnode/storage/bootstrap/result"
"github.com/m3db/m3/src/dbnode/storage/index"
"github.com/m3db/m3/src/dbnode/storage/index/compaction"
"github.com/m3db/m3/src/x/ident"
"github.com/m3db/m3/src/x/instrument"
"github.com/m3db/m3/src/x/pool"
)
var (
errPersistManagerNotSet = errors.New("persist manager not set")
errCompactorNotSet = errors.New("compactor not set")
errIndexOptionsNotSet = errors.New("index options not set")
errFilesystemOptionsNotSet = errors.New("filesystem options not set")
errMigrationOptionsNotSet = errors.New("migration options not set")
// NB(r): Bootstrapping data doesn't use large amounts of memory
// that won't be released, so its fine to do this as fast as possible.
defaultBootstrapDataNumProcessors = int(math.Ceil(float64(goruntime.NumCPU()) / 2))
// NB(r): Bootstrapping index segments pulls a lot of data into memory
// since its across all shards, so we actually break up the
// number of segments we even create across the set of shards if
// we have to create an FST in place, this is to avoid OOMing a node.
// Because of this we only want to create one segment at a time otherwise
// us splitting an index block into smaller pieces is moot because we'll
// pull a lot more data into memory if we create more than one at a time.
defaultBootstrapIndexNumProcessors = 1
// defaultIndexSegmentConcurrency defines the default index segment building concurrency.
defaultIndexSegmentConcurrency = 1
)
type options struct {
instrumentOpts instrument.Options
resultOpts result.Options
fsOpts fs.Options
indexOpts index.Options
persistManager persist.Manager
compactor *compaction.Compactor
indexSegmentConcurrency int
runtimeOptsMgr runtime.OptionsManager
identifierPool ident.Pool
migrationOpts migration.Options
storageOpts storage.Options
}
// NewOptions creates new bootstrap options
func NewOptions() Options {
bytesPool := pool.NewCheckedBytesPool(nil, nil, func(s []pool.Bucket) pool.BytesPool {
return pool.NewBytesPool(s, nil)
})
bytesPool.Init()
idPool := ident.NewPool(bytesPool, ident.PoolOptions{})
return &options{
instrumentOpts: instrument.NewOptions(),
resultOpts: result.NewOptions(),
indexSegmentConcurrency: defaultIndexSegmentConcurrency,
runtimeOptsMgr: runtime.NewOptionsManager(),
identifierPool: idPool,
migrationOpts: migration.NewOptions(),
storageOpts: storage.NewOptions(),
}
}
func (o *options) Validate() error {
if o.persistManager == nil {
return errPersistManagerNotSet
}
if o.compactor == nil {
return errCompactorNotSet
}
if o.indexOpts == nil {
return errIndexOptionsNotSet
}
if o.fsOpts == nil {
return errFilesystemOptionsNotSet
}
if o.migrationOpts == nil {
return errMigrationOptionsNotSet
}
if err := o.migrationOpts.Validate(); err != nil {
return err
}
if n := o.indexSegmentConcurrency; n <= 0 {
return fmt.Errorf("index segment concurrency not >= 1: actual=%d", n)
}
return nil
}
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) SetResultOptions(value result.Options) Options {
opts := *o
opts.resultOpts = value
return &opts
}
func (o *options) ResultOptions() result.Options {
return o.resultOpts
}
func (o *options) SetFilesystemOptions(value fs.Options) Options {
opts := *o
opts.fsOpts = value
return &opts
}
func (o *options) FilesystemOptions() fs.Options {
return o.fsOpts
}
func (o *options) SetIndexOptions(value index.Options) Options {
opts := *o
opts.indexOpts = value
return &opts
}
func (o *options) IndexOptions() index.Options {
return o.indexOpts
}
func (o *options) SetPersistManager(value persist.Manager) Options {
opts := *o
opts.persistManager = value
return &opts
}
func (o *options) PersistManager() persist.Manager {
return o.persistManager
}
func (o *options) SetCompactor(value *compaction.Compactor) Options {
opts := *o
opts.compactor = value
return &opts
}
func (o *options) Compactor() *compaction.Compactor {
return o.compactor
}
func (o *options) SetIndexSegmentConcurrency(value int) Options {
opts := *o
opts.indexSegmentConcurrency = value
return &opts
}
func (o *options) IndexSegmentConcurrency() int {
return o.indexSegmentConcurrency
}
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) SetIdentifierPool(value ident.Pool) Options {
opts := *o
opts.identifierPool = value
return &opts
}
func (o *options) IdentifierPool() ident.Pool {
return o.identifierPool
}
func (o *options) SetMigrationOptions(value migration.Options) Options {
opts := *o
opts.migrationOpts = value
return &opts
}
func (o *options) MigrationOptions() migration.Options {
return o.migrationOpts
}
func (o *options) SetStorageOptions(value storage.Options) Options {
opts := *o
opts.storageOpts = value
return &opts
}
func (o *options) StorageOptions() storage.Options {
return o.storageOpts
}