table: Fix schema mismatch between memtable reader and sstable writer

The schema used to create the sstable writer has to be the same as the
schema used by the reader, as the former is used to intrpret mutation
fragments produced by the reader.

Commit 9124a70 intorduced a deferring point between reader creation
and writer creation which can result in schema mismatch if there was a
concurrent alter.

This could lead to the sstable write to crash, or generate a corrupted
sstable.

Fixes #7994

Message-Id: <20210222153149.289308-1-tgrabiec@scylladb.com>
This commit is contained in:
Tomasz Grabiec
2021-02-22 16:31:49 +01:00
committed by Avi Kivity
parent 81d773e5d8
commit fb1d3fe2cf

View File

@@ -1698,7 +1698,8 @@ write_memtable_to_sstable(flat_mutation_reader reader,
cfg.replay_position = mt.replay_position();
cfg.monitor = &monitor;
cfg.origin = "memtable";
return sst->write_components(std::move(reader), mt.partition_count(), mt.schema(), cfg, mt.get_encoding_stats(), pc);
schema_ptr s = reader.schema();
return sst->write_components(std::move(reader), mt.partition_count(), s, cfg, mt.get_encoding_stats(), pc);
}
future<>