-
Notifications
You must be signed in to change notification settings - Fork 451
/
types.go
219 lines (182 loc) · 8.35 KB
/
types.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
// 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 bootstrap
import (
"time"
"github.com/m3db/m3/src/dbnode/persist"
"github.com/m3db/m3/src/dbnode/storage/bootstrap/result"
"github.com/m3db/m3/src/dbnode/storage/namespace"
"github.com/m3db/m3/src/dbnode/topology"
xtime "github.com/m3db/m3x/time"
)
// ProcessProvider constructs a bootstrap process that can execute a
// bootstrap run.
type ProcessProvider interface {
// SetBootstrapper sets the bootstrapper provider to use when running the
// process.
SetBootstrapperProvider(bootstrapper BootstrapperProvider)
// Bootstrapper returns the current bootstrappe provider to use when
// running the process.
BootstrapperProvider() BootstrapperProvider
// Provide constructs a bootstrap process.
Provide() (Process, error)
}
// Process represents the bootstrap process. Note that a bootstrap process can and will
// be reused so it is important to not rely on state stored in the bootstrap itself
// with the mindset that it will always be set to default values from the constructor.
type Process interface {
// Run runs the bootstrap process, returning the bootstrap result and any error encountered.
Run(start time.Time, ns namespace.Metadata, shards []uint32) (ProcessResult, error)
}
// ProcessResult is the result of a bootstrap process.
type ProcessResult struct {
DataResult result.DataBootstrapResult
IndexResult result.IndexBootstrapResult
}
// TargetRange is a bootstrap target range.
type TargetRange struct {
// Range is the time range to bootstrap for.
Range xtime.Range
// RunOptions is the bootstrap run options specific to the target range.
RunOptions RunOptions
}
// PersistConfig is the configuration for a bootstrap with persistence.
type PersistConfig struct {
// If enabled bootstrappers are allowed to write out bootstrapped data
// to disk on their own instead of just returning result in-memory.
Enabled bool
// If enabled, what type of persistence files should be generated during
// the process.
FileSetType persist.FileSetType
}
// ProcessOptions is a set of options for a bootstrap provider.
type ProcessOptions interface {
// SetCacheSeriesMetadata sets whether bootstrappers created by this
// provider should cache series metadata between runs.
SetCacheSeriesMetadata(value bool) ProcessOptions
// CacheSeriesMetadata returns whether bootstrappers created by this
// provider should cache series metadata between runs.
CacheSeriesMetadata() bool
// SetTopologyMapProvider sets the TopologyMapProvider.
SetTopologyMapProvider(value topology.MapProvider) ProcessOptions
// TopologyMapProvider returns the TopologyMapProvider.
TopologyMapProvider() topology.MapProvider
// SetOrigin sets the origin.
SetOrigin(value topology.Host) ProcessOptions
// Origin returns the origin.
Origin() topology.Host
// Validate validates that the ProcessOptions are correct.
Validate() error
}
// RunOptions is a set of options for a bootstrap run.
type RunOptions interface {
// SetPersistConfig sets persistence configuration for this bootstrap.
SetPersistConfig(value PersistConfig) RunOptions
// PersistConfig returns the persistence configuration for this bootstrap.
PersistConfig() PersistConfig
// SetCacheSeriesMetadata sets whether bootstrappers created by this
// provider should cache series metadata between runs.
SetCacheSeriesMetadata(value bool) RunOptions
// CacheSeriesMetadata returns whether bootstrappers created by this
// provider should cache series metadata between runs.
CacheSeriesMetadata() bool
// SetInitialTopologyState sets the initial topology state as it was
// measured before the bootstrap process began.
SetInitialTopologyState(value *topology.StateSnapshot) RunOptions
// InitialTopologyState returns the initial topology as it was measured
// before the bootstrap process began.
InitialTopologyState() *topology.StateSnapshot
}
// BootstrapperProvider constructs a bootstrapper.
type BootstrapperProvider interface {
// String returns the name of the bootstrapper.
String() string
// Provide constructs a bootstrapper.
Provide() (Bootstrapper, error)
}
// Strategy describes a bootstrap strategy.
type Strategy int
const (
// BootstrapSequential describes whether a bootstrap can use the sequential bootstrap strategy.
BootstrapSequential Strategy = iota
// BootstrapParallel describes whether a bootstrap can use the parallel bootstrap strategy.
BootstrapParallel
)
// Bootstrapper is the interface for different bootstrapping mechanisms. Note that a bootstrapper
// can and will be reused so it is important to not rely on state stored in the bootstrapper itself
// with the mindset that it will always be set to default values from the constructor.
type Bootstrapper interface {
// String returns the name of the bootstrapper
String() string
// Can returns whether a specific bootstrapper strategy can be applied.
Can(strategy Strategy) bool
// BootstrapData performs bootstrapping of data for the given time ranges, returning the bootstrapped
// series data and the time ranges it's unable to fulfill in parallel. A bootstrapper
// should only return an error should it want to entirely cancel the bootstrapping of the
// node, i.e. non-recoverable situation like not being able to read from the filesystem.
BootstrapData(
ns namespace.Metadata,
shardsTimeRanges result.ShardTimeRanges,
opts RunOptions,
) (result.DataBootstrapResult, error)
// BootstrapIndex performs bootstrapping of index blocks for the given time ranges, returning
// the bootstrapped index blocks and the time ranges it's unable to fulfill in parallel. A bootstrapper
// should only return an error should it want to entirely cancel the bootstrapping of the
// node, i.e. non-recoverable situation like not being able to read from the filesystem.
BootstrapIndex(
ns namespace.Metadata,
shardsTimeRanges result.ShardTimeRanges,
opts RunOptions,
) (result.IndexBootstrapResult, error)
}
// Source represents a bootstrap source. Note that a source can and will be reused so
// it is important to not rely on state stored in the source itself with the mindset
// that it will always be set to default values from the constructor.
type Source interface {
// Can returns whether a specific bootstrapper strategy can be applied.
Can(strategy Strategy) bool
// AvailableData returns what time ranges are available for bootstrapping a given set of shards.
AvailableData(
ns namespace.Metadata,
shardsTimeRanges result.ShardTimeRanges,
runOpts RunOptions,
) (result.ShardTimeRanges, error)
// ReadData returns raw series for a given set of shards & specified time ranges and
// the time ranges it's unable to fulfill. A bootstrapper source should only return
// an error should it want to entirely cancel the bootstrapping of the node,
// i.e. non-recoverable situation like not being able to read from the filesystem.
ReadData(
ns namespace.Metadata,
shardsTimeRanges result.ShardTimeRanges,
runOpts RunOptions,
) (result.DataBootstrapResult, error)
// AvailableIndex returns what time ranges are available for bootstrapping.
AvailableIndex(
ns namespace.Metadata,
shardsTimeRanges result.ShardTimeRanges,
opts RunOptions,
) (result.ShardTimeRanges, error)
// ReadIndex returns series index blocks.
ReadIndex(
ns namespace.Metadata,
shardsTimeRanges result.ShardTimeRanges,
opts RunOptions,
) (result.IndexBootstrapResult, error)
}