# Test a value separation policy that writes new blob files, and that the policy
# obeys the minimum size. A blob file should only be created, and only the
# values "yuumi" and "poiandyaya" should be stored in them. Input values that
# are stored in existing blob files should be retrieved.

init write-new-blob-files minimum-size=5
----

add
bar#201,SET:poi
bax#202,SET:blob{value=yaya}
----
# create: 000001.sst
RawWriter.Add("bar#201,SET", "poi", false)
RawWriter.Add("bax#202,SET", "yaya", false)

estimated-sizes
----
file: 0, references: 0

add
baz#202,SET:blob{value=yuumi}
foo#209,SET:poiandyaya
----
# create: 000002.blob
RawWriter.AddWithBlobHandle("baz#202,SET", "(f0,blk0,id0,len5)", 0, false)
RawWriter.AddWithBlobHandle("foo#209,SET", "(f0,blk0,id1,len10)", 0, false)

# Ensure that merge and deletesized keys do not get separated if they meet the
# minimum size.
add
gaa#210,MERGE:chickenpigeon
gaa#209,DELSIZED:varint(16)
gac#211,SET:yuumiisthebest
----
RawWriter.Add("gaa#210,MERGE", "chickenpigeon", false)
RawWriter.Add("gaa#209,DELSIZED", "varint(16)", false)
RawWriter.AddWithBlobHandle("gac#211,SET", "(f0,blk0,id2,len14)", 0, false)

estimated-sizes
----
file: 99, references: 99

close-output
----
# sync-data: 000001.sst
# close: 000001.sst
# sync-data: 000002.blob
# close: 000002.blob
Blob file created: 000002 size:[120 (120B)] vals:[29 (29B)]
{BlockCount: 1, ValueCount: 3, UncompressedValueBytes: 29, FileLen: 120}
blobrefs:[
 0: B000002 29
]

add
zoo#220,SET:mai
----
# create: 000003.sst
RawWriter.Add("zoo#220,SET", "mai", false)

estimated-sizes
----
file: 0, references: 0

close-output
----
# sync-data: 000003.sst
# close: 000003.sst
no blob file created
blobrefs:[]

# Test a policy to never separate values. Existing blob handles should be
# retrieved and stored inline.

init never-separate-values
----

add
a#9,SET:blob{value=poipoipoipoipoi}
b#8,SET:yayayayayayaya
c#7,SET:blob{value=maimaimaimaimai}
d#6,SET:yuumiyuumiyuumiyuumi
----
# create: 000004.sst
RawWriter.Add("a#9,SET", "poipoipoipoipoi", false)
RawWriter.Add("b#8,SET", "yayayayayayaya", false)
RawWriter.Add("c#7,SET", "maimaimaimaimai", false)
RawWriter.Add("d#6,SET", "yuumiyuumiyuumiyuumi", false)

estimated-sizes
----
file: 0, references: 0

close-output
----
# sync-data: 000004.sst
# close: 000004.sst
no blob file created
blobrefs:[]

# Test a policy to preserve blob references. We need to configure it with a set
# of blob file metadatas for blob files that are referenced by the compaction's
# input sstables. The compaction should only observe references to these files.

init preserve-blob-references
B000001 physical:{000001 size:[903530] vals:[39531]}
B000002 physical:{000002 size:[82530] vals:[72111]}
B000003 physical:{000003 size:[192542] vals:[85225]}
----

add
a#9,SET:blob{fileNum=000001 value=darcy}
a#5,SET:blob{fileNum=000003 value=tani}
b#2,DEL:
c#9,SET:paddy
----
# create: 000005.sst
RawWriter.AddWithBlobHandle("a#9,SET", "(f0,blk0,id0,len5)", 5, false)
RawWriter.AddWithBlobHandle("a#5,SET", "(f1,blk0,id0,len4)", 4, false)
RawWriter.Add("b#2,DEL", "", false)
RawWriter.Add("c#9,SET", "paddy", false)

estimated-sizes
----
file: 0, references: 9

close-output
----
# sync-data: 000005.sst
# close: 000005.sst
no blob file created
blobrefs:[
 0: B000001 5
 1: B000003 4
]

add
d#2,DEL:
e#9,SET:blob{value=yayoi}
----
# create: 000006.sst
RawWriter.Add("d#2,DEL", "", false)
RawWriter.AddWithBlobHandle("e#9,SET", "(f0,blk0,id1,len5)", 5, false)

estimated-sizes
----
file: 0, references: 5

close-output
----
# sync-data: 000006.sst
# close: 000006.sst
no blob file created
blobrefs:[
 0: B000003 5
]

# Test handling of a short attribute extractor that errors when we attempt to
# extract the short attribute. We should fall back to writing the value inplace
# within the output sstable.

init write-new-blob-files minimum-size=2 short-attr-extractor=error
----

add
bar#201,SET:poi
bax#202,SET:blob{value=yaya}
----
# create: 000007.sst
# invalid value for key "bar", value: "poi": short attribute extractor error
RawWriter.Add("bar#201,SET", "poi", false)
# invalid value for key "bax", value: "yaya": short attribute extractor error
RawWriter.Add("bax#202,SET", "yaya", false)

close-output
----
# sync-data: 000007.sst
# close: 000007.sst
no blob file created
blobrefs:[]
