table_helper: Use local qp as setup_table argument
The goal is to make table_helper API require the query_processor reference and use it where needed. The .setup_table() is private method, and still grabs the query processor reference itself. Since its futures do noth reshard, it's safe to carry the query processor reference through. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -26,8 +26,7 @@
|
||||
#include "cql3/statements/modification_statement.hh"
|
||||
#include "database.hh"
|
||||
|
||||
future<> table_helper::setup_table() const {
|
||||
auto& qp = cql3::get_local_query_processor();
|
||||
future<> table_helper::setup_table(cql3::query_processor& qp) const {
|
||||
auto& db = qp.db();
|
||||
|
||||
if (db.has_schema(_keyspace, _name)) {
|
||||
@@ -67,13 +66,14 @@ future<> table_helper::cache_table_info(service::query_state& qs) {
|
||||
return now();
|
||||
}
|
||||
|
||||
return cql3::get_local_query_processor().prepare(_insert_cql, qs.get_client_state(), false)
|
||||
cql3::query_processor& qp = cql3::get_local_query_processor();
|
||||
return qp.prepare(_insert_cql, qs.get_client_state(), false)
|
||||
.then([this] (shared_ptr<cql_transport::messages::result_message::prepared> msg_ptr) noexcept {
|
||||
_prepared_stmt = std::move(msg_ptr->get_prepared());
|
||||
shared_ptr<cql3::cql_statement> cql_stmt = _prepared_stmt->statement;
|
||||
_insert_stmt = dynamic_pointer_cast<cql3::statements::modification_statement>(cql_stmt);
|
||||
_is_fallback_stmt = false;
|
||||
}).handle_exception_type([this, &qs] (exceptions::invalid_request_exception& eptr) {
|
||||
}).handle_exception_type([this, &qs, &qp] (exceptions::invalid_request_exception& eptr) {
|
||||
// the non-fallback statement can't be prepared
|
||||
if (!_insert_cql_fallback) {
|
||||
return make_exception_future(eptr);
|
||||
@@ -82,17 +82,17 @@ future<> table_helper::cache_table_info(service::query_state& qs) {
|
||||
// we have already prepared the fallback statement
|
||||
return now();
|
||||
}
|
||||
return cql3::get_local_query_processor().prepare(_insert_cql_fallback.value(), qs.get_client_state(), false)
|
||||
return qp.prepare(_insert_cql_fallback.value(), qs.get_client_state(), false)
|
||||
.then([this] (shared_ptr<cql_transport::messages::result_message::prepared> msg_ptr) noexcept {
|
||||
_prepared_stmt = std::move(msg_ptr->get_prepared());
|
||||
shared_ptr<cql3::cql_statement> cql_stmt = _prepared_stmt->statement;
|
||||
_insert_stmt = dynamic_pointer_cast<cql3::statements::modification_statement>(cql_stmt);
|
||||
_is_fallback_stmt = true;
|
||||
});
|
||||
}).handle_exception([this] (auto eptr) {
|
||||
}).handle_exception([this, &qp] (auto eptr) {
|
||||
// One of the possible causes for an error here could be the table that doesn't exist.
|
||||
//FIXME: discarded future.
|
||||
(void)this->setup_table().discard_result();
|
||||
(void)this->setup_table(qp).discard_result();
|
||||
|
||||
// We throw the bad_column_family exception because the caller
|
||||
// expects and accounts this type of errors.
|
||||
@@ -124,7 +124,8 @@ future<> table_helper::setup_keyspace(const sstring& keyspace_name, sstring repl
|
||||
}
|
||||
}
|
||||
return seastar::async([&keyspace_name, replication_factor, &qs, tables] {
|
||||
auto& db = cql3::get_local_query_processor().db();
|
||||
cql3::query_processor& qp = cql3::get_local_query_processor();
|
||||
database& db = qp.db();
|
||||
|
||||
// Create a keyspace
|
||||
if (!db.has_keyspace(keyspace_name)) {
|
||||
@@ -141,7 +142,7 @@ future<> table_helper::setup_keyspace(const sstring& keyspace_name, sstring repl
|
||||
// Create tables
|
||||
size_t n = tables.size();
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
tables[i]->setup_table().get();
|
||||
tables[i]->setup_table(qp).get();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
#include "service/migration_manager.hh"
|
||||
|
||||
|
||||
namespace cql3::statements {
|
||||
namespace cql3 {
|
||||
class query_processor;
|
||||
namespace statements {
|
||||
class modification_statement;
|
||||
}
|
||||
}}
|
||||
|
||||
/**
|
||||
* \class table_helper
|
||||
@@ -64,7 +66,7 @@ public:
|
||||
* @return A future that resolves when the operation is complete. Any
|
||||
* possible errors are ignored.
|
||||
*/
|
||||
future<> setup_table() const;
|
||||
future<> setup_table(cql3::query_processor& qp) const;
|
||||
|
||||
/**
|
||||
* @return a future that resolves when the given t_helper is ready to be used for
|
||||
|
||||
Reference in New Issue
Block a user