sstables: Handle empty counter value in read path

Due to a bug in an sstable writer, empty counters
were stored without a header.

Correct way of storing empty counter is to still write
a header that indicates the emptiness.

Next patch in this series fixes the write path
but we have to make sure that we handle incorrectly
serialized counters in the read path becuase there
may exist sstables with counters stored without header.

Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>
This commit is contained in:
Piotr Jastrzebski
2019-05-20 16:17:49 +02:00
parent d92973ba86
commit f711cce024

View File

@@ -44,6 +44,14 @@ namespace sstables {
atomic_cell make_counter_cell(api::timestamp_type timestamp, bytes_view value) {
static constexpr size_t shard_size = 32;
if (value.empty()) {
// This will never happen in a correct MC sstable but
// we had a bug #4363 that caused empty counters
// to be incorrectly stored inside sstables.
counter_cell_builder ccb;
return ccb.build(timestamp);
}
data_input in(value);
auto header_size = in.read<int16_t>();