Files
scylladb/mutation.hh
Nadav Har'El 78a8ac8470 Make mutation_reader usable outside database.cc
The "mutation_reader" defined in database.cc is a convenient mechanism
for iterating over mutations. It can be useful for more than just
database.cc (I want to use it in the compaction code), so this patch moves
the type's definition to mutation.hh, and the make_memtable_reader()
function to memtable::make_reader() (in memtable.hh).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-06-16 14:03:34 +02:00

58 lines
2.8 KiB
C++

/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#pragma once
#include <iostream>
#include "mutation_partition.hh"
#include "keys.hh"
#include "schema.hh"
#include "dht/i_partitioner.hh"
class mutation final {
private:
schema_ptr _schema;
dht::decorated_key _dk;
mutation_partition _p;
public:
mutation(dht::decorated_key key, schema_ptr schema);
mutation(partition_key key, schema_ptr schema);
mutation(schema_ptr schema, dht::decorated_key key, mutation_partition mp);
mutation(mutation&&) = default;
mutation(const mutation&) = default;
mutation& operator=(mutation&& x) = default;
void set_static_cell(const column_definition& def, atomic_cell_or_collection value);
void set_static_cell(const bytes& name, const boost::any& value, api::timestamp_type timestamp, ttl_opt ttl = {});
void set_clustered_cell(const exploded_clustering_prefix& prefix, const column_definition& def, atomic_cell_or_collection value);
void set_clustered_cell(const clustering_key& key, const bytes& name, const boost::any& value, api::timestamp_type timestamp, ttl_opt ttl = {});
void set_clustered_cell(const clustering_key& key, const column_definition& def, atomic_cell_or_collection value);
void set_cell(const exploded_clustering_prefix& prefix, const bytes& name, const boost::any& value, api::timestamp_type timestamp, ttl_opt ttl = {});
void set_cell(const exploded_clustering_prefix& prefix, const column_definition& def, atomic_cell_or_collection value);
std::experimental::optional<atomic_cell_or_collection> get_cell(const clustering_key& rkey, const column_definition& def) const;
const partition_key& key() const { return _dk._key; };
const dht::decorated_key& decorated_key() const { return _dk; };
const dht::token token() const { return _dk._token; }
const schema_ptr& schema() const { return _schema; }
const mutation_partition& partition() const { return _p; }
mutation_partition& partition() { return _p; }
const utils::UUID& column_family_id() const { return _schema->id(); }
bool operator==(const mutation&) const;
bool operator!=(const mutation&) const;
private:
friend std::ostream& operator<<(std::ostream& os, const mutation& m);
};
using mutation_opt = std::experimental::optional<mutation>;
// A mutation_reader is an object which allows iterating on mutations: invoke
// the function to get a future for the next mutation, with an unset optional
// marking the end of iteration. After calling mutation_reader's operator(),
// caller must keep the object alive until the returned future is fulfilled.
// TODO: When iterating over mutations, we don't need a schema_ptr for every
// single one as it is normally the same for all of them. So "mutation" might
// not be the optimal object to use here.
using mutation_reader = std::function<future<mutation_opt> ()>;