From dc6bfb63dae05beea68c833562deef82fb78d6ab Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 24 Jun 2015 14:07:12 +0200 Subject: [PATCH] system_keyspace: Introduce query() Simple method to get all data from a system table. Note: Perhaps we should move storage_proxy::query_local() here as well. --- db/system_keyspace.cc | 27 +++++++++++++++++++++++++++ db/system_keyspace.hh | 12 ++++++++++++ 2 files changed, 39 insertions(+) diff --git a/db/system_keyspace.cc b/db/system_keyspace.cc index 1c2a8dc305..d37ffa26ee 100644 --- a/db/system_keyspace.cc +++ b/db/system_keyspace.cc @@ -21,9 +21,13 @@ * Copyright 2015 Cloudius Systems */ +#include +#include + #include "system_keyspace.hh" #include "types.hh" #include "service/storage_service.hh" +#include "service/storage_proxy.hh" namespace db { namespace system_keyspace { @@ -1058,5 +1062,28 @@ load_dc_rack_info() #endif return result; } + +future> +query(service::storage_proxy& proxy, const sstring& cf_name) { + database& db = proxy.get_db().local(); + schema_ptr schema = db.find_schema(db::system_keyspace::NAME, cf_name); + std::vector regular_cols; + boost::range::push_back(regular_cols, schema->regular_columns() | boost::adaptors::transformed(std::mem_fn(&column_definition::id))); + std::vector static_cols; + boost::range::push_back(static_cols, schema->static_columns() | boost::adaptors::transformed(std::mem_fn(&column_definition::id))); + auto opts = query::partition_slice::option_set::of< + query::partition_slice::option::send_partition_key, + query::partition_slice::option::send_clustering_key>(); + query::partition_slice slice{{query::clustering_range::make_open_ended_both_sides()}, static_cols, regular_cols, opts}; + auto cmd = make_lw_shared(schema->id(), slice, std::numeric_limits::max()); + return proxy.query(cmd, {query::full_partition_range}, db::consistency_level::ONE).then([schema, cmd] (auto&& result) { + query::result_set_builder builder{schema}; + bytes_ostream w(result->buf()); + query::result_view view(w.linearize()); + view.consume(cmd->slice, builder); + return builder.build(); + }); +} + } // namespace system_keyspace } // namespace db diff --git a/db/system_keyspace.hh b/db/system_keyspace.hh index 8c75156ccd..f8ce270fa4 100644 --- a/db/system_keyspace.hh +++ b/db/system_keyspace.hh @@ -29,6 +29,13 @@ #include "legacy_schema_tables.hh" #include "utils/UUID.hh" #include "gms/inet_address.hh" +#include "query-result-set.hh" + +namespace service { + +class storage_proxy; + +} namespace db { namespace system_keyspace { @@ -54,6 +61,11 @@ extern schema_ptr built_indexes(); // TODO (from Cassandra): make private std::vector all_tables(); void make(database& db, bool durable); +// Returns all data from given system table. +// Intended to be used by code which is not performance critical. +future> query(service::storage_proxy& proxy, const sstring& cf_name); + + // Endpoint Data Center and Rack names struct endpoint_dc_rack { sstring dc;