sstables: Do not write corrupted sstables when column names are too large

This may result in errors during reading like the following one:

  runtime error: Unexpected marker. Found k, expected \x01\n)'

The error above happened when executing limits.py:max_key_length_test dtest.

After change the exception will happen during writing and will be clearer.

Refs #807.

This patch doesn't deal with the problem of ensuring that we will
never hit those errors, which is very desirable. We shouldn't ack a
write if we can't persist it to sstables.

Message-Id: <1456130045-2364-1-git-send-email-tgrabiec@scylladb.com>
This commit is contained in:
Tomasz Grabiec
2016-02-22 09:34:05 +01:00
committed by Avi Kivity
parent f2c6f16a50
commit fb3344eba1

View File

@@ -985,15 +985,23 @@ void sstable::write_column_name(file_writer& out, const composite& clustering_ke
if (c.size() == 1) {
ck_bview.remove_suffix(1);
}
uint16_t sz = ck_bview.size() + c.size();
write(out, sz, ck_bview, c);
size_t sz = ck_bview.size() + c.size();
if (sz > std::numeric_limits<uint16_t>::max()) {
throw std::runtime_error(sprint("Column name too large (%d > %d)", sz, std::numeric_limits<uint16_t>::max()));
}
uint16_t sz16 = sz;
write(out, sz16, ck_bview, c);
}
void sstable::write_column_name(file_writer& out, bytes_view column_names) {
column_name_helper::min_max_components(_c_stats.min_column_names, _c_stats.max_column_names, { column_names });
uint16_t sz = column_names.size();
write(out, sz, column_names);
size_t sz = column_names.size();
if (sz > std::numeric_limits<uint16_t>::max()) {
throw std::runtime_error(sprint("Column name too large (%d > %d)", sz, std::numeric_limits<uint16_t>::max()));
}
uint16_t sz16 = sz;
write(out, sz16, column_names);
}