From 9530a372ccaf21345bbf47a4be6dfd22275d07b6 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 6 Feb 2015 12:56:56 +0100 Subject: [PATCH] cql3: Take reference to storage_proxy and call instance methods --- cql3/cql_statement.hh | 5 +++-- cql3/statements/modification_statement.cc | 14 +++++++------- cql3/statements/modification_statement.hh | 8 ++++---- cql3/statements/schema_altering_statement.hh | 4 ++-- cql3/statements/truncate_statement.hh | 4 ++-- cql3/statements/use_statement.hh | 4 ++-- service/storage_proxy.hh | 9 +++++---- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/cql3/cql_statement.hh b/cql3/cql_statement.hh index 8ddde8477e..1c6de1a138 100644 --- a/cql3/cql_statement.hh +++ b/cql3/cql_statement.hh @@ -28,6 +28,7 @@ #include "transport/messages/result_message.hh" #include "service/client_state.hh" #include "service/query_state.hh" +#include "service/storage_proxy.hh" #include "cql3/query_options.hh" #include "database.hh" @@ -62,7 +63,7 @@ public: * @param options options for this query (consistency, variables, pageSize, ...) */ virtual future> - execute(service::query_state& state, const query_options& options) = 0; + execute(service::storage_proxy& proxy, service::query_state& state, const query_options& options) = 0; /** * Variant of execute used for internal query against the system tables, and thus only query the local node = 0. @@ -70,7 +71,7 @@ public: * @param state the current query state */ virtual future> - execute_internal(service::query_state& state, const query_options& options) = 0; + execute_internal(database& db, service::query_state& state, const query_options& options) = 0; virtual bool uses_function(const sstring& ks_name, const sstring& function_name) const = 0; }; diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index 608c96ce81..da880e7ae7 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -278,23 +278,23 @@ modification_statement::build_partition_keys(const query_options& options) { } future> -modification_statement::execute(service::query_state& qs, const query_options& options) { +modification_statement::execute(service::storage_proxy& proxy, service::query_state& qs, const query_options& options) { if (has_conditions() && options.get_protocol_version() == 1) { throw new exceptions::invalid_request_exception("Conditional updates are not supported by the protocol version in use. You need to upgrade to a driver using the native protocol v2."); } if (has_conditions()) { - return execute_with_condition(qs, options); + return execute_with_condition(proxy, qs, options); } - return execute_without_condition(qs, options).then([] { + return execute_without_condition(proxy, qs, options).then([] { return make_ready_future>( std::experimental::optional{}); }); } future<> -modification_statement::execute_without_condition(service::query_state& qs, const query_options& options) { +modification_statement::execute_without_condition(service::storage_proxy& proxy, service::query_state& qs, const query_options& options) { auto cl = options.get_consistency(); if (is_counter()) { db::validate_counter_for_write(s, cl); @@ -302,16 +302,16 @@ modification_statement::execute_without_condition(service::query_state& qs, cons db::validate_for_write(s->ks_name, cl); } - return get_mutations(options, false, options.get_timestamp(qs)).then([cl] (auto mutations) { + return get_mutations(options, false, options.get_timestamp(qs)).then([cl, &proxy] (auto mutations) { if (mutations.empty()) { return now(); } - return service::storage_proxy::mutate_with_triggers(std::move(mutations), cl, false); + return proxy.mutate_with_triggers(std::move(mutations), cl, false); }); } future> -modification_statement::execute_with_condition(service::query_state& qs, const query_options& options) { +modification_statement::execute_with_condition(service::storage_proxy& proxy, service::query_state& qs, const query_options& options) { unimplemented::lwt(); #if 0 List keys = buildPartitionKeyNames(options); diff --git a/cql3/statements/modification_statement.hh b/cql3/statements/modification_statement.hh index e9f65ace5c..dc01ea8be9 100644 --- a/cql3/statements/modification_statement.hh +++ b/cql3/statements/modification_statement.hh @@ -296,19 +296,19 @@ public: } virtual future> - execute(service::query_state& qs, const query_options& options) override; + execute(service::storage_proxy& proxy, service::query_state& qs, const query_options& options) override; virtual future> - execute_internal(service::query_state& qs, const query_options& options) override { + execute_internal(database& db, service::query_state& qs, const query_options& options) override { throw std::runtime_error("not implemented"); } private: future<> - execute_without_condition(service::query_state& qs, const query_options& options); + execute_without_condition(service::storage_proxy& proxy, service::query_state& qs, const query_options& options); future> - execute_with_condition(service::query_state& qs, const query_options& options); + execute_with_condition(service::storage_proxy& proxy, service::query_state& qs, const query_options& options); #if 0 public void addConditions(Composite clusteringPrefix, CQL3CasRequest request, QueryOptions options) throws InvalidRequestException diff --git a/cql3/statements/schema_altering_statement.hh b/cql3/statements/schema_altering_statement.hh index b3a2ea5c3d..6e5bcbdb5a 100644 --- a/cql3/statements/schema_altering_statement.hh +++ b/cql3/statements/schema_altering_statement.hh @@ -82,7 +82,7 @@ protected: #endif virtual future> - execute(service::query_state& state, const query_options& options) override { + execute(service::storage_proxy& proxy, service::query_state& state, const query_options& options) override { throw std::runtime_error("not implemented"); #if 0 // If an IF [NOT] EXISTS clause was used, this may not result in an actual schema change. To avoid doing @@ -97,7 +97,7 @@ protected: } virtual future> - execute_internal(service::query_state& state, const query_options& options) override { + execute_internal(database& db, service::query_state& state, const query_options& options) override { throw std::runtime_error("unsupported operation"); #if 0 try diff --git a/cql3/statements/truncate_statement.hh b/cql3/statements/truncate_statement.hh index b0130929d9..f376e281b1 100644 --- a/cql3/statements/truncate_statement.hh +++ b/cql3/statements/truncate_statement.hh @@ -63,7 +63,7 @@ public: } virtual future> - execute(service::query_state& state, const query_options& options) override { + execute(service::storage_proxy& proxy, service::query_state& state, const query_options& options) override { throw std::runtime_error("not implemented"); #if 0 try @@ -87,7 +87,7 @@ public: } virtual future> - execute_internal(service::query_state& state, const query_options& options) override { + execute_internal(database& db, service::query_state& state, const query_options& options) override { throw std::runtime_error("unsupported operation"); } }; diff --git a/cql3/statements/use_statement.hh b/cql3/statements/use_statement.hh index ae44205ccd..c641fabcdb 100644 --- a/cql3/statements/use_statement.hh +++ b/cql3/statements/use_statement.hh @@ -61,7 +61,7 @@ public: } virtual future> - execute(service::query_state& state, const query_options& options) override { + execute(service::storage_proxy& proxy, service::query_state& state, const query_options& options) override { throw std::runtime_error("not implemented"); #if 0 state.getClientState().setKeyspace(keyspace); @@ -70,7 +70,7 @@ public: } virtual future> - execute_internal(service::query_state& state, const query_options& options) override { + execute_internal(database& db, service::query_state& state, const query_options& options) override { // Internal queries are exclusively on the system keyspace and 'use' is thus useless throw std::runtime_error("unsupported operation"); } diff --git a/service/storage_proxy.hh b/service/storage_proxy.hh index 5b620c5b2d..e334efa83a 100644 --- a/service/storage_proxy.hh +++ b/service/storage_proxy.hh @@ -25,6 +25,7 @@ #pragma once #include "database.hh" +#include "db/consistency_level.hh" namespace service { @@ -39,10 +40,10 @@ public: * @param mutations the mutations to be applied across the replicas * @param consistency_level the consistency level for the operation */ - static future<> mutate(std::vector mutations, db::consistency_level cl); + future<> mutate(std::vector mutations, db::consistency_level cl); - static future<> mutate_with_triggers(std::vector mutations, - db::consistency_level cl, bool should_mutate_atomically); + future<> mutate_with_triggers(std::vector mutations, db::consistency_level cl, + bool should_mutate_atomically); /** * See mutate. Adds additional steps before and after writing a batch. @@ -53,7 +54,7 @@ public: * @param mutations the Mutations to be applied across the replicas * @param consistency_level the consistency level for the operation */ - static future<> mutate_atomically(std::vector mutations, db::consistency_level cl); + future<> mutate_atomically(std::vector mutations, db::consistency_level cl); }; }