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.
This commit is contained in:
Tomasz Grabiec
2015-06-24 14:07:12 +02:00
committed by Avi Kivity
parent a723942a54
commit dc6bfb63da
2 changed files with 39 additions and 0 deletions

View File

@@ -21,9 +21,13 @@
* Copyright 2015 Cloudius Systems
*/
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/range/adaptor/transformed.hpp>
#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<lw_shared_ptr<query::result_set>>
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<column_id> regular_cols;
boost::range::push_back(regular_cols, schema->regular_columns() | boost::adaptors::transformed(std::mem_fn(&column_definition::id)));
std::vector<column_id> 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<query::read_command>(schema->id(), slice, std::numeric_limits<uint32_t>::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

View File

@@ -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<schema_ptr> 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<lw_shared_ptr<query::result_set>> query(service::storage_proxy& proxy, const sstring& cf_name);
// Endpoint Data Center and Rack names
struct endpoint_dc_rack {
sstring dc;