Files
scylladb/mutation_query.hh
Tomasz Grabiec 9bea6aa0a3 db: Introduce mutation query interface
Mutation query differs from data query in that returns information
needed to reconcile data slice with that retruned by other data
sources.

There is a generic mutation_query() algorithm introduced, which can
work with any mutation_source.

database::query_mutations() is a shard-local interface for mutation
queries.

The reconcilable_result is introduced as a medium for mutation query
results. It piggy backs on frozen_mutation as a medium for
reconcilable data.
2015-07-12 12:51:38 +02:00

97 lines
2.9 KiB
C++

/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
#pragma once
#include "query-request.hh"
#include "query-result.hh"
#include "mutation_reader.hh"
#include "frozen_mutation.hh"
#include "db/serializer.hh"
class reconcilable_result;
class frozen_reconcilable_result;
// Can be read by other cores after publishing.
struct partition {
uint32_t _row_count;
frozen_mutation _m; // FIXME: We don't need cf UUID, which frozen_mutation includes.
partition(uint32_t row_count, frozen_mutation m)
: _row_count(row_count)
, _m(std::move(m))
{ }
uint32_t row_count() const {
return _row_count;
}
const frozen_mutation& mut() const {
return _m;
}
bool operator==(const partition& other) const {
return _row_count == other._row_count && _m.representation() == other._m.representation();
}
bool operator!=(const partition& other) const {
return !(*this == other);
}
};
// The partitions held by this object are ordered according to dht::decorated_key ordering and non-overlapping.
// Each mutation must have different key.
//
// Can be read by other cores after publishing.
class reconcilable_result {
uint32_t _row_count;
std::vector<partition> _partitions;
public:
~reconcilable_result();
reconcilable_result();
reconcilable_result(reconcilable_result&&) = default;
reconcilable_result& operator=(reconcilable_result&&) = default;
reconcilable_result(uint32_t row_count, std::vector<partition> partitions);
const std::vector<partition>& partitions() const;
std::vector<partition>& partitions();
uint32_t row_count() const {
return _row_count;
}
bool operator==(const reconcilable_result& other) const;
bool operator!=(const reconcilable_result& other) const;
};
query::result to_data_query_result(const reconcilable_result&, schema_ptr, const query::partition_slice&);
namespace db {
template<> serializer<reconcilable_result>::serializer(const reconcilable_result&);
template<> void serializer<reconcilable_result>::write(output&, const reconcilable_result&);
template<> void serializer<reconcilable_result>::read(reconcilable_result&, input&);
extern template class serializer<reconcilable_result>;
}
// Performs a query on given data source returning data in reconcilable form.
//
// Reads at most row_limit rows. If less rows are returned, the data source
// didn't have more live data satisfying the query.
//
// Any cells which have expired according to query_time are returned as
// deleted cells and do not count towards live data. The mutations are
// compact, meaning that any cell which is covered by higher-level tombstone
// is absent in the results.
//
// 'source' doesn't have to survive deferring.
future<reconcilable_result> mutation_query(
const mutation_source& source,
const query::partition_range& range,
const query::partition_slice& slice,
uint32_t row_limit,
gc_clock::time_point query_time);