sstables: parse statistics: improve error handling

Properly return malformed_sstable_exception if the
statistics file fails to parse.

Test: unit(dev)
Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Message-Id: <20210524113808.973951-1-bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2021-05-24 14:38:08 +03:00
committed by Avi Kivity
parent 5da0ad2ebc
commit 56d3cb514a

View File

@@ -632,18 +632,25 @@ future<> parse(const schema& schema, sstable_version_types v, random_access_read
return parse<stats_metadata>(schema, v, in, s.contents[type]);
case metadata_type::Serialization:
if (v < sstable_version_types::mc) {
throw std::runtime_error(
throw malformed_sstable_exception(
"Statistics is malformed: SSTable is in 2.x format but contains serialization header.");
} else {
return parse<serialization_header>(schema, v, in, s.contents[type]);
}
return make_ready_future<>();
default:
sstlog.warn("Invalid metadata type at Statistics file: {} ", int(type));
return make_ready_future<>();
throw malformed_sstable_exception(fmt::format("Invalid metadata type at Statistics file: {} ", int(type)));
}
});
});
}).handle_exception([] (std::exception_ptr ex) {
try {
std::rethrow_exception(ex);
} catch (const malformed_sstable_exception&) {
throw;
} catch (...) {
throw malformed_sstable_exception(fmt::format("Statistics file is malformed: {}", ex));
}
});
}