-
Notifications
You must be signed in to change notification settings - Fork 451
/
types.go
232 lines (185 loc) · 7.31 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
220
221
222
223
224
225
226
227
228
229
230
231
232
// 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 commitlog
import (
"time"
"github.com/m3db/m3/src/dbnode/clock"
"github.com/m3db/m3/src/dbnode/persist"
"github.com/m3db/m3/src/dbnode/persist/fs"
"github.com/m3db/m3/src/dbnode/ts"
"github.com/m3db/m3/src/dbnode/ts/writes"
"github.com/m3db/m3/src/x/context"
"github.com/m3db/m3/src/x/ident"
"github.com/m3db/m3/src/x/instrument"
"github.com/m3db/m3/src/x/pool"
xtime "github.com/m3db/m3/src/x/time"
)
// Strategy describes the commit log writing strategy
type Strategy int
const (
// StrategyWriteWait describes the strategy that waits
// for the buffered commit log chunk that contains a write to flush
// before acknowledging a write
StrategyWriteWait Strategy = iota
// StrategyWriteBehind describes the strategy that does not wait
// for the buffered commit log chunk that contains a write to flush
// before acknowledging a write
StrategyWriteBehind
)
// CommitLog provides a synchronized commit log
type CommitLog interface {
// Open the commit log
Open() error
// Write will write an entry in the commit log for a given series
Write(
ctx context.Context,
series ts.Series,
datapoint ts.Datapoint,
unit xtime.Unit,
annotation ts.Annotation,
) error
// WriteBatch is the same as Write, but in batch.
WriteBatch(
ctx context.Context,
writes writes.WriteBatch,
) error
// Close the commit log
Close() error
// ActiveLogs returns a slice of the active commitlogs.
ActiveLogs() (persist.CommitLogFiles, error)
// RotateLogs rotates the commitlog and returns the File that represents
// the new commitlog file.
RotateLogs() (persist.CommitLogFile, error)
// QueueLength returns the number of writes that are currently in the commitlog
// queue.
QueueLength() int64
}
// LogEntry is a commit log entry being read.
type LogEntry struct {
Series ts.Series
Datapoint ts.Datapoint
Unit xtime.Unit
Annotation ts.Annotation
Metadata LogEntryMetadata
}
// LogEntryMetadata is a set of metadata about a commit log entry being read.
type LogEntryMetadata struct {
// FileReadID is a unique index for the current commit log
// file that is being read (only unique per-process).
FileReadID uint64
// SeriesUniqueIndex is the series unique index relative to the
// current commit log file being read.
SeriesUniqueIndex uint64
}
// Iterator provides an iterator for commit logs.
type Iterator interface {
// Next returns whether the iterator has the next value.
Next() bool
// Current returns the current commit log entry.
Current() LogEntry
// Err returns an error if an error occurred.
Err() error
// Close the iterator.
Close()
}
// IteratorOpts is a struct that contains coptions for the Iterator.
type IteratorOpts struct {
CommitLogOptions Options
FileFilterPredicate FileFilterPredicate
// ReturnMetadataAsRef will return all series metadata such as ID,
// tags and namespace as a reference instead of returning pooled
// or allocated byte/string/ID references.
// Useful if caller does not hold onto the result between calls to
// the next read log entry and wants to avoid allocations and pool
// contention.
// Note: Series metadata will only be set on the result of a log
// entry read if the series is read for the first time for the
// combined tuple of FileReadID and SeriesUniqueIndex returned by
// the LogEntryMetadata. EncodedTags will also be returned
// instead of Tags on the series metadata.
ReturnMetadataAsRef bool
}
// Options represents the options for the commit log.
type Options interface {
// Validate validates the Options.
Validate() error
// SetClockOptions sets the clock options.
SetClockOptions(value clock.Options) Options
// ClockOptions returns the clock options.
ClockOptions() clock.Options
// SetInstrumentOptions sets the instrumentation options.
SetInstrumentOptions(value instrument.Options) Options
// InstrumentOptions returns the instrumentation options,
InstrumentOptions() instrument.Options
// SetBlockSize sets the block size.
SetBlockSize(value time.Duration) Options
// BlockSize returns the block size.
BlockSize() time.Duration
// SetFilesystemOptions sets the filesystem options.
SetFilesystemOptions(value fs.Options) Options
// FilesystemOptions returns the filesystem options.
FilesystemOptions() fs.Options
// SetFlushSize sets the flush size.
SetFlushSize(value int) Options
// FlushSize returns the flush size.
FlushSize() int
// SetStrategy sets the strategy.
SetStrategy(value Strategy) Options
// Strategy returns the strategy.
Strategy() Strategy
// SetFlushInterval sets the flush interval.
SetFlushInterval(value time.Duration) Options
// FlushInterval returns the flush interval.
FlushInterval() time.Duration
// SetBacklogQueueSize sets the backlog queue size.
SetBacklogQueueSize(value int) Options
// BacklogQueueSize returns the backlog queue size.
BacklogQueueSize() int
// SetBacklogQueueChannelSize sets the size of the Golang channel
// that backs the queue.
SetBacklogQueueChannelSize(value int) Options
// BacklogQueueChannelSize returns the size of the Golang channel
// that backs the queue.
BacklogQueueChannelSize() int
// SetBytesPool sets the checked bytes pool.
SetBytesPool(value pool.CheckedBytesPool) Options
// BytesPool returns the checked bytes pool.
BytesPool() pool.CheckedBytesPool
// SetReadConcurrency sets the concurrency of the reader.
SetReadConcurrency(concurrency int) Options
// ReadConcurrency returns the concurrency of the reader.
ReadConcurrency() int
// SetIdentifierPool sets the IdentifierPool to use for pooling identifiers.
SetIdentifierPool(value ident.Pool) Options
// IdentifierPool returns the IdentifierPool to use for pooling identifiers.
IdentifierPool() ident.Pool
}
// FileFilterInfo contains information about a commitog file that can be used to
// determine whether the iterator should filter it out or not.
type FileFilterInfo struct {
// If isCorrupt is true then File will contain a valid CommitLogFile, otherwise
// ErrorWithPath will contain an error and the path of the corrupt file.
File persist.CommitLogFile
Err ErrorWithPath
IsCorrupt bool
}
// FileFilterPredicate is a predicate that allows the caller to determine
// which commitlogs the iterator should read from.
type FileFilterPredicate func(f FileFilterInfo) bool