sstables: fail sstable write if unable to generate sharding metadata

SSTable can generate an empty sharding metadata after a bug like
the one introduced here 115ff10, that results in tokens being
generated using base table for the view table. That leads to
sstable being deleted in subsequent boot because all shards will
agree on its deletion given that it will not belong to anybody,
and also compaction to crash because this relies on resulting
sstable belonging to one shard at least.

I wouldn't like to spend days debugging it again because sstable
write silently generated empty sharding metadata, so let's make
write fail when it happens (see issue #2932 for details).

Refs #2932.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
Message-Id: <20171223120140.3642-1-raphaelsc@scylladb.com>
This commit is contained in:
Raphael S. Carvalho
2017-12-23 10:01:39 -02:00
committed by Avi Kivity
parent 2618209c2d
commit fa5a26f12d

View File

@@ -2250,6 +2250,11 @@ sstable::write_scylla_metadata(const io_priority_class& pc, shard_id shard, ssta
auto&& first_key = get_first_decorated_key();
auto&& last_key = get_last_decorated_key();
auto sm = create_sharding_metadata(_schema, first_key, last_key, shard);
// sstable write may fail to generate empty metadata if mutation source has only data from other shard.
// see https://github.com/scylladb/scylla/issues/2932 for details on how it can happen.
if (sm.token_ranges.elements.empty()) {
throw std::runtime_error(sprint("Failed to generate sharding metadata for %s", get_filename()));
}
_components->scylla_metadata.emplace();
_components->scylla_metadata->data.set<scylla_metadata_type::Sharding>(std::move(sm));
_components->scylla_metadata->data.set<scylla_metadata_type::Features>(std::move(features));