
reset
----

switch 1
----
ok

batch
set d foo
set e bar
----

flush
----

compact a-z
----
ok

switch 2
----
ok

batch
set c fooz
set f foobar
----

flush
----

compact a-z
----
ok

batch
set d foobar
----

flush
----

lsm
----
L0.0:
  000007:[d#12,SET-d#12,SET]
L6:
  000005:[c#10,SET-f#11,SET]

compact a-z block=c1
----
spun off in separate goroutine

iter
first
next
next
next
next
----
c: (fooz, .)
d: (foobar, .)
f: (foobar, .)
.
.

# This excise should cancel the in-flight compaction, causing it to error out
# below. The eventually file-only snapshot should go through because it's not
# waiting on any keys in memtables

file-only-snapshot s1
  c e
----
ok

replicate 1 2 b e
----
replicated 1 shared SSTs

unblock c1
----
ok

wait-for-file-only-snapshot s1
----
ok

lsm
----
L6:
  000010(000010):[d#14,DELSIZED-d#14,DEL]
  000011(000005):[f#11,SET-f#11,SET]

compact a-z
----
ok

wait-for-compaction-error
----
pebble: compaction cancelled by a concurrent operation, will retry compaction

iter
first
next
next
next
next
----
d: (foo, .)
f: (foobar, .)
.
.
.

batch
set d fo
set ee foobar
set f3 something
----

flush
----

compact a-z
----
ok

switch 1
----
ok

# The below file-only snapshot should not error out, despite a concurrent excise.

batch
set d something
----

flush
----

batch
set dd memory
----

file-only-snapshot s2
 c e
----
ok

iter snapshot=s2
first
next
next
next
----
d: (something, .)
dd: (memory, .)
e: (bar, .)
.

replicate 2 1 c dd
----
replicated 1 shared SSTs

wait-for-file-only-snapshot s2
----
ok

iter snapshot=s2
first
next
next
next
----
d: (something, .)
dd: (memory, .)
e: (bar, .)
.


reset
----

switch 1
----
ok

batch
set a bar
----

flush
----

compact a-z
----
ok

build ext6
set e foo
----

ingest ext6
----

lsm
----
L6:
  000005:[a#10,SET-a#10,SET]
  000006:[e#11,SET-e#11,SET]

batch
set a new
----

flush
----

batch
set d new
set e new
----

flush
----

lsm
----
L0.0:
  000008:[a#12,SET-a#12,SET]
  000010:[d#13,SET-e#14,SET]
L6:
  000005:[a#10,SET-a#10,SET]
  000006:[e#11,SET-e#11,SET]

build ext5
set bb something
set b something
del-range b c
----

lsm
----
L0.0:
  000008:[a#12,SET-a#12,SET]
  000010:[d#13,SET-e#14,SET]
L6:
  000005:[a#10,SET-a#10,SET]
  000006:[e#11,SET-e#11,SET]

compact a-e block=c1
----
spun off in separate goroutine

batch
set bb new
----

iter
first
next
next
next
next
----
a: (new, .)
bb: (new, .)
d: (new, .)
e: (new, .)
.

lsm
----
L0.0:
  000008:[a#12,SET-a#12,SET]
  000010:[d#13,SET-e#14,SET]
L6:
  000005:[a#10,SET-a#10,SET]
  000006:[e#11,SET-e#11,SET]

ingest-and-excise ext5 excise=b-c
----

iter
first
next
next
next
----
a: (new, .)
b: (something, .)
bb: (something, .)
d: (new, .)

lsm
----
L0.0:
  000008:[a#12,SET-a#12,SET]
  000010:[d#13,SET-e#14,SET]
L6:
  000005:[a#10,SET-a#10,SET]
  000012:[b#17,RANGEDEL-c#inf,RANGEDEL]
  000006:[e#11,SET-e#11,SET]

unblock c1
----
ok

compact a-z
----
ok

iter
first
next
next
next
next
----
a: (new, .)
b: (something, .)
bb: (something, .)
d: (new, .)
e: (new, .)

lsm
----
L6:
  000015:[a#0,SET-e#0,SET]
