-
Notifications
You must be signed in to change notification settings - Fork 450
/
types.go
129 lines (115 loc) · 4.26 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
// Copyright (c) 2020 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 writes
import (
"time"
"github.com/m3db/m3/src/dbnode/storage/index"
"github.com/m3db/m3/src/dbnode/ts"
"github.com/m3db/m3/src/m3ninx/doc"
"github.com/m3db/m3/src/x/ident"
xtime "github.com/m3db/m3/src/x/time"
)
// FinalizeEncodedTagsFn is a function that will be called for each encoded tags once
// the WriteBatch itself is finalized.
type FinalizeEncodedTagsFn func(b []byte)
// FinalizeAnnotationFn is a function that will be called for each annotation once
// the WriteBatch itself is finalized.
type FinalizeAnnotationFn func(b []byte)
// Write is a write for the commitlog.
type Write struct {
Series ts.Series
Datapoint ts.Datapoint
Unit xtime.Unit
Annotation ts.Annotation
}
// PendingIndexInsert is a pending index insert.
type PendingIndexInsert struct {
Entry index.WriteBatchEntry
Document doc.Document
}
// BatchWrite represents a write that was added to the
// BatchWriter.
type BatchWrite struct {
// Used by the commitlog. If this is false, the commitlog should not write
// the series at this index.
SkipWrite bool
// PendingIndex returns whether a write has a pending index.
PendingIndex bool
// Used by the commitlog (series needed to be updated by the shard
// object first, cannot use the Series provided by the caller as it
// is missing important fields like Tags.)
Write Write
// Not used by the commitlog, provided by the caller (since the request
// is usually coming from over the wire) and is superseded by the Tags
// in Write.Series which will get set by the Shard object.
TagIter ident.TagIterator
// EncodedTags is used by the commit log, but also held onto as a reference
// here so that it can be returned to the pool after the write to commit log
// completes (since the Write.Series gets overwritten in SetOutcome so can't
// use the reference there for returning to the pool).
EncodedTags ts.EncodedTags
// Used to help the caller tie errors back to an index in their
// own collection.
OriginalIndex int
// Used by the commitlog.
Err error
}
// WriteBatch is the interface that supports adding writes to the batch,
// as well as iterating through the batched writes and resetting the
// struct (for pooling).
type WriteBatch interface {
BatchWriter
// Can't use a real iterator pattern here as it slows things down.
Iter() []BatchWrite
SetPendingIndex(idx int, pending PendingIndexInsert)
PendingIndex() []PendingIndexInsert
SetError(idx int, err error)
SetSeries(idx int, series ts.Series)
SetSkipWrite(idx int)
Reset(batchSize int, ns ident.ID)
Finalize()
// Returns the WriteBatch's internal capacity. Used by the pool to throw
// away batches that have grown too large.
cap() int
}
// BatchWriter is the interface that is used for preparing a batch of
// writes.
type BatchWriter interface {
Add(
originalIndex int,
id ident.ID,
timestamp time.Time,
value float64,
unit xtime.Unit,
annotation []byte,
) error
AddTagged(
originalIndex int,
id ident.ID,
tags ident.TagIterator,
encodedTags ts.EncodedTags,
timestamp time.Time,
value float64,
unit xtime.Unit,
annotation []byte,
) error
SetFinalizeEncodedTagsFn(f FinalizeEncodedTagsFn)
SetFinalizeAnnotationFn(f FinalizeAnnotationFn)
}