diff --git a/db/commitlog/commitlog_entry.cc b/db/commitlog/commitlog_entry.cc index e8e3898bcb..a7423709f2 100644 --- a/db/commitlog/commitlog_entry.cc +++ b/db/commitlog/commitlog_entry.cc @@ -34,48 +34,26 @@ #include "idl/mutation.dist.impl.hh" #include "idl/commitlog.dist.impl.hh" -commitlog_entry::commitlog_entry(stdx::optional mapping, frozen_mutation&& mutation) - : _mapping(std::move(mapping)) - , _mutation_storage(std::move(mutation)) - , _mutation(*_mutation_storage) -{ } - -commitlog_entry::commitlog_entry(stdx::optional mapping, const frozen_mutation& mutation) - : _mapping(std::move(mapping)) - , _mutation(mutation) -{ } - -commitlog_entry::commitlog_entry(commitlog_entry&& ce) - : _mapping(std::move(ce._mapping)) - , _mutation_storage(std::move(ce._mutation_storage)) - , _mutation(_mutation_storage ? *_mutation_storage : ce._mutation) -{ -} - -commitlog_entry& commitlog_entry::operator=(commitlog_entry&& ce) -{ - if (this != &ce) { - this->~commitlog_entry(); - new (this) commitlog_entry(std::move(ce)); - } - return *this; -} - -commitlog_entry commitlog_entry_writer::get_entry() const { - if (_with_schema) { - return commitlog_entry(_schema->get_column_mapping(), _mutation); - } else { - return commitlog_entry({}, _mutation); - } +template +void commitlog_entry_writer::serialize(Output& out) const { + [this, wr = ser::writer_of_commitlog_entry(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() { - _size = ser::get_sizeof(get_entry()); + seastar::measuring_output_stream ms; + serialize(ms); + _size = ms.size(); } void commitlog_entry_writer::write(data_output& out) const { seastar::simple_output_stream str(out.reserve(size()), size()); - ser::serialize(str, get_entry()); + serialize(str); } commitlog_entry_reader::commitlog_entry_reader(const temporary_buffer& buffer) diff --git a/db/commitlog/commitlog_entry.hh b/db/commitlog/commitlog_entry.hh index 25149c951b..ddc9754e07 100644 --- a/db/commitlog/commitlog_entry.hh +++ b/db/commitlog/commitlog_entry.hh @@ -31,15 +31,10 @@ namespace stdx = std::experimental; class commitlog_entry { stdx::optional _mapping; - stdx::optional _mutation_storage; - const frozen_mutation& _mutation; + frozen_mutation _mutation; public: - commitlog_entry(stdx::optional mapping, frozen_mutation&& mutation); - commitlog_entry(stdx::optional mapping, const frozen_mutation& mutation); - commitlog_entry(commitlog_entry&&); - commitlog_entry(const commitlog_entry&) = delete; - commitlog_entry& operator=(commitlog_entry&&); - commitlog_entry& operator=(const commitlog_entry&) = delete; + commitlog_entry(stdx::optional mapping, frozen_mutation&& mutation) + : _mapping(std::move(mapping)), _mutation(std::move(mutation)) { } const stdx::optional& mapping() const { return _mapping; } const frozen_mutation& mutation() const { return _mutation; } }; @@ -50,8 +45,9 @@ class commitlog_entry_writer { bool _with_schema = true; size_t _size; private: + template + void serialize(Output&) const; void compute_size(); - commitlog_entry get_entry() const; public: commitlog_entry_writer(schema_ptr s, const frozen_mutation& fm) : _schema(std::move(s)), _mutation(fm) @@ -88,4 +84,4 @@ public: const stdx::optional& get_column_mapping() const { return _ce.mapping(); } const frozen_mutation& mutation() const { return _ce.mutation(); } -}; \ No newline at end of file +}; diff --git a/idl/commitlog.idl.hh b/idl/commitlog.idl.hh index a4d88076de..a2dc60c4e8 100644 --- a/idl/commitlog.idl.hh +++ b/idl/commitlog.idl.hh @@ -19,7 +19,7 @@ * along with Scylla. If not, see . */ -class commitlog_entry { +class commitlog_entry [[writable]] { std::experimental::optional mapping(); frozen_mutation mutation(); -}; \ No newline at end of file +};