Breaks the file into individually tagged + crc:ed pages. Each page (sized as disk write alignment) gets a trailing 12-byte metadata, including CRC of the first page-12 bytes, and the ID of the segment being written. When reading, each page read is CRC:ed and checked to be part of the expected segment by comparing ID:s. If crc is broken, we have broken data. If crc is ok, but ID does not match, we have a prematurely terminated segment (truncated), which, depending on whether we use batch mode or not, implied data loss.
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
/*
|
|
* Copyright 2016-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include "counters.hh"
|
|
#include "commitlog_entry.hh"
|
|
#include "idl/commitlog.dist.hh"
|
|
#include "idl/commitlog.dist.impl.hh"
|
|
|
|
#include <seastar/core/simple-stream.hh>
|
|
|
|
template<typename Output>
|
|
void commitlog_entry_writer::serialize(Output& out) const {
|
|
[this, wr = ser::writer_of_commitlog_entry<Output>(out)] () mutable {
|
|
if (_with_schema) {
|
|
return std::move(wr).write_mapping(_schema->get_column_mapping());
|
|
} else {
|
|
return std::move(wr).skip_mapping();
|
|
}
|
|
}().write_mutation(_mutation).end_commitlog_entry();
|
|
}
|
|
|
|
void commitlog_entry_writer::compute_size() {
|
|
seastar::measuring_output_stream ms;
|
|
serialize(ms);
|
|
_size = ms.size();
|
|
}
|
|
|
|
void commitlog_entry_writer::write(ostream& out) const {
|
|
serialize(out);
|
|
}
|
|
|
|
commitlog_entry_reader::commitlog_entry_reader(const fragmented_temporary_buffer& buffer)
|
|
: _ce([&] {
|
|
auto in = seastar::fragmented_memory_input_stream(fragmented_temporary_buffer::view(buffer).begin(), buffer.size_bytes());
|
|
return ser::deserialize(in, boost::type<commitlog_entry>());
|
|
}())
|
|
{
|
|
}
|