Files
scylladb/db/commitlog/commitlog_entry.cc
Paweł Dziepak 4469f76e7c commitlog: switch to fragmented buffers
So far commitlog was using contiguous buffers for storing the data that
is about to be written to disk. It was able to coalesce small writes so
that multiple small mutations would use the same buffer, but if a
muation was large the commitlog would attempt to allocate a single,
appropriately large buffer. This excessively stresses the memory
allocator and may cause memory fragmentation to become an issue. The
solution is to use fixed-size buffers of 128 kB, which is the standard
buffer size in Scylla and keep large values fragmented.
2018-09-18 17:22:59 +01:00

65 lines
2.1 KiB
C++

/*
* Copyright 2016 ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#include "counters.hh"
#include "commitlog_entry.hh"
#include "idl/uuid.dist.hh"
#include "idl/keys.dist.hh"
#include "idl/frozen_mutation.dist.hh"
#include "idl/mutation.dist.hh"
#include "idl/commitlog.dist.hh"
#include "serializer_impl.hh"
#include "serialization_visitors.hh"
#include "idl/uuid.dist.impl.hh"
#include "idl/keys.dist.impl.hh"
#include "idl/frozen_mutation.dist.impl.hh"
#include "idl/mutation.dist.impl.hh"
#include "idl/commitlog.dist.impl.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(typename seastar::memory_output_stream<std::vector<temporary_buffer<char>>::iterator>& out) const {
serialize(out);
}
commitlog_entry_reader::commitlog_entry_reader(const temporary_buffer<char>& buffer)
: _ce([&] {
seastar::simple_input_stream in(buffer.get(), buffer.size());
return ser::deserialize(in, boost::type<commitlog_entry>());
}())
{
}