# Size of value index is 3 bytes plus 5 + 5 = 10 bytes of trailer of the value
# block and value index block. So size 18 - 13 = 5 size of the value in the
# value block.
build
a@2.SET.1:a2
b@5.SET.7:b5
b@4.DEL.3:
b@3.SET.2:bat3
b@2.SET.1:vbat2
----
value-blocks: num-values 1, num-blocks: 1, size: 18

scan-raw
----
a@2#1,1:in-place a2, same-pre false
b@5#7,1:in-place b5, same-pre false
b@4#3,0:
b@3#2,1:in-place bat3, same-pre false
b@2#1,1:value-handle len 5 block 0 offset 0, att 5, same-pre true

scan
----
a@2#1,1:a2
b@5#7,1:b5
b@4#3,0:
b@3#2,1:bat3
b@2#1,1:vbat2

scan-cloned-lazy-values
----
0(in-place: len 2): a2
1(in-place: len 2): b5
2(in-place: len 0): 
3(in-place: len 4): bat3
4(lazy: len 5, attr: 5): vbat2

# Size of value index is 3 bytes plus 5 + 5 = 10 bytes of trailer of the value
# block and value index block. So size 33 - 13 = 20 is the total size of the
# values in the value block.
build
blue@10.SET.20:blue10
blue@8.SET.18:blue8
blue@8.SET.16:blue8s
blue@6.DEL.14:
blue@4.SET.12:blue4
blue@3.SET.10:blue3
red@9.SET.18:red9
red@7.SET.8:red7
----
value-blocks: num-values 4, num-blocks: 1, size: 33

scan-raw
----
blue@10#20,1:in-place blue10, same-pre false
blue@8#18,1:value-handle len 5 block 0 offset 0, att 5, same-pre true
blue@8#16,1:value-handle len 6 block 0 offset 5, att 6, same-pre true
blue@6#14,0:
blue@4#12,1:in-place blue4, same-pre false
blue@3#10,1:value-handle len 5 block 0 offset 11, att 5, same-pre true
red@9#18,1:in-place red9, same-pre false
red@7#8,1:value-handle len 4 block 0 offset 16, att 4, same-pre true

scan
----
blue@10#20,1:blue10
blue@8#18,1:blue8
blue@8#16,1:blue8s
blue@6#14,0:
blue@4#12,1:blue4
blue@3#10,1:blue3
red@9#18,1:red9
red@7#8,1:red7

scan-cloned-lazy-values
----
0(in-place: len 6): blue10
1(lazy: len 5, attr: 5): blue8
2(lazy: len 6, attr: 6): blue8s
3(in-place: len 0): 
4(in-place: len 5): blue4
5(lazy: len 5, attr: 5): blue3
6(in-place: len 4): red9
7(lazy: len 4, attr: 4): red7

# Multiple value blocks. Trailers of 5+5+5 for the two value blocks and the
# value index block, totals to 15. The values are 5+6+15=26. The value index
# block has to encode two tuples, each of 4 bytes (blockNumByteLength=1,
# blockOffsetByteLength=2, blockLengthByteLength=1), so 2*4=8. The total is
# 15+26+8=49 bytes, which corresponds to "size: 49" below.
build block-size=8
blue@10.SET.20:blue10
blue@8.SET.18:blue8
blue@8.SET.16:blue8s
blue@6.SET.16:blue6isverylong
----
value-blocks: num-values 3, num-blocks: 2, size: 49

scan-raw
----
blue@10#20,1:in-place blue10, same-pre false
blue@8#18,1:value-handle len 5 block 0 offset 0, att 5, same-pre true
blue@8#16,1:value-handle len 6 block 0 offset 5, att 6, same-pre true
blue@6#16,1:value-handle len 15 block 1 offset 0, att 7, same-pre true

scan
----
blue@10#20,1:blue10
blue@8#18,1:blue8
blue@8#16,1:blue8s
blue@6#16,1:blue6isverylong

scan-cloned-lazy-values
----
0(in-place: len 6): blue10
1(lazy: len 5, attr: 5): blue8
2(lazy: len 6, attr: 6): blue8s
3(lazy: len 15, attr: 7): blue6isverylong

layout
----
         0  data (33)
         0    record (25 = 3 [0] + 15 + 7) [restart]
                blue@10#20,1:blue10
        25    [restart 0]
        33    [trailer compression=none checksum=0x5fb0d551]
        38  data (29)
        38    record (21 = 3 [0] + 14 + 4) [restart]
                blue@8#18,1:value handle {valueLen:5 blockNum:0 offsetInBlock:0}
        59    [restart 38]
        67    [trailer compression=none checksum=0x628e4a10]
        72  data (29)
        72    record (21 = 3 [0] + 14 + 4) [restart]
                blue@8#16,1:value handle {valueLen:6 blockNum:0 offsetInBlock:5}
        93    [restart 72]
       101    [trailer compression=none checksum=0xdc74261]
       106  data (29)
       106    record (21 = 3 [0] + 14 + 4) [restart]
                blue@6#16,1:value handle {valueLen:15 blockNum:1 offsetInBlock:0}
       127    [restart 106]
       135    [trailer compression=none checksum=0x9f60e629]
       140  index (28)
       140    block:0/33 [restart]
       160    [restart 140]
       168    [trailer compression=none checksum=0x32b37f08]
       173  index (27)
       173    block:38/29 [restart]
       192    [restart 173]
       200    [trailer compression=none checksum=0x21d27815]
       205  index (27)
       205    block:72/29 [restart]
       224    [restart 205]
       232    [trailer compression=none checksum=0xbae26eb3]
       237  index (22)
       237    block:106/29 [restart]
       251    [restart 237]
       259    [trailer compression=none checksum=0x802be702]
       264  top-index (77)
       264    block:140/28 [restart]
       285    block:173/27 [restart]
       305    block:205/27 [restart]
       325    block:237/22 [restart]
       340    [restart 264]
       344    [restart 285]
       348    [restart 305]
       352    [restart 325]
       341    [trailer compression=snappy checksum=0x6b2d79b]
       346  value-block (11)
       362  value-block (15)
       382  value-index (8)
       395  properties (785)
       395    pebble.num.value-blocks (27) [restart]
       422    pebble.num.values.in.value-blocks (21)
       443    pebble.value-blocks.size (21)
       464    rocksdb.block.based.table.index.type (43)
       507    rocksdb.block.based.table.prefix.filtering (20)
       527    rocksdb.block.based.table.whole.key.filtering (23)
       550    rocksdb.column.family.id (24)
       574    rocksdb.comparator (35)
       609    rocksdb.compression (16)
       625    rocksdb.compression_options (106)
       731    rocksdb.creation.time (16)
       747    rocksdb.data.size (14)
       761    rocksdb.deleted.keys (15)
       776    rocksdb.external_sst_file.global_seqno (41)
       817    rocksdb.external_sst_file.version (14)
       831    rocksdb.filter.size (15)
       846    rocksdb.fixed.key.length (18)
       864    rocksdb.format.version (17)
       881    rocksdb.index.key.is.user.key (25)
       906    rocksdb.index.partitions (14)
       920    rocksdb.index.size (9)
       929    rocksdb.index.value.is.delta.encoded (26)
       955    rocksdb.merge.operands (18)
       973    rocksdb.merge.operator (24)
       997    rocksdb.num.data.blocks (19)
      1016    rocksdb.num.entries (11)
      1027    rocksdb.num.range-deletions (19)
      1046    rocksdb.oldest.key.time (19)
      1065    rocksdb.prefix.extractor.name (31)
      1096    rocksdb.property.collectors (22)
      1118    rocksdb.raw.key.size (16)
      1134    rocksdb.raw.value.size (14)
      1148    rocksdb.top-level.index.size (24)
      1172    [restart 395]
      1180    [trailer compression=none checksum=0x4352b7fd]
      1185  meta-index (64)
      1185    pebble.value_index block:382/8 value-blocks-index-lengths: 1(num), 2(offset), 1(length) [restart]
      1212    rocksdb.properties block:395/785 [restart]
      1237    [restart 1185]
      1241    [restart 1212]
      1249    [trailer compression=none checksum=0xe7aed935]
      1254  footer (53)
      1254    checksum type: crc32c
      1255    meta: offset=1185, length=64
      1258    index: offset=264, length=77
      1261    [padding]
      1295    version: 3
      1299    magic number: 0xf09faab3f09faab3
      1307  EOF

# Require that [c,e) must be in-place.
build in-place-bound=(c,e)
blue@10.SET.20:blue10
blue@8.SET.18:blue8
c@10.SET.16:c10
c@8.SET.14:c8
e@20.SET.25:eat20
e@18.SET.23:eat18
----
value-blocks: num-values 2, num-blocks: 1, size: 23

scan-raw
----
blue@10#20,1:in-place blue10, same-pre false
blue@8#18,1:value-handle len 5 block 0 offset 0, att 5, same-pre true
c@10#16,1:in-place c10, same-pre false
c@8#14,1:in-place c8, same-pre false
e@20#25,1:in-place eat20, same-pre false
e@18#23,1:value-handle len 5 block 0 offset 5, att 5, same-pre true

scan
----
blue@10#20,1:blue10
blue@8#18,1:blue8
c@10#16,1:c10
c@8#14,1:c8
e@20#25,1:eat20
e@18#23,1:eat18

scan-cloned-lazy-values
----
0(in-place: len 6): blue10
1(lazy: len 5, attr: 5): blue8
2(in-place: len 3): c10
3(in-place: len 2): c8
4(in-place: len 5): eat20
5(lazy: len 5, attr: 5): eat18

# Try write empty values to value blocks.
build
b@5.SET.7:b5
b@3.SET.2:
c@6.DEL.7:
c@5.DEL.6:
----
value-blocks: num-values 0, num-blocks: 0, size: 0

scan-raw
----
b@5#7,1:in-place b5, same-pre false
b@3#2,1:in-place , same-pre true
c@6#7,0:
c@5#6,0:

scan
----
b@5#7,1:b5
b@3#2,1:
c@6#7,0:
c@5#6,0:

layout
----
         0  data (66)
         0    record (17 = 3 [0] + 11 + 3) [restart]
                b@5#7,1:b5
        17    record (14 = 3 [1] + 10 + 1)
                b@3#2,1:
        31    record (14 = 3 [0] + 11 + 0)
                c@6#7,0:
        45    record (13 = 3 [1] + 10 + 0)
                c@5#6,0:
        58    [restart 0]
        66    [trailer compression=none checksum=0x4e91250f]
        71  index (22)
        71    block:0/66 [restart]
        85    [restart 71]
        93    [trailer compression=none checksum=0xf80f5bcf]
        98  properties (676)
        98    rocksdb.block.based.table.index.type (43) [restart]
       141    rocksdb.block.based.table.prefix.filtering (20)
       161    rocksdb.block.based.table.whole.key.filtering (23)
       184    rocksdb.column.family.id (24)
       208    rocksdb.comparator (35)
       243    rocksdb.compression (16)
       259    rocksdb.compression_options (106)
       365    rocksdb.creation.time (16)
       381    rocksdb.data.size (13)
       394    rocksdb.deleted.keys (15)
       409    rocksdb.external_sst_file.global_seqno (41)
       450    rocksdb.external_sst_file.version (14)
       464    rocksdb.filter.size (15)
       479    rocksdb.fixed.key.length (18)
       497    rocksdb.format.version (17)
       514    rocksdb.index.key.is.user.key (25)
       539    rocksdb.index.size (8)
       547    rocksdb.index.value.is.delta.encoded (26)
       573    rocksdb.merge.operands (18)
       591    rocksdb.merge.operator (24)
       615    rocksdb.num.data.blocks (19)
       634    rocksdb.num.entries (11)
       645    rocksdb.num.range-deletions (19)
       664    rocksdb.oldest.key.time (19)
       683    rocksdb.prefix.extractor.name (31)
       714    rocksdb.property.collectors (22)
       736    rocksdb.raw.key.size (16)
       752    rocksdb.raw.value.size (14)
       766    [restart 98]
       774    [trailer compression=none checksum=0x9367b10c]
       779  meta-index (32)
       779    rocksdb.properties block:98/676 [restart]
       803    [restart 779]
       811    [trailer compression=none checksum=0xca0f17d]
       816  footer (53)
       816    checksum type: crc32c
       817    meta: offset=779, length=32
       820    index: offset=71, length=22
       822    [padding]
       857    version: 3
       861    magic number: 0xf09faab3f09faab3
       869  EOF
