From f711cce024ef587da76e5a67fc012ec9b2987472 Mon Sep 17 00:00:00 2001 From: Piotr Jastrzebski Date: Mon, 20 May 2019 16:17:49 +0200 Subject: [PATCH] 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 --- sstables/mp_row_consumer.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sstables/mp_row_consumer.cc b/sstables/mp_row_consumer.cc index 1e71f4ed60..75ad4e5920 100644 --- a/sstables/mp_row_consumer.cc +++ b/sstables/mp_row_consumer.cc @@ -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();