-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathcollection_bulk.go
202 lines (159 loc) · 4.41 KB
/
collection_bulk.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
//nolint:unused
package gocb
import (
"context"
"time"
)
type bulkOp struct {
finishFn func()
}
func (op *bulkOp) finish() {
op.finishFn()
}
// BulkOp represents a single operation that can be submitted (within a list of more operations) to .Do()
// You can create a bulk operation by instantiating one of the implementations of BulkOp,
// such as GetOp, UpsertOp, ReplaceOp, and more.
// UNCOMMITTED: This API may change in the future.
type BulkOp interface {
isBulkOp()
finish()
}
// BulkOpOptions are the set of options available when performing BulkOps using Do.
type BulkOpOptions struct {
Timeout time.Duration
Transcoder Transcoder
RetryStrategy RetryStrategy
ParentSpan RequestSpan
// Using a deadlined Context alongside a Timeout will cause the shorter of the two to cause cancellation, this
// also applies to global level timeouts.
// UNCOMMITTED: This API may change in the future.
Context context.Context
}
// Do execute one or more `BulkOp` items in parallel.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) Do(ops []BulkOp, opts *BulkOpOptions) error {
return autoOpControlErrorOnly(c.kvBulkController(), "", func(agent kvBulkProvider) error {
if opts == nil {
opts = &BulkOpOptions{}
}
return agent.Do(c, ops, opts)
})
}
// GetOp represents a type of `BulkOp` used for Get operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type GetOp struct {
bulkOp
ID string
Result *GetResult
Err error
}
func (item *GetOp) isBulkOp() {}
// GetAndTouchOp represents a type of `BulkOp` used for GetAndTouch operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type GetAndTouchOp struct {
bulkOp
ID string
Expiry time.Duration
Result *GetResult
Err error
}
func (item *GetAndTouchOp) isBulkOp() {}
// TouchOp represents a type of `BulkOp` used for Touch operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type TouchOp struct {
bulkOp
ID string
Expiry time.Duration
Result *MutationResult
Err error
}
func (item *TouchOp) isBulkOp() {}
// RemoveOp represents a type of `BulkOp` used for Remove operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type RemoveOp struct {
bulkOp
ID string
Cas Cas
Result *MutationResult
Err error
}
func (item *RemoveOp) isBulkOp() {}
// UpsertOp represents a type of `BulkOp` used for Upsert operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type UpsertOp struct {
bulkOp
ID string
Value interface{}
Expiry time.Duration
Cas Cas
Result *MutationResult
Err error
}
func (item *UpsertOp) isBulkOp() {}
// InsertOp represents a type of `BulkOp` used for Insert operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type InsertOp struct {
bulkOp
ID string
Value interface{}
Expiry time.Duration
Result *MutationResult
Err error
}
func (item *InsertOp) isBulkOp() {}
// ReplaceOp represents a type of `BulkOp` used for Replace operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type ReplaceOp struct {
bulkOp
ID string
Value interface{}
Expiry time.Duration
Cas Cas
Result *MutationResult
Err error
}
func (item *ReplaceOp) isBulkOp() {}
// AppendOp represents a type of `BulkOp` used for Append operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type AppendOp struct {
bulkOp
ID string
Value string
Result *MutationResult
Err error
}
func (item *AppendOp) isBulkOp() {}
// PrependOp represents a type of `BulkOp` used for Prepend operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type PrependOp struct {
bulkOp
ID string
Value string
Result *MutationResult
Err error
}
func (item *PrependOp) isBulkOp() {}
// IncrementOp represents a type of `BulkOp` used for Increment operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type IncrementOp struct {
bulkOp
ID string
Delta int64
Initial int64
Expiry time.Duration
Result *CounterResult
Err error
}
func (item *IncrementOp) isBulkOp() {}
// DecrementOp represents a type of `BulkOp` used for Decrement operations. See BulkOp.
// UNCOMMITTED: This API may change in the future.
type DecrementOp struct {
bulkOp
ID string
Delta int64
Initial int64
Expiry time.Duration
Result *CounterResult
Err error
}
func (item *DecrementOp) isBulkOp() {}