-
Notifications
You must be signed in to change notification settings - Fork 199
/
batch_attr.go
293 lines (251 loc) · 6.18 KB
/
batch_attr.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// Copyright 2014-2022 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package aerospike
type batchAttr struct {
filterExp *Expression
readAttr int
writeAttr int
infoAttr int
expiration uint32
generation uint32
hasWrite bool
sendKey bool
}
func newBatchAttr(policy *BatchPolicy, rattr int) *batchAttr {
res := &batchAttr{}
res.setRead(policy)
res.readAttr |= rattr
return res
}
func newBatchAttrOps(rp *BatchPolicy, wp *BatchWritePolicy, ops []*Operation) {
res := &batchAttr{}
readAllBins := false
readHeader := false
hasRead := false
hasWriteOp := false
for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readHeader = true
hasRead = true
case _BIT_READ, _EXP_READ, _HLL_READ, _MAP_READ, _CDT_READ, _READ:
// _Read all bins if no bin is specified.
if op.binName == "" {
readAllBins = true
}
hasRead = true
default:
hasWriteOp = true
}
}
if hasWriteOp {
res.setBatchWrite(wp)
if hasRead {
res.readAttr |= _INFO1_READ
if readAllBins {
res.readAttr |= _INFO1_GET_ALL
} else if readHeader {
res.readAttr |= _INFO1_NOBINDATA
}
}
} else {
res.setRead(rp)
if readAllBins {
res.readAttr |= _INFO1_GET_ALL
} else if readHeader {
res.readAttr |= _INFO1_NOBINDATA
}
}
}
func (ba *batchAttr) setRead(rp *BatchPolicy) {
ba.filterExp = nil
ba.readAttr = _INFO1_READ
if rp.ReadModeAP == ReadModeAPAll {
ba.readAttr |= _INFO1_READ_MODE_AP_ALL
}
ba.writeAttr = 0
switch rp.ReadModeSC {
default:
case ReadModeSCSession:
ba.infoAttr = 0
case ReadModeSCLinearize:
ba.infoAttr = _INFO3_SC_READ_TYPE
case ReadModeSCAllowReplica:
ba.infoAttr = _INFO3_SC_READ_RELAX
case ReadModeSCAllowUnavailable:
ba.infoAttr = _INFO3_SC_READ_TYPE | _INFO3_SC_READ_RELAX
}
ba.expiration = uint32(rp.ReadTouchTTLPercent)
ba.generation = 0
ba.hasWrite = false
ba.sendKey = false
}
func (ba *batchAttr) setBatchRead(rp *BatchReadPolicy) {
ba.filterExp = rp.FilterExpression
ba.readAttr = _INFO1_READ
if rp.ReadModeAP == ReadModeAPAll {
ba.readAttr |= _INFO1_READ_MODE_AP_ALL
}
ba.writeAttr = 0
switch rp.ReadModeSC {
default:
case ReadModeSCSession:
ba.infoAttr = 0
case ReadModeSCLinearize:
ba.infoAttr = _INFO3_SC_READ_TYPE
case ReadModeSCAllowReplica:
ba.infoAttr = _INFO3_SC_READ_RELAX
case ReadModeSCAllowUnavailable:
ba.infoAttr = _INFO3_SC_READ_TYPE | _INFO3_SC_READ_RELAX
}
ba.expiration = uint32(rp.ReadTouchTTLPercent)
ba.generation = 0
ba.hasWrite = false
ba.sendKey = false
}
func (ba *batchAttr) adjustRead(ops []*Operation) {
readAllBins := false
readHeader := false
for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readHeader = true
case _BIT_READ, _EXP_READ, _HLL_READ, _MAP_READ, _CDT_READ, _READ:
// Read all bins if no bin is specified.
if op.binName == "" {
readAllBins = true
}
default:
}
}
if readAllBins {
ba.readAttr |= _INFO1_GET_ALL
} else if readHeader {
ba.readAttr |= _INFO1_NOBINDATA
}
}
func (ba *batchAttr) adjustReadForAllBins(readAllBins bool) {
if readAllBins {
ba.readAttr |= _INFO1_GET_ALL
} else {
ba.readAttr |= _INFO1_NOBINDATA
}
}
func (ba *batchAttr) setBatchWrite(wp *BatchWritePolicy) {
ba.filterExp = wp.FilterExpression
ba.readAttr = 0
ba.writeAttr = _INFO2_WRITE | _INFO2_RESPOND_ALL_OPS
ba.infoAttr = 0
ba.expiration = wp.Expiration
ba.hasWrite = true
ba.sendKey = wp.SendKey
switch wp.GenerationPolicy {
default:
fallthrough
case NONE:
ba.generation = 0
case EXPECT_GEN_EQUAL:
ba.generation = wp.Generation
ba.writeAttr |= _INFO2_GENERATION
case EXPECT_GEN_GT:
ba.generation = wp.Generation
ba.writeAttr |= _INFO2_GENERATION_GT
}
switch wp.RecordExistsAction {
case UPDATE:
case UPDATE_ONLY:
ba.infoAttr |= _INFO3_UPDATE_ONLY
case REPLACE:
ba.infoAttr |= _INFO3_CREATE_OR_REPLACE
case REPLACE_ONLY:
ba.infoAttr |= _INFO3_REPLACE_ONLY
case CREATE_ONLY:
ba.writeAttr |= _INFO2_CREATE_ONLY
}
if wp.DurableDelete {
ba.writeAttr |= _INFO2_DURABLE_DELETE
}
if wp.CommitLevel == COMMIT_MASTER {
ba.infoAttr |= _INFO3_COMMIT_MASTER
}
}
func (ba *batchAttr) adjustWrite(ops []*Operation) {
readAllBins := false
readHeader := false
hasRead := false
for _, op := range ops {
switch op.opType {
case _READ_HEADER:
readHeader = true
hasRead = true
case _BIT_READ, _EXP_READ, _HLL_READ, _MAP_READ, _CDT_READ, _READ:
// _Read all bins if no bin is specified.
if op.binName == "" {
readAllBins = true
}
hasRead = true
default:
}
}
if hasRead {
ba.readAttr |= _INFO1_READ
if readAllBins {
ba.readAttr |= _INFO1_GET_ALL
} else if readHeader {
ba.readAttr |= _INFO1_NOBINDATA
}
}
}
func (ba *batchAttr) setBatchUDF(up *BatchUDFPolicy) {
ba.filterExp = up.FilterExpression
ba.readAttr = 0
ba.writeAttr = _INFO2_WRITE
ba.infoAttr = 0
ba.expiration = up.Expiration
ba.generation = 0
ba.hasWrite = true
ba.sendKey = up.SendKey
if up.DurableDelete {
ba.writeAttr |= _INFO2_DURABLE_DELETE
}
if up.CommitLevel == COMMIT_MASTER {
ba.infoAttr |= _INFO3_COMMIT_MASTER
}
}
func (ba *batchAttr) setBatchDelete(dp *BatchDeletePolicy) {
ba.filterExp = dp.FilterExpression
ba.readAttr = 0
ba.writeAttr = _INFO2_WRITE | _INFO2_RESPOND_ALL_OPS | _INFO2_DELETE
ba.infoAttr = 0
ba.expiration = 0
ba.hasWrite = true
ba.sendKey = dp.SendKey
switch dp.GenerationPolicy {
default:
case NONE:
ba.generation = 0
case EXPECT_GEN_EQUAL:
ba.generation = dp.Generation
ba.writeAttr |= _INFO2_GENERATION
case EXPECT_GEN_GT:
ba.generation = dp.Generation
ba.writeAttr |= _INFO2_GENERATION_GT
}
if dp.DurableDelete {
ba.writeAttr |= _INFO2_DURABLE_DELETE
}
if dp.CommitLevel == COMMIT_MASTER {
ba.infoAttr |= _INFO3_COMMIT_MASTER
}
}