-
Notifications
You must be signed in to change notification settings - Fork 480
/
Copy pathindexed_batch_mutation
471 lines (384 loc) · 6.61 KB
/
indexed_batch_mutation
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# Set a key within the indexed batch.
new-batch
set foo foo
----
# Construct an iterator over the indexed batch.
new-iter i0
----
# The key we set should be visible.
iter iter=i0
first
next
----
foo: (foo, .)
.
# Set a new key, while the above iterator is still open.
mutate
set bar bar
----
# The new key should be invisible.
iter iter=i0
prev
next
----
foo: (foo, .)
.
# A set-options operation should refresh the Iterator's view of the batch. The
# bar key should now be visibile.
iter iter=i0
set-options
first
next
next
----
.
bar: (bar, .)
foo: (foo, .)
.
# Delete foo with a range deletion.
mutate
del-range f g
----
# Both keys should still be visible.
iter iter=i0
prev
prev
----
foo: (foo, .)
bar: (bar, .)
# After refreshing the iterator's view of the batch, foo should be deleted.
iter iter=i0
set-options
seek-ge foo
seek-lt foo
----
.
.
bar: (bar, .)
# Write a range key set and a point key.
mutate
range-key-set a c @1 boop
set b b
----
# The mutations should not be visible.
iter iter=i0
prev
next
----
.
bar: (bar, .)
# But refreshing the batch through a call to SetOptions should surface them.
iter iter=i0
set-options
first
next
next
----
.
a: (., [a-c) @1=boop)
b: (b, [a-c) @1=boop)
bar: (bar, [a-c) @1=boop)
# Remove part of the range key to fragment it.
mutate
range-key-del ace arc
----
iter iter=i0
next
prev
prev
prev
prev
----
.
bar: (bar, [a-c) @1=boop)
b: (b, [a-c) @1=boop)
a: (., [a-c) @1=boop)
.
iter iter=i0
set-options
first
next
next
next
----
.
a: (., [a-ace) @1=boop)
arc: (., [arc-c) @1=boop)
b: (b, [arc-c) @1=boop)
bar: (bar, [arc-c) @1=boop)
# Create a new indexed batch and a new iterator over it.
new-batch
set foo foo
----
new-iter i1
----
iter iter=i1
first
next
----
foo: (foo, .)
.
# Test interactions with cloned iterators.
# First, apply mutations to the batch. They should remain invisible.
mutate
set bar bar
range-key-set a z @1 boop
del-range f g
----
iter iter=i1
first
next
----
foo: (foo, .)
.
# Clone i1 to create i2.
clone from=i1 to=i2 refresh-batch=false
----
# i1 unchanged.
iter iter=i1
first
next
----
foo: (foo, .)
.
# i2 sees exactly the same stale state as i1 until SetOptions is called to
# explicitly refresh the view of the underlying batch.
iter iter=i2
first
next
set-options
first
next
next
----
foo: (foo, .)
.
.
a: (., [a-z) @1=boop)
bar: (bar, [a-z) @1=boop)
.
# Clone i1 to create i3, this time passing RefreshBatchView: true. This clone
# should view the updated view of the underlying batch.
clone from=i1 to=i3 refresh-batch=true
----
iter iter=i3
first
next
----
a: (., [a-z) @1=boop)
bar: (bar, [a-z) @1=boop)
# i1 should still have the old, stale view of the batch.
iter iter=i1
first
next
----
foo: (foo, .)
.
# Mutate the underlying batch again.
mutate
set foo foo
range-key-set a z @2 bax
del-range b c
----
# The new mutations should be invisible until SetOptions is called.
iter iter=i1
first
next
set-options
first
next
next
----
foo: (foo, .)
.
.
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
iter iter=i2
first
next
next
set-options
first
next
next
----
a: (., [a-z) @1=boop)
bar: (bar, [a-z) @1=boop)
.
.
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
# Commit a separate batch to the underlying engine.
batch
range-key-set a z @5 poi
set apple apple
----
# The writes to the underlying engine should be invisible.
iter iter=i1
first
next
next
----
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
# Clone i1 to create i4.
clone from=i1 to=i4 refresh-batch=false
----
iter iter=i4
first
next
next
----
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
# Refresh i4's view of its batch. It should still not see the newly committed
# writes.
iter iter=i4
set-options
first
next
next
----
.
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
# Create a new iterator i5 over the indexed batch [not a Clone]. It should see
# all committed writes and uncommitted writes.
new-iter i5
----
iter iter=i5
first
next
next
next
----
a: (., [a-z) @5=poi, @2=bax, @1=boop)
apple: (apple, [a-z) @5=poi, @2=bax, @1=boop)
foo: (foo, [a-z) @5=poi, @2=bax, @1=boop)
.
# Mutate all the open iterators' underlying batch.
mutate
range-key-set a z @6 yaya
set c c
----
# The iterators should still not see the committed writes, even after refreshing
# to observe more recent batch writes.
iter iter=i1
first
next
next
----
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
iter iter=i4
first
next
next
set-options
first
next
next
----
a: (., [a-z) @2=bax, @1=boop)
foo: (foo, [a-z) @2=bax, @1=boop)
.
.
a: (., [a-z) @6=yaya, @2=bax, @1=boop)
c: (c, [a-z) @6=yaya, @2=bax, @1=boop)
foo: (foo, [a-z) @6=yaya, @2=bax, @1=boop)
# Test a scenario where constructing an Iterator should NOT use the cached
# fragmented tombstones / range keys, because the new Iterator is a Clone which
# must read at an earlier batch sequence number.
# Reset and start a new batch.
reset
----
new-batch
set foo foo
----
new-iter i1
----
iter iter=i1
first
next
----
foo: (foo, .)
.
# Apply a range deletion and a range key.
mutate
del-range a z
range-key-set a z @1 foo
----
# Create a new iterator which will see both the range deletion and the range
# key, and cache both on the batch so that future iterators constructed over the
# batch do not need to.
new-iter i2
----
iter iter=i2
first
next
----
a: (., [a-z) @1=foo)
.
# Clone the original iterator from before the delete range and the range key
# were created. It should not use the cached fragments of range deletions or
# range keys, and should not see the effects of either.
clone from=i1 to=i3 refresh-batch=false
----
iter iter=i3
first
next
----
foo: (foo, .)
.
reset
----
new-batch
range-key-set a c @1 poi
range-key-set b d @2 yaya
----
new-iter i1
----
# The batch contains 2 range keys, but the skiplist of fragmented range keys
# contains 3 elements (a-b, b-c, c-d).
iter iter=i1
first
next
next
----
a: (., [a-b) @1=poi)
b: (., [b-c) @2=yaya, @1=poi)
c: (., [c-d) @2=yaya)
# Add a new range key to the batch. The batch contains 3 internal range keys,
# and the skiplist of fragmented range keys contains 3 elements.
mutate
range-key-set e f @3 foo
----
# Refreshing the iterator's view of the batch through SetOptions should surface
# the new range key. An earlier bug incorrectly compared the number of
# fragmented range keys to the number of internal batch range keys in order to
# determine when to refresh the iterator.
iter iter=i1
first
next
next
set-options
first
next
next
next
----
a: (., [a-b) @1=poi)
b: (., [b-c) @2=yaya, @1=poi)
c: (., [c-d) @2=yaya)
.
a: (., [a-b) @1=poi)
b: (., [b-c) @2=yaya, @1=poi)
c: (., [c-d) @2=yaya)
e: (., [e-f) @3=foo)