db: Make the whole database printable

For debugging purposes.
This commit is contained in:
Tomasz Grabiec
2015-04-02 13:36:52 +02:00
parent 0be6cec13f
commit b34cdd76ae
4 changed files with 49 additions and 8 deletions

View File

@@ -9,6 +9,7 @@
#include "tombstone.hh"
#include "gc_clock.hh"
#include <cstdint>
#include <iostream>
template<typename T>
static inline
@@ -223,6 +224,7 @@ public:
collection_mutation::view as_collection_mutation() const {
return collection_mutation::view{_data};
}
friend std::ostream& operator<<(std::ostream&, const atomic_cell_or_collection&);
};
class column_definition;

View File

@@ -720,14 +720,6 @@ bool column_definition::is_compact_value() const {
return false;
}
std::ostream& operator<<(std::ostream& os, const mutation& m) {
return fprint(os, "{mutation: schema %p key %s data %s}", m.schema.get(), static_cast<bytes_view>(m.key), m.p);
}
std::ostream& operator<<(std::ostream& os, const mutation_partition& mp) {
return fprint(os, "{mutation_partition: ...}");
}
boost::iterator_range<mutation_partition::rows_type::const_iterator>
mutation_partition::range(const schema& schema, const query::range<clustering_key_prefix>& r) const {
if (r.is_full()) {
@@ -970,6 +962,51 @@ database::query(const query::read_command& cmd) {
}
}
std::ostream& operator<<(std::ostream& out, const atomic_cell_or_collection& c) {
return out << to_hex(c._data);
}
void print_partition(std::ostream& out, const schema& s, const mutation_partition& mp) {
out << "{rows={\n";
for (auto&& e : mp.range(s, query::range<clustering_key_prefix>())) {
out << e.key() << " => ";
for (auto&& cell_e : e.row().cells) {
out << cell_e.first << ":";
out << cell_e.second << " ";
}
out << "\n";
}
out << "}}";
}
std::ostream& operator<<(std::ostream& os, const mutation& m) {
fprint(os, "{mutation: schema %p key %s data ", m.schema.get(), static_cast<bytes_view>(m.key));
print_partition(os, *m.schema, m.p);
os << "}";
return os;
}
std::ostream& operator<<(std::ostream& out, const column_family& cf) {
out << "{\n";
for (auto&& e : cf.partitions) {
out << e.first << " => ";
print_partition(out, *cf._schema, e.second);
out << "\n";
}
out << "}";
return out;
}
std::ostream& operator<<(std::ostream& out, const database& db) {
out << "{\n";
for (auto&& e : db._column_families) {
auto&& cf = e.second;
out << "(" << e.first.to_sstring() << ", " << cf._schema->cf_name << ", " << cf._schema->ks_name << "): " << cf << "\n";
}
out << "}";
return out;
}
namespace db {
std::ostream& operator<<(std::ostream& os, db::consistency_level cl) {

View File

@@ -326,6 +326,7 @@ public:
}
unsigned shard_of(const dht::token& t);
future<lw_shared_ptr<query::result>> query(const query::read_command& cmd);
friend std::ostream& operator<<(std::ostream& out, const database& db);
};
// FIXME: stub

View File

@@ -40,6 +40,7 @@ public:
, _end()
, _singular(true)
{ }
range() : range({}, {}) {}
public:
static range make(bound start, bound end) {
return range({std::move(start)}, {std::move(end)});