/* * 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 . */ #pragma once #include #include "frozen_mutation.hh" #include "schema.hh" namespace stdx = std::experimental; class commitlog_entry { stdx::optional _mapping; stdx::optional _mutation_storage; const 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; const stdx::optional& mapping() const { return _mapping; } const frozen_mutation& mutation() const { return _mutation; } }; class commitlog_entry_writer { schema_ptr _schema; const frozen_mutation& _mutation; bool _with_schema = true; size_t _size; private: 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) { compute_size(); } void set_with_schema(bool value) { _with_schema = value; compute_size(); } bool with_schema() { return _with_schema; } schema_ptr schema() const { return _schema; } size_t size() const { return _size; } void write(data_output& out) const; }; class commitlog_entry_reader { commitlog_entry _ce; public: commitlog_entry_reader(const temporary_buffer& buffer); const stdx::optional& get_column_mapping() const { return _ce.mapping(); } const frozen_mutation& mutation() const { return _ce.mutation(); } };