db: Make the whole database printable
For debugging purposes.
This commit is contained in:
@@ -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;
|
||||
|
||||
53
database.cc
53
database.cc
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user