diff --git a/auth/common.cc b/auth/common.cc index 29ce1b495a..3e986ca6a0 100644 --- a/auth/common.cc +++ b/auth/common.cc @@ -64,7 +64,7 @@ static future<> create_metadata_table_if_missing_impl( static auto ignore_existing = [] (seastar::noncopyable_function()> func) { return futurize_invoke(std::move(func)).handle_exception_type([] (exceptions::already_exists_exception& ignored) { }); }; - auto& db = qp.db(); + auto db = qp.db(); auto parsed_statement = cql3::query_processor::parse_statement(cql); auto& parsed_cf_statement = static_cast(*parsed_statement); diff --git a/auth/default_authorizer.cc b/auth/default_authorizer.cc index 2d7f9d0acd..9fa74b2910 100644 --- a/auth/default_authorizer.cc +++ b/auth/default_authorizer.cc @@ -159,7 +159,7 @@ future<> default_authorizer::start() { _migration_manager).then([this] { _finished = do_after_system_ready(_as, [this] { return async([this] { - wait_for_schema_agreement(_migration_manager, _qp.db(), _as).get0(); + wait_for_schema_agreement(_migration_manager, _qp.db().real_database(), _as).get0(); if (legacy_metadata_exists()) { if (!any_granted().get0()) { diff --git a/auth/password_authenticator.cc b/auth/password_authenticator.cc index d6c5a37404..7a99e6a516 100644 --- a/auth/password_authenticator.cc +++ b/auth/password_authenticator.cc @@ -160,7 +160,7 @@ future<> password_authenticator::start() { _stopped = do_after_system_ready(_as, [this] { return async([this] { - wait_for_schema_agreement(_migration_manager, _qp.db(), _as).get0(); + wait_for_schema_agreement(_migration_manager, _qp.db().real_database(), _as).get0(); if (any_nondefault_role_row_satisfies(_qp, &has_salted_hash).get0()) { if (legacy_metadata_exists()) { diff --git a/auth/service.cc b/auth/service.cc index 02803899e7..abcc625f7a 100644 --- a/auth/service.cc +++ b/auth/service.cc @@ -141,7 +141,7 @@ service::service( } future<> service::create_keyspace_if_missing(::service::migration_manager& mm) const { - auto& db = _qp.db(); + auto db = _qp.db(); if (!db.has_keyspace(meta::AUTH_KS)) { locator::replication_strategy_config_options opts{{"replication_factor", "1"}}; diff --git a/auth/standard_role_manager.cc b/auth/standard_role_manager.cc index d5e79fe2ae..911121d351 100644 --- a/auth/standard_role_manager.cc +++ b/auth/standard_role_manager.cc @@ -243,7 +243,7 @@ future<> standard_role_manager::start() { return this->create_metadata_tables_if_missing().then([this] { _stopped = auth::do_after_system_ready(_as, [this] { return seastar::async([this] { - wait_for_schema_agreement(_migration_manager, _qp.db(), _as).get0(); + wait_for_schema_agreement(_migration_manager, _qp.db().real_database(), _as).get0(); if (any_nondefault_role_row_satisfies(_qp, &has_can_login).get0()) { if (this->legacy_metadata_exists()) { diff --git a/cql3/assignment_testable.hh b/cql3/assignment_testable.hh index df4b6a6dc4..8a9fa5d5a7 100644 --- a/cql3/assignment_testable.hh +++ b/cql3/assignment_testable.hh @@ -42,11 +42,10 @@ #pragma once #include "column_specification.hh" +#include "data_dictionary/data_dictionary.hh" #include #include -class database; - namespace cql3 { class assignment_testable { @@ -70,7 +69,7 @@ public: // Test all elements of toTest for assignment. If all are exact match, return exact match. If any is not assignable, // return not assignable. Otherwise, return weakly assignable. template - static test_result test_all(database& db, const sstring& keyspace, const column_specification& receiver, + static test_result test_all(data_dictionary::database db, const sstring& keyspace, const column_specification& receiver, AssignmentTestablePtrRange&& to_test) { test_result res = test_result::EXACT_MATCH; for (auto&& rt : to_test) { @@ -99,7 +98,7 @@ public: * Most caller should just call the isAssignable() method on the result, though functions have a use for * testing "strong" equality to decide the most precise overload to pick when multiple could match. */ - virtual test_result test_assignment(database& db, const sstring& keyspace, const column_specification& receiver) const = 0; + virtual test_result test_assignment(data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) const = 0; // for error reporting virtual sstring assignment_testable_source_context() const = 0; diff --git a/cql3/attributes.cc b/cql3/attributes.cc index 2f6b004bab..576a55bbc6 100644 --- a/cql3/attributes.cc +++ b/cql3/attributes.cc @@ -150,7 +150,7 @@ void attributes::fill_prepare_context(prepare_context& ctx) { } } -std::unique_ptr attributes::raw::prepare(database& db, const sstring& ks_name, const sstring& cf_name) const { +std::unique_ptr attributes::raw::prepare(data_dictionary::database db, const sstring& ks_name, const sstring& cf_name) const { std::optional ts, ttl, to; if (timestamp.has_value()) { diff --git a/cql3/attributes.hh b/cql3/attributes.hh index cf37b33cc8..23aa014325 100644 --- a/cql3/attributes.hh +++ b/cql3/attributes.hh @@ -85,7 +85,7 @@ public: std::optional time_to_live; std::optional timeout; - std::unique_ptr prepare(database& db, const sstring& ks_name, const sstring& cf_name) const; + std::unique_ptr prepare(data_dictionary::database db, const sstring& ks_name, const sstring& cf_name) const; private: lw_shared_ptr timestamp_receiver(const sstring& ks_name, const sstring& cf_name) const; diff --git a/cql3/column_condition.cc b/cql3/column_condition.cc index a7366f6ec7..8c95e2c9b5 100644 --- a/cql3/column_condition.cc +++ b/cql3/column_condition.cc @@ -284,7 +284,7 @@ bool column_condition::applies_to(const data_value* cell_value, const query_opti } lw_shared_ptr -column_condition::raw::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +column_condition::raw::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { if (receiver.type->is_counter()) { throw exceptions::invalid_request_exception("Conditions on counters are not supported"); } diff --git a/cql3/column_condition.hh b/cql3/column_condition.hh index af2d6cf2f2..93463af031 100644 --- a/cql3/column_condition.hh +++ b/cql3/column_condition.hh @@ -163,7 +163,7 @@ public: std::move(collection_element), expr::oper_t::IN); } - lw_shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const; + lw_shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const; }; }; diff --git a/cql3/cql3_type.cc b/cql3/cql3_type.cc index ee16f46dc6..d71d195862 100644 --- a/cql3/cql3_type.cc +++ b/cql3/cql3_type.cc @@ -26,8 +26,9 @@ #include "cql3_type.hh" #include "cql3/util.hh" #include "ut_name.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "data_dictionary/user_types_metadata.hh" +#include "data_dictionary/keyspace_metadata.hh" #include "types/map.hh" #include "types/set.hh" #include "types/list.hh" @@ -69,11 +70,11 @@ cql3_type::kind_enum_set::prepared cql3_type::get_kind() const { return kind_enum_set::prepare(get_cql3_kind(*_type)); } -cql3_type cql3_type::raw::prepare(database& db, const sstring& keyspace) { +cql3_type cql3_type::raw::prepare(data_dictionary::database db, const sstring& keyspace) { try { auto&& ks = db.find_keyspace(keyspace); return prepare_internal(keyspace, ks.metadata()->user_types()); - } catch (no_such_keyspace& nsk) { + } catch (data_dictionary::no_such_keyspace& nsk) { throw exceptions::invalid_request_exception("Unknown keyspace " + keyspace); } } @@ -98,10 +99,10 @@ public: : _type{type} { } public: - virtual cql3_type prepare(database& db, const sstring& keyspace) override { + virtual cql3_type prepare(data_dictionary::database db, const sstring& keyspace) override { return _type; } - cql3_type prepare_internal(const sstring&, const user_types_metadata&) override { + cql3_type prepare_internal(const sstring&, const data_dictionary::user_types_metadata&) override { return _type; } @@ -158,7 +159,7 @@ public: return true; } - virtual cql3_type prepare_internal(const sstring& keyspace, const user_types_metadata& user_types) override { + virtual cql3_type prepare_internal(const sstring& keyspace, const data_dictionary::user_types_metadata& user_types) override { assert(_values); // "Got null values type for a collection"; if (!is_frozen() && _values->supports_freezing() && !_values->is_frozen()) { @@ -225,7 +226,7 @@ public: _frozen = true; } - virtual cql3_type prepare_internal(const sstring& keyspace, const user_types_metadata& user_types) override { + virtual cql3_type prepare_internal(const sstring& keyspace, const data_dictionary::user_types_metadata& user_types) override { if (_name.has_keyspace()) { // The provided keyspace is the one of the current statement this is part of. If it's different from the keyspace of // the UTName, we reject since we want to limit user types to their own keyspace (see #6643) @@ -284,7 +285,7 @@ public: } _frozen = true; } - virtual cql3_type prepare_internal(const sstring& keyspace, const user_types_metadata& user_types) override { + virtual cql3_type prepare_internal(const sstring& keyspace, const data_dictionary::user_types_metadata& user_types) override { if (!is_frozen()) { freeze(); } diff --git a/cql3/cql3_type.hh b/cql3/cql3_type.hh index 4bfd08c242..eb610f4d00 100644 --- a/cql3/cql3_type.hh +++ b/cql3/cql3_type.hh @@ -42,13 +42,13 @@ #pragma once #include "types.hh" +#include "data_dictionary/data_dictionary.hh" #include "exceptions/exceptions.hh" #include #include "enum_set.hh" -class database; - namespace data_dictionary { +class database; class user_types_metadata; } @@ -85,7 +85,7 @@ public: virtual std::optional keyspace() const; virtual void freeze(); virtual cql3_type prepare_internal(const sstring& keyspace, const data_dictionary::user_types_metadata&) = 0; - virtual cql3_type prepare(database& db, const sstring& keyspace); + virtual cql3_type prepare(data_dictionary::database db, const sstring& keyspace); static shared_ptr from(cql3_type type); static shared_ptr user_type(ut_name name); static shared_ptr map(shared_ptr t1, shared_ptr t2); diff --git a/cql3/expr/expression.hh b/cql3/expr/expression.hh index dd23e3b000..2f5eee1f4d 100644 --- a/cql3/expr/expression.hh +++ b/cql3/expr/expression.hh @@ -34,13 +34,14 @@ #include "cql3/assignment_testable.hh" #include "cql3/cql3_type.hh" #include "cql3/functions/function_name.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" #include "gc_clock.hh" #include "range.hh" #include "seastarx.hh" #include "utils/overloaded_functor.hh" #include "utils/variant_element.hh" #include "cql3/values.hh" +#include "database_fwd.hh" class row; @@ -580,8 +581,8 @@ extern expression replace_token(const expression&, const column_definition*); extern expression search_and_replace(const expression& e, const noncopyable_function (const expression& candidate)>& replace_candidate); -extern expression prepare_expression(const expression& expr, database& db, const sstring& keyspace, lw_shared_ptr receiver); -extern expression prepare_expression_multi_column(const expression& expr, database& db, const sstring& keyspace, const std::vector>& receivers); +extern expression prepare_expression(const expression& expr, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver); +extern expression prepare_expression_multi_column(const expression& expr, data_dictionary::database db, const sstring& keyspace, const std::vector>& receivers); /** @@ -593,11 +594,11 @@ extern expression prepare_expression_multi_column(const expression& expr, databa * Most caller should just call the is_assignable() method on the result, though functions have a use for * testing "strong" equality to decide the most precise overload to pick when multiple could match. */ -extern assignment_testable::test_result test_assignment(const expression& expr, database& db, const sstring& keyspace, const column_specification& receiver); +extern assignment_testable::test_result test_assignment(const expression& expr, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver); // Test all elements of exprs for assignment. If all are exact match, return exact match. If any is not assignable, // return not assignable. Otherwise, return weakly assignable. -extern assignment_testable::test_result test_assignment_all(const std::vector& exprs, database& db, const sstring& keyspace, const column_specification& receiver); +extern assignment_testable::test_result test_assignment_all(const std::vector& exprs, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver); extern shared_ptr as_assignment_testable(expression e); diff --git a/cql3/expr/prepare_expr.cc b/cql3/expr/prepare_expr.cc index 72ac60d7a8..580076c263 100644 --- a/cql3/expr/prepare_expr.cc +++ b/cql3/expr/prepare_expr.cc @@ -51,7 +51,7 @@ usertype_field_spec_of(const column_specification& column, size_t field) { static void -usertype_constructor_validate_assignable_to(const usertype_constructor& u, database& db, const sstring& keyspace, const column_specification& receiver) { +usertype_constructor_validate_assignable_to(const usertype_constructor& u, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { if (!receiver.type->is_user_type()) { throw exceptions::invalid_request_exception(format("Invalid user type literal for {} of type {}", receiver.name, receiver.type->as_cql3_type())); } @@ -72,7 +72,7 @@ usertype_constructor_validate_assignable_to(const usertype_constructor& u, datab static assignment_testable::test_result -usertype_constructor_test_assignment(const usertype_constructor& u, database& db, const sstring& keyspace, const column_specification& receiver) { +usertype_constructor_test_assignment(const usertype_constructor& u, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { try { usertype_constructor_validate_assignable_to(u, db, keyspace, receiver); return assignment_testable::test_result::WEAKLY_ASSIGNABLE; @@ -83,7 +83,7 @@ usertype_constructor_test_assignment(const usertype_constructor& u, database& db static expression -usertype_constructor_prepare_expression(const usertype_constructor& u, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +usertype_constructor_prepare_expression(const usertype_constructor& u, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { usertype_constructor_validate_assignable_to(u, db, keyspace, *receiver); auto&& ut = static_pointer_cast(receiver->type); bool all_terminal = true; @@ -150,7 +150,7 @@ map_value_spec_of(const column_specification& column) { static void -map_validate_assignable_to(const collection_constructor& c, database& db, const sstring& keyspace, const column_specification& receiver) { +map_validate_assignable_to(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { if (!receiver.type->without_reversed().is_map()) { throw exceptions::invalid_request_exception(format("Invalid map literal for {} of type {}", *receiver.name, receiver.type->as_cql3_type())); } @@ -172,7 +172,7 @@ map_validate_assignable_to(const collection_constructor& c, database& db, const static assignment_testable::test_result -map_test_assignment(const collection_constructor& c, database& db, const sstring& keyspace, const column_specification& receiver) { +map_test_assignment(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { if (!dynamic_pointer_cast(receiver.type)) { return assignment_testable::test_result::NOT_ASSIGNABLE; } @@ -201,7 +201,7 @@ map_test_assignment(const collection_constructor& c, database& db, const sstring static expression -map_prepare_expression(const collection_constructor& c, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +map_prepare_expression(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { map_validate_assignable_to(c, db, keyspace, *receiver); auto key_spec = maps::key_spec_of(*receiver); @@ -254,7 +254,7 @@ set_value_spec_of(const column_specification& column) { static void -set_validate_assignable_to(const collection_constructor& c, database& db, const sstring& keyspace, const column_specification& receiver) { +set_validate_assignable_to(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { if (!receiver.type->without_reversed().is_set()) { // We've parsed empty maps as a set literal to break the ambiguity so // handle that case now @@ -275,7 +275,7 @@ set_validate_assignable_to(const collection_constructor& c, database& db, const static assignment_testable::test_result -set_test_assignment(const collection_constructor& c, database& db, const sstring& keyspace, const column_specification& receiver) { +set_test_assignment(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { if (!receiver.type->without_reversed().is_set()) { // We've parsed empty maps as a set literal to break the ambiguity so handle that case now if (dynamic_pointer_cast(receiver.type) && c.elements.empty()) { @@ -296,7 +296,7 @@ set_test_assignment(const collection_constructor& c, database& db, const sstring static expression -set_prepare_expression(const collection_constructor& c, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +set_prepare_expression(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { set_validate_assignable_to(c, db, keyspace, *receiver); if (c.elements.empty()) { @@ -363,7 +363,7 @@ list_value_spec_of(const column_specification& column) { static void -list_validate_assignable_to(const collection_constructor& c, database& db, const sstring keyspace, const column_specification& receiver) { +list_validate_assignable_to(const collection_constructor& c, data_dictionary::database db, const sstring keyspace, const column_specification& receiver) { if (!receiver.type->without_reversed().is_list()) { throw exceptions::invalid_request_exception(format("Invalid list literal for {} of type {}", *receiver.name, receiver.type->as_cql3_type())); @@ -379,7 +379,7 @@ list_validate_assignable_to(const collection_constructor& c, database& db, const static assignment_testable::test_result -list_test_assignment(const collection_constructor& c, database& db, const sstring& keyspace, const column_specification& receiver) { +list_test_assignment(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { if (!dynamic_pointer_cast(receiver.type)) { return assignment_testable::test_result::NOT_ASSIGNABLE; } @@ -396,7 +396,7 @@ list_test_assignment(const collection_constructor& c, database& db, const sstrin static expression -list_prepare_expression(const collection_constructor& c, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +list_prepare_expression(const collection_constructor& c, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { list_validate_assignable_to(c, db, keyspace, *receiver); // In Cassandra, an empty (unfrozen) map/set/list is equivalent to the column being null. In @@ -446,7 +446,7 @@ component_spec_of(const column_specification& column, size_t component) { static void -tuple_constructor_validate_assignable_to(const tuple_constructor& tc, database& db, const sstring& keyspace, const column_specification& receiver) { +tuple_constructor_validate_assignable_to(const tuple_constructor& tc, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { auto tt = dynamic_pointer_cast(receiver.type->underlying_type()); if (!tt) { throw exceptions::invalid_request_exception(format("Invalid tuple type literal for {} of type {}", receiver.name, receiver.type->as_cql3_type())); @@ -467,7 +467,7 @@ tuple_constructor_validate_assignable_to(const tuple_constructor& tc, database& static assignment_testable::test_result -tuple_constructor_test_assignment(const tuple_constructor& tc, database& db, const sstring& keyspace, const column_specification& receiver) { +tuple_constructor_test_assignment(const tuple_constructor& tc, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { try { tuple_constructor_validate_assignable_to(tc, db, keyspace, receiver); return assignment_testable::test_result::WEAKLY_ASSIGNABLE; @@ -478,7 +478,7 @@ tuple_constructor_test_assignment(const tuple_constructor& tc, database& db, con static expression -tuple_constructor_prepare_nontuple(const tuple_constructor& tc, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +tuple_constructor_prepare_nontuple(const tuple_constructor& tc, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { tuple_constructor_validate_assignable_to(tc, db, keyspace, *receiver); std::vector values; bool all_terminal = true; @@ -502,7 +502,7 @@ tuple_constructor_prepare_nontuple(const tuple_constructor& tc, database& db, co static expression -tuple_constructor_prepare_tuple(const tuple_constructor& tc, database& db, const sstring& keyspace, const std::vector>& receivers) { +tuple_constructor_prepare_tuple(const tuple_constructor& tc, data_dictionary::database db, const sstring& keyspace, const std::vector>& receivers) { if (tc.elements.size() != receivers.size()) { throw exceptions::invalid_request_exception(format("Expected {:d} elements in value tuple, but got {:d}: {}", receivers.size(), tc.elements.size(), tc)); } @@ -566,7 +566,7 @@ untyped_constant_parsed_value(const untyped_constant uc, data_type validator) static assignment_testable::test_result -untyped_constant_test_assignment(const untyped_constant& uc, database& db, const sstring& keyspace, const column_specification& receiver) +untyped_constant_test_assignment(const untyped_constant& uc, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { auto receiver_type = receiver.type->as_cql3_type(); if (receiver_type.is_collection() || receiver_type.is_user_type()) { @@ -640,7 +640,7 @@ untyped_constant_test_assignment(const untyped_constant& uc, database& db, const static constant -untyped_constant_prepare_expression(const untyped_constant& uc, database& db, const sstring& keyspace, lw_shared_ptr receiver) +untyped_constant_prepare_expression(const untyped_constant& uc, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { if (!is_assignable(untyped_constant_test_assignment(uc, db, keyspace, *receiver))) { throw exceptions::invalid_request_exception(format("Invalid {} constant ({}) for \"{}\" of type {}", @@ -652,13 +652,13 @@ untyped_constant_prepare_expression(const untyped_constant& uc, database& db, co static assignment_testable::test_result -bind_variable_test_assignment(const bind_variable& bv, database& db, const sstring& keyspace, const column_specification& receiver) { +bind_variable_test_assignment(const bind_variable& bv, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { return assignment_testable::test_result::WEAKLY_ASSIGNABLE; } static bind_variable -bind_variable_scalar_prepare_expression(const bind_variable& bv, database& db, const sstring& keyspace, lw_shared_ptr receiver) +bind_variable_scalar_prepare_expression(const bind_variable& bv, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { return bind_variable { .shape = bind_variable::shape_type::scalar, @@ -676,7 +676,7 @@ bind_variable_scalar_in_make_receiver(const column_specification& receiver) { static bind_variable -bind_variable_scalar_in_prepare_expression(const bind_variable& bv, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +bind_variable_scalar_in_prepare_expression(const bind_variable& bv, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { return bind_variable { .shape = bind_variable::shape_type::scalar, .bind_index = bv.bind_index, @@ -706,7 +706,7 @@ bind_variable_tuple_make_receiver(const std::vector>& receivers) { +bind_variable_tuple_prepare_expression(const bind_variable& bv, data_dictionary::database db, const sstring& keyspace, const std::vector>& receivers) { return bind_variable { .shape = bind_variable::shape_type::tuple, .bind_index = bv.bind_index, @@ -741,7 +741,7 @@ bind_variable_tuple_in_make_receiver(const std::vector>& receivers) { +bind_variable_tuple_in_prepare_expression(const bind_variable& bv, data_dictionary::database db, const sstring& keyspace, const std::vector>& receivers) { return bind_variable { .shape = bind_variable::shape_type::tuple_in, .bind_index = bv.bind_index, @@ -751,7 +751,7 @@ bind_variable_tuple_in_prepare_expression(const bind_variable& bv, database& db, static assignment_testable::test_result -null_test_assignment(database& db, +null_test_assignment(data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { return receiver.type->is_counter() @@ -761,7 +761,7 @@ null_test_assignment(database& db, static constant -null_prepare_expression(database& db, const sstring& keyspace, lw_shared_ptr receiver) { +null_prepare_expression(data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { if (!is_assignable(null_test_assignment(db, keyspace, *receiver))) { throw exceptions::invalid_request_exception("Invalid null value for counter increment/decrement"); } @@ -776,7 +776,7 @@ cast_display_name(const cast& c) { static lw_shared_ptr -casted_spec_of(const cast& c, database& db, const sstring& keyspace, const column_specification& receiver) { +casted_spec_of(const cast& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { auto& type = std::get>(c.type); return make_lw_shared(receiver.ks_name, receiver.cf_name, ::make_shared(cast_display_name(c), true), type->prepare(db, keyspace).get_type()); @@ -784,7 +784,7 @@ casted_spec_of(const cast& c, database& db, const sstring& keyspace, const colum static assignment_testable::test_result -cast_test_assignment(const cast& c, database& db, const sstring& keyspace, const column_specification& receiver) { +cast_test_assignment(const cast& c, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { auto type = std::get>(c.type); try { auto&& casted_type = type->prepare(db, keyspace).get_type(); @@ -802,7 +802,7 @@ cast_test_assignment(const cast& c, database& db, const sstring& keyspace, const static expression -cast_prepare_expression(const cast& c, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +cast_prepare_expression(const cast& c, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { auto type = std::get>(c.type); if (!is_assignable(test_assignment(c.arg, db, keyspace, *casted_spec_of(c, db, keyspace, *receiver)))) { throw exceptions::invalid_request_exception(format("Cannot cast value {} to type {}", c.arg, type)); @@ -814,7 +814,7 @@ cast_prepare_expression(const cast& c, database& db, const sstring& keyspace, lw } expr::expression -prepare_function_call(const expr::function_call& fc, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +prepare_function_call(const expr::function_call& fc, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { auto&& fun = std::visit(overloaded_functor{ [] (const shared_ptr& func) { return func; @@ -875,7 +875,7 @@ prepare_function_call(const expr::function_call& fc, database& db, const sstring } assignment_testable::test_result -test_assignment_function_call(const cql3::expr::function_call& fc, database& db, const sstring& keyspace, const column_specification& receiver) { +test_assignment_function_call(const cql3::expr::function_call& fc, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { // Note: Functions.get() will return null if the function doesn't exist, or throw is no function matching // the arguments can be found. We may get one of those if an undefined/wrong function is used as argument // of another, existing, function. In that case, we return true here because we'll throw a proper exception @@ -903,7 +903,7 @@ test_assignment_function_call(const cql3::expr::function_call& fc, database& db, } expression -prepare_expression(const expression& expr, database& db, const sstring& keyspace, lw_shared_ptr receiver) { +prepare_expression(const expression& expr, data_dictionary::database db, const sstring& keyspace, lw_shared_ptr receiver) { return expr::visit(overloaded_functor{ [] (const constant&) -> expression { on_internal_error(expr_logger, "Can't prepare constant_value, it should not appear in parser output"); @@ -968,7 +968,7 @@ prepare_expression(const expression& expr, database& db, const sstring& keyspace } expression -prepare_expression_multi_column(const expression& expr, database& db, const sstring& keyspace, const std::vector>& receivers) { +prepare_expression_multi_column(const expression& expr, data_dictionary::database db, const sstring& keyspace, const std::vector>& receivers) { return expr::visit(overloaded_functor{ [&] (const bind_variable& bv) -> expression { switch (bv.shape) { @@ -989,7 +989,7 @@ prepare_expression_multi_column(const expression& expr, database& db, const sstr } assignment_testable::test_result -test_assignment(const expression& expr, database& db, const sstring& keyspace, const column_specification& receiver) { +test_assignment(const expression& expr, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { using test_result = assignment_testable::test_result; return expr::visit(overloaded_functor{ [&] (const constant&) -> test_result { @@ -1051,7 +1051,7 @@ test_assignment(const expression& expr, database& db, const sstring& keyspace, c } assignment_testable::test_result -test_assignment_all(const std::vector& to_test, database& db, const sstring& keyspace, const column_specification& receiver) { +test_assignment_all(const std::vector& to_test, data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) { using test_result = assignment_testable::test_result; test_result res = test_result::EXACT_MATCH; for (auto&& e : to_test) { @@ -1070,7 +1070,7 @@ class assignment_testable_expression : public assignment_testable { expression _e; public: explicit assignment_testable_expression(expression e) : _e(std::move(e)) {} - virtual test_result test_assignment(database& db, const sstring& keyspace, const column_specification& receiver) const override { + virtual test_result test_assignment(data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) const override { return expr::test_assignment(_e, db, keyspace, receiver); } virtual sstring assignment_testable_source_context() const override { diff --git a/cql3/functions/functions.cc b/cql3/functions/functions.cc index 4a00dc0f14..4bcdbed373 100644 --- a/cql3/functions/functions.cc +++ b/cql3/functions/functions.cc @@ -27,7 +27,7 @@ #include "cql3/constants.hh" #include "cql3/user_types.hh" #include "cql3/type_json.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "types/map.hh" #include "types/set.hh" #include "types/list.hh" @@ -191,7 +191,7 @@ make_to_json_function(data_type t) { inline shared_ptr -make_from_json_function(database& db, const sstring& keyspace, data_type t) { +make_from_json_function(data_dictionary::database db, const sstring& keyspace, data_type t) { return make_native_scalar_function("fromjson", t, {utf8_type}, [&db, keyspace, t](cql_serialization_format sf, const std::vector& parameters) -> bytes_opt { try { @@ -209,7 +209,7 @@ make_from_json_function(database& db, const sstring& keyspace, data_type t) { } shared_ptr -functions::get(database& db, +functions::get(data_dictionary::database db, const sstring& keyspace, const function_name& name, const std::vector>& provided_args, @@ -376,7 +376,7 @@ functions::find(const function_name& name, const std::vector& arg_typ // This method and matchArguments are somewhat duplicate, but this method allows us to provide more precise errors in the common // case where there is no override for a given function. This is thus probably worth the minor code duplication. void -functions::validate_types(database& db, +functions::validate_types(data_dictionary::database db, const sstring& keyspace, shared_ptr fun, const std::vector>& provided_args, @@ -407,7 +407,7 @@ functions::validate_types(database& db, } assignment_testable::test_result -functions::match_arguments(database& db, const sstring& keyspace, +functions::match_arguments(data_dictionary::database db, const sstring& keyspace, shared_ptr fun, const std::vector>& provided_args, const sstring& receiver_ks, diff --git a/cql3/functions/functions.hh b/cql3/functions/functions.hh index de8e809868..9e1a57ece0 100644 --- a/cql3/functions/functions.hh +++ b/cql3/functions/functions.hh @@ -70,7 +70,7 @@ public: static lw_shared_ptr make_arg_spec(const sstring& receiver_ks, const sstring& receiver_cf, const function& fun, size_t i); public: - static shared_ptr get(database& db, + static shared_ptr get(data_dictionary::database db, const sstring& keyspace, const function_name& name, const std::vector>& provided_args, @@ -78,7 +78,7 @@ public: const sstring& receiver_cf, const column_specification* receiver = nullptr); template - static shared_ptr get(database& db, + static shared_ptr get(data_dictionary::database db, const sstring& keyspace, const function_name& name, AssignmentTestablePtrRange&& provided_args, @@ -102,13 +102,13 @@ private: // This method and matchArguments are somewhat duplicate, but this method allows us to provide more precise errors in the common // case where there is no override for a given function. This is thus probably worth the minor code duplication. - static void validate_types(database& db, + static void validate_types(data_dictionary::database db, const sstring& keyspace, shared_ptr fun, const std::vector>& provided_args, const sstring& receiver_ks, const sstring& receiver_cf); - static assignment_testable::test_result match_arguments(database& db, const sstring& keyspace, + static assignment_testable::test_result match_arguments(data_dictionary::database db, const sstring& keyspace, shared_ptr fun, const std::vector>& provided_args, const sstring& receiver_ks, diff --git a/cql3/multi_column_relation.hh b/cql3/multi_column_relation.hh index 732023ec66..ec6bf44d86 100644 --- a/cql3/multi_column_relation.hh +++ b/cql3/multi_column_relation.hh @@ -149,7 +149,7 @@ public: virtual bool is_multi_column() const override { return true; } protected: - virtual shared_ptr new_EQ_restriction(database& db, schema_ptr schema, + virtual shared_ptr new_EQ_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override { auto rs = receivers(db, *schema); std::vector> col_specs(rs.size()); @@ -160,7 +160,7 @@ protected: return ::make_shared(schema, rs, std::move(e)); } - virtual shared_ptr new_IN_restriction(database& db, schema_ptr schema, + virtual shared_ptr new_IN_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override { auto rs = receivers(db, *schema); std::vector> col_specs(rs.size()); @@ -183,7 +183,7 @@ protected: } } - virtual shared_ptr new_slice_restriction(database& db, schema_ptr schema, + virtual shared_ptr new_slice_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, statements::bound bound, bool inclusive) override { auto rs = receivers(db, *schema); @@ -195,13 +195,13 @@ protected: return ::make_shared(schema, rs, bound, inclusive, std::move(e), _mode); } - virtual shared_ptr new_contains_restriction(database& db, schema_ptr schema, + virtual shared_ptr new_contains_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, bool is_key) override { throw exceptions::invalid_request_exception(format("{} cannot be used for Multi-column relations", get_operator())); } virtual ::shared_ptr new_LIKE_restriction( - database& db, schema_ptr schema, prepare_context& ctx) override { + data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override { throw exceptions::invalid_request_exception("LIKE cannot be used for Multi-column relations"); } @@ -213,14 +213,14 @@ protected: } virtual expr::expression to_expression(const std::vector>& receivers, - const expr::expression& raw, database& db, const sstring& keyspace, + const expr::expression& raw, data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const override { auto e = prepare_expression_multi_column(raw, db, keyspace, receivers); expr::fill_prepare_context(e, ctx); return e; } - std::vector receivers(database& db, const schema& schema) { + std::vector receivers(data_dictionary::database db, const schema& schema) { using namespace statements::request_validations; int previous_position = -1; diff --git a/cql3/operation.cc b/cql3/operation.cc index 5d29e1516f..050df4a164 100644 --- a/cql3/operation.cc +++ b/cql3/operation.cc @@ -58,7 +58,7 @@ operation::set_element::to_string(const column_definition& receiver) const { } shared_ptr -operation::set_element::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::set_element::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { using exceptions::invalid_request_exception; auto rtype = dynamic_pointer_cast(receiver.type); if (!rtype) { @@ -99,7 +99,7 @@ operation::set_field::to_string(const column_definition& receiver) const { } shared_ptr -operation::set_field::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::set_field::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { if (!receiver.type->is_user_type()) { throw exceptions::invalid_request_exception( format("Invalid operation ({}) for non-UDT column {}", to_string(receiver), receiver.name_as_text())); @@ -135,7 +135,7 @@ operation::field_deletion::affected_column() const { } shared_ptr -operation::field_deletion::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::field_deletion::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { if (!receiver.type->is_user_type()) { throw exceptions::invalid_request_exception( format("Invalid deletion operation for non-UDT column {}", receiver.name_as_text())); @@ -160,7 +160,7 @@ operation::addition::to_string(const column_definition& receiver) const { } shared_ptr -operation::addition::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::addition::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { auto v = prepare_expression(_value, db, keyspace, receiver.column_specification); auto ctype = dynamic_pointer_cast(receiver.type); @@ -195,7 +195,7 @@ operation::subtraction::to_string(const column_definition& receiver) const { } shared_ptr -operation::subtraction::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::subtraction::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { auto ctype = dynamic_pointer_cast(receiver.type); if (!ctype) { if (!receiver.is_counter()) { @@ -237,7 +237,7 @@ operation::prepend::to_string(const column_definition& receiver) const { } shared_ptr -operation::prepend::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::prepend::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { auto v = prepare_expression(_value, db, keyspace, receiver.column_specification); if (!dynamic_cast(receiver.type.get())) { @@ -256,7 +256,7 @@ operation::prepend::is_compatible_with(const std::unique_ptr& other) ::shared_ptr -operation::set_value::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::set_value::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { auto v = prepare_expression(_value, db, keyspace, receiver.column_specification); if (receiver.type->is_counter()) { @@ -284,7 +284,7 @@ operation::set_value::prepare(database& db, const sstring& keyspace, const colum } ::shared_ptr -operation::set_counter_value_from_tuple_list::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::set_counter_value_from_tuple_list::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { static thread_local const data_type counter_tuple_type = tuple_type_impl::get_instance({int32_type, uuid_type, long_type, long_type}); static thread_local const data_type counter_tuple_list_type = list_type_impl::get_instance(counter_tuple_type, true); @@ -372,7 +372,7 @@ operation::element_deletion::affected_column() const { } shared_ptr -operation::element_deletion::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const { +operation::element_deletion::prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const { if (!receiver.type->is_collection()) { throw exceptions::invalid_request_exception(format("Invalid deletion operation for non collection column {}", receiver.name())); } else if (!receiver.type->is_multi_cell()) { diff --git a/cql3/operation.hh b/cql3/operation.hh index 50454e92b0..5c7f70495c 100644 --- a/cql3/operation.hh +++ b/cql3/operation.hh @@ -43,7 +43,7 @@ #include #include "exceptions/exceptions.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" #include "update_parameters.hh" #include "cql3/column_identifier.hh" #include "cql3/expr/expression.hh" @@ -143,7 +143,7 @@ public: * be a true column. * @return the prepared update operation. */ - virtual ::shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const = 0; + virtual ::shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const = 0; /** * @return whether this operation can be applied alongside the {@code @@ -180,7 +180,7 @@ public: * @param receiver the "column" this operation applies to. * @return the prepared delete operation. */ - virtual ::shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const = 0; + virtual ::shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const = 0; }; class set_value; @@ -197,7 +197,7 @@ public: : _selector(std::move(selector)), _value(std::move(value)), _by_uuid(by_uuid) { } - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; virtual bool is_compatible_with(const std::unique_ptr& other) const override; }; @@ -213,7 +213,7 @@ public: : _field(std::move(field)), _value(std::move(value)) { } - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; virtual bool is_compatible_with(const std::unique_ptr& other) const override; }; @@ -230,7 +230,7 @@ public: virtual const column_identifier::raw& affected_column() const override; - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; }; class addition : public raw_update { @@ -242,7 +242,7 @@ public: : _value(std::move(value)) { } - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; virtual bool is_compatible_with(const std::unique_ptr& other) const override; }; @@ -256,7 +256,7 @@ public: : _value(std::move(value)) { } - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; virtual bool is_compatible_with(const std::unique_ptr& other) const override; }; @@ -270,7 +270,7 @@ public: : _value(std::move(value)) { } - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; virtual bool is_compatible_with(const std::unique_ptr& other) const override; }; @@ -285,7 +285,7 @@ public: : _id(std::move(id)), _element(std::move(element)) { } virtual const column_identifier::raw& affected_column() const override; - virtual shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; }; }; diff --git a/cql3/operation_impl.hh b/cql3/operation_impl.hh index b2db462252..40d10d299f 100644 --- a/cql3/operation_impl.hh +++ b/cql3/operation_impl.hh @@ -56,7 +56,7 @@ protected: public: set_value(expr::expression value) : _value(std::move(value)) {} - virtual ::shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + virtual ::shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; #if 0 protected String toString(ColumnSpecification column) @@ -71,7 +71,7 @@ public: class operation::set_counter_value_from_tuple_list : public set_value { public: using set_value::set_value; - ::shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override; + ::shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override; }; class operation::column_deletion : public raw_deletion { @@ -86,7 +86,7 @@ public: return *_id; } - virtual ::shared_ptr prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override { + virtual ::shared_ptr prepare(data_dictionary::database db, const sstring& keyspace, const column_definition& receiver) const override { // No validation, deleting a column is always "well typed" return ::make_shared(receiver); } diff --git a/cql3/query_processor.cc b/cql3/query_processor.cc index b5eec38f01..7a6a19174b 100644 --- a/cql3/query_processor.cc +++ b/cql3/query_processor.cc @@ -50,7 +50,7 @@ #include "cql3/util.hh" #include "cql3/untyped_result_set.hh" #include "db/config.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "hashers.hh" namespace cql3 { @@ -85,7 +85,7 @@ public: } }; -query_processor::query_processor(service::storage_proxy& proxy, database& db, service::migration_notifier& mn, service::migration_manager& mm, query_processor::memory_config mcfg, cql_config& cql_cfg) +query_processor::query_processor(service::storage_proxy& proxy, data_dictionary::database db, service::migration_notifier& mn, service::migration_manager& mm, query_processor::memory_config mcfg, cql_config& cql_cfg) : _migration_subscriber{std::make_unique(this)} , _proxy(proxy) , _db(db) diff --git a/cql3/query_processor.hh b/cql3/query_processor.hh index a222c070fc..d1a1761145 100644 --- a/cql3/query_processor.hh +++ b/cql3/query_processor.hh @@ -119,7 +119,7 @@ public: private: std::unique_ptr _migration_subscriber; service::storage_proxy& _proxy; - database& _db; + data_dictionary::database _db; service::migration_notifier& _mnotifier; service::migration_manager& _mm; const cql_config& _cql_config; @@ -157,11 +157,11 @@ public: static std::unique_ptr parse_statement(const std::string_view& query); static std::vector> parse_statements(std::string_view queries); - query_processor(service::storage_proxy& proxy, database& db, service::migration_notifier& mn, service::migration_manager& mm, memory_config mcfg, cql_config& cql_cfg); + query_processor(service::storage_proxy& proxy, data_dictionary::database db, service::migration_notifier& mn, service::migration_manager& mm, memory_config mcfg, cql_config& cql_cfg); ~query_processor(); - database& db() { + data_dictionary::database db() { return _db; } diff --git a/cql3/relation.hh b/cql3/relation.hh index 3a3861c268..08532be7d4 100644 --- a/cql3/relation.hh +++ b/cql3/relation.hh @@ -138,7 +138,7 @@ public: * @return the Restriction corresponding to this Relation * @throws InvalidRequestException if this Relation is not valid */ - virtual ::shared_ptr to_restriction(database& db, schema_ptr schema, prepare_context& ctx) final { + virtual ::shared_ptr to_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) final { if (_relation_type == expr::oper_t::EQ) { return new_EQ_restriction(db, schema, ctx); } else if (_relation_type == expr::oper_t::LT) { @@ -180,7 +180,7 @@ public: * @return a new EQ restriction instance. * @throws InvalidRequestException if the relation cannot be converted into an EQ restriction. */ - virtual ::shared_ptr new_EQ_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_EQ_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) = 0; /** @@ -191,7 +191,7 @@ public: * @return a new IN restriction instance * @throws InvalidRequestException if the relation cannot be converted into an IN restriction. */ - virtual ::shared_ptr new_IN_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_IN_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) = 0; /** @@ -204,7 +204,7 @@ public: * @return a new slice restriction instance * @throws InvalidRequestException if the Relation is not valid */ - virtual ::shared_ptr new_slice_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_slice_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, statements::bound bound, bool inclusive) = 0; @@ -218,13 +218,13 @@ public: * @return a new Contains ::shared_ptr instance * @throws InvalidRequestException if the Relation is not valid */ - virtual ::shared_ptr new_contains_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_contains_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, bool isKey) = 0; /** * Creates a new LIKE restriction instance. */ - virtual ::shared_ptr new_LIKE_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_LIKE_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) = 0; /** @@ -250,7 +250,7 @@ protected: */ virtual expr::expression to_expression(const std::vector>& receivers, const expr::expression& raw, - database& db, + data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const = 0; @@ -266,7 +266,7 @@ protected: */ std::vector to_expressions(const std::vector>& receivers, const std::vector& raws, - database& db, + data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const { std::vector expressions; diff --git a/cql3/restrictions/statement_restrictions.cc b/cql3/restrictions/statement_restrictions.cc index 25e0e2ac16..89e3790e0e 100644 --- a/cql3/restrictions/statement_restrictions.cc +++ b/cql3/restrictions/statement_restrictions.cc @@ -33,7 +33,7 @@ #include "statement_restrictions.hh" #include "multi_column_restriction.hh" #include "token_restriction.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "cartesian_product.hh" #include "cql3/constants.hh" @@ -380,7 +380,7 @@ static std::vector extract_clustering_prefix_restrictions( return prefix; } -statement_restrictions::statement_restrictions(database& db, +statement_restrictions::statement_restrictions(data_dictionary::database db, schema_ptr schema, statements::statement_type type, const std::vector<::shared_ptr>& where_clause, @@ -446,7 +446,7 @@ statement_restrictions::statement_restrictions(database& db, _clustering_prefix_restrictions = extract_clustering_prefix_restrictions(*_where, _schema); _partition_range_restrictions = extract_partition_range(*_where, _schema); } - auto& cf = db.find_column_family(schema); + auto cf = db.find_column_family(schema); auto& sim = cf.get_index_manager(); const expr::allow_local_index allow_local( !_partition_key_restrictions->has_unrestricted_components(*_schema) @@ -576,7 +576,7 @@ const single_column_restrictions::restrictions_map* get_individual_restrictions_ } // anonymous namespace -std::pair, ::shared_ptr> statement_restrictions::find_idx(secondary_index::secondary_index_manager& sim) const { +std::pair, ::shared_ptr> statement_restrictions::find_idx(const secondary_index::secondary_index_manager& sim) const { std::optional chosen_index; int chosen_index_score = 0; ::shared_ptr chosen_index_restrictions; @@ -606,7 +606,7 @@ bool statement_restrictions::has_eq_restriction_on_column(const column_definitio return expr::has_eq_restriction_on_column(column, *_where); } -std::vector statement_restrictions::get_column_defs_for_filtering(database& db) const { +std::vector statement_restrictions::get_column_defs_for_filtering(data_dictionary::database db) const { std::vector column_defs_for_filtering; if (need_filtering()) { auto& sim = db.find_column_family(_schema).get_index_manager(); @@ -1537,7 +1537,7 @@ bool statement_restrictions::need_filtering() const { if (_has_queriable_ck_index && _uses_secondary_indexing) { // In cases where we use an index, clustering column restrictions might cause the need for filtering. // TODO: This is overly conservative, there are some cases when this returns true but filtering - // is not needed. Because of that the database will sometimes perform filtering when it's not actually needed. + // is not needed. Because of that the data_dictionary::database will sometimes perform filtering when it's not actually needed. // Query performance shouldn't be affected much, at most we will filter rows that are all correct. // Here are some cases to consider: // On a table with primary key (p, c1, c2, c3) with an index on c3 diff --git a/cql3/restrictions/statement_restrictions.hh b/cql3/restrictions/statement_restrictions.hh index 1cedab446d..ba64fb8513 100644 --- a/cql3/restrictions/statement_restrictions.hh +++ b/cql3/restrictions/statement_restrictions.hh @@ -150,7 +150,7 @@ public: */ statement_restrictions(schema_ptr schema, bool allow_filtering); - statement_restrictions(database& db, + statement_restrictions(data_dictionary::database db, schema_ptr schema, statements::statement_type type, const std::vector<::shared_ptr>& where_clause, @@ -223,10 +223,10 @@ public: /** * Builds a possibly empty collection of column definitions that will be used for filtering - * @param db - the database context + * @param db - the data_dictionary::database context * @return A list with the column definitions needed for filtering. */ - std::vector get_column_defs_for_filtering(database& db) const; + std::vector get_column_defs_for_filtering(data_dictionary::database db) const; /** * Gives a score that the index has - index with the highest score will be chosen @@ -236,11 +236,11 @@ public: /** * Determines the index to be used with the restriction. - * @param db - the database context (for extracting index manager) + * @param db - the data_dictionary::database context (for extracting index manager) * @return If an index can be used, an optional containing this index, otherwise an empty optional. * In case the index is returned, second parameter returns the index restriction it uses. */ - std::pair, ::shared_ptr> find_idx(secondary_index::secondary_index_manager& sim) const; + std::pair, ::shared_ptr> find_idx(const secondary_index::secondary_index_manager& sim) const; /** * Checks if the partition key has some unrestricted components. diff --git a/cql3/selection/selectable.cc b/cql3/selection/selectable.cc index dde4b2ea53..9649913695 100644 --- a/cql3/selection/selectable.cc +++ b/cql3/selection/selectable.cc @@ -43,7 +43,7 @@ class selectable_column : public selectable { column_identifier _ci; public: explicit selectable_column(column_identifier ci) : _ci(std::move(ci)) {} - virtual ::shared_ptr new_selector_factory(database& db, schema_ptr schema, + virtual ::shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr schema, std::vector& defs) override; virtual sstring to_string() const override { return _ci.to_string(); @@ -51,7 +51,7 @@ public: }; ::shared_ptr -selectable_column::new_selector_factory(database& db, schema_ptr schema, std::vector& defs) { +selectable_column::new_selector_factory(data_dictionary::database db, schema_ptr schema, std::vector& defs) { auto def = get_column_definition(*schema, _ci); if (!def) { throw exceptions::invalid_request_exception(format("Undefined name {} in selection clause", _ci.text())); @@ -65,7 +65,7 @@ selectable_column::new_selector_factory(database& db, schema_ptr schema, std::ve } shared_ptr -selectable::writetime_or_ttl::new_selector_factory(database& db, schema_ptr s, std::vector& defs) { +selectable::writetime_or_ttl::new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) { auto&& def = s->get_column_definition(_id->name()); if (!def || def->is_hidden_from_cql()) { throw exceptions::invalid_request_exception(format("Undefined name {} in selection clause", _id)); @@ -90,7 +90,7 @@ selectable::writetime_or_ttl::to_string() const { } shared_ptr -selectable::with_function::new_selector_factory(database& db, schema_ptr s, std::vector& defs) { +selectable::with_function::new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) { auto&& factories = selector_factories::create_factories_and_collect_column_definitions(_args, db, s, defs); // resolve built-in functions before user defined functions @@ -118,7 +118,7 @@ make_count_rows_function_expression() { } shared_ptr -selectable::with_anonymous_function::new_selector_factory(database& db, schema_ptr s, std::vector& defs) { +selectable::with_anonymous_function::new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) { auto&& factories = selector_factories::create_factories_and_collect_column_definitions(_args, db, s, defs); return abstract_function_selector::new_factory(_function, std::move(factories)); } @@ -129,7 +129,7 @@ selectable::with_anonymous_function::to_string() const { } shared_ptr -selectable::with_field_selection::new_selector_factory(database& db, schema_ptr s, std::vector& defs) { +selectable::with_field_selection::new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) { auto&& factory = _selected->new_selector_factory(db, s, defs); auto&& type = factory->new_instance()->get_type(); if (!type->underlying_type()->is_user_type()) { @@ -153,7 +153,7 @@ selectable::with_field_selection::to_string() const { } shared_ptr -selectable::with_cast::new_selector_factory(database& db, schema_ptr s, std::vector& defs) { +selectable::with_cast::new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) { std::vector> args{_arg}; auto&& factories = selector_factories::create_factories_and_collect_column_definitions(args, db, s, defs); auto&& fun = functions::castas_functions::get(_type.get_type(), factories->new_instances()); diff --git a/cql3/selection/selectable.hh b/cql3/selection/selectable.hh index a0a4ba5b92..3252d6fabc 100644 --- a/cql3/selection/selectable.hh +++ b/cql3/selection/selectable.hh @@ -58,7 +58,7 @@ class selectable; class selectable { public: virtual ~selectable() {} - virtual ::shared_ptr new_selector_factory(database& db, schema_ptr schema, std::vector& defs) = 0; + virtual ::shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr schema, std::vector& defs) = 0; virtual sstring to_string() const = 0; protected: static size_t add_and_get_index(const column_definition& def, std::vector& defs) { @@ -92,7 +92,7 @@ public: virtual sstring to_string() const override; - virtual shared_ptr new_selector_factory(database& db, schema_ptr s, std::vector& defs) override; + virtual shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) override; }; class selectable::with_anonymous_function : public selectable { @@ -105,7 +105,7 @@ public: virtual sstring to_string() const override; - virtual shared_ptr new_selector_factory(database& db, schema_ptr s, std::vector& defs) override; + virtual shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) override; }; class selectable::with_cast : public selectable { @@ -118,7 +118,7 @@ public: virtual sstring to_string() const override; - virtual shared_ptr new_selector_factory(database& db, schema_ptr s, std::vector& defs) override; + virtual shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) override; }; } diff --git a/cql3/selection/selectable_with_field_selection.hh b/cql3/selection/selectable_with_field_selection.hh index 8c7b9874a6..216271cfe4 100644 --- a/cql3/selection/selectable_with_field_selection.hh +++ b/cql3/selection/selectable_with_field_selection.hh @@ -61,7 +61,7 @@ public: virtual sstring to_string() const override; - virtual shared_ptr new_selector_factory(database& db, schema_ptr s, std::vector& defs) override; + virtual shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) override; }; } diff --git a/cql3/selection/selection.cc b/cql3/selection/selection.cc index 5ee9556cc6..e888eb0a85 100644 --- a/cql3/selection/selection.cc +++ b/cql3/selection/selection.cc @@ -282,7 +282,7 @@ uint32_t selection::add_column_for_post_processing(const column_definition& c) { return _columns.size() - 1; } -::shared_ptr selection::from_selectors(database& db, schema_ptr schema, const std::vector<::shared_ptr>& raw_selectors) { +::shared_ptr selection::from_selectors(data_dictionary::database db, schema_ptr schema, const std::vector<::shared_ptr>& raw_selectors) { std::vector defs; ::shared_ptr factories = diff --git a/cql3/selection/selection.hh b/cql3/selection/selection.hh index 4c720531d6..412a14c698 100644 --- a/cql3/selection/selection.hh +++ b/cql3/selection/selection.hh @@ -156,7 +156,7 @@ private: static std::vector> collect_metadata(const schema& schema, const std::vector<::shared_ptr>& raw_selectors, const selector_factories& factories); public: - static ::shared_ptr from_selectors(database& db, schema_ptr schema, const std::vector<::shared_ptr>& raw_selectors); + static ::shared_ptr from_selectors(data_dictionary::database db, schema_ptr schema, const std::vector<::shared_ptr>& raw_selectors); virtual std::unique_ptr new_selectors() const = 0; diff --git a/cql3/selection/selector.hh b/cql3/selection/selector.hh index a5da3130c1..5e2b1895e6 100644 --- a/cql3/selection/selector.hh +++ b/cql3/selection/selector.hh @@ -107,7 +107,7 @@ public: */ virtual void reset() = 0; - virtual assignment_testable::test_result test_assignment(database& db, const sstring& keyspace, const column_specification& receiver) const override { + virtual assignment_testable::test_result test_assignment(data_dictionary::database db, const sstring& keyspace, const column_specification& receiver) const override { auto t1 = receiver.type->underlying_type(); auto t2 = get_type()->underlying_type(); // We want columns of `counter_type' to be served by underlying type's overloads diff --git a/cql3/selection/selector_factories.cc b/cql3/selection/selector_factories.cc index 71b4ff33f3..3caa8e6e5d 100644 --- a/cql3/selection/selector_factories.cc +++ b/cql3/selection/selector_factories.cc @@ -49,7 +49,7 @@ namespace cql3 { namespace selection { selector_factories::selector_factories(std::vector<::shared_ptr> selectables, - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, std::vector& defs) : _contains_write_time_factory(false) , _contains_ttl_factory(false) diff --git a/cql3/selection/selector_factories.hh b/cql3/selection/selector_factories.hh index 8c42dbfff3..79dd9dcae8 100644 --- a/cql3/selection/selector_factories.hh +++ b/cql3/selection/selector_factories.hh @@ -93,13 +93,13 @@ public: */ static ::shared_ptr create_factories_and_collect_column_definitions( std::vector<::shared_ptr> selectables, - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, std::vector& defs) { return ::make_shared(std::move(selectables), db, std::move(schema), defs); } selector_factories(std::vector<::shared_ptr> selectables, - database& db, schema_ptr schema, std::vector& defs); + data_dictionary::database db, schema_ptr schema, std::vector& defs); public: /** * Adds a new Selector.Factory for a column that is needed only for ORDER BY or post diff --git a/cql3/selection/writetime_or_ttl.hh b/cql3/selection/writetime_or_ttl.hh index ee72bd2736..3650f2f4ca 100644 --- a/cql3/selection/writetime_or_ttl.hh +++ b/cql3/selection/writetime_or_ttl.hh @@ -60,7 +60,7 @@ public: virtual sstring to_string() const override; - virtual shared_ptr new_selector_factory(database& db, schema_ptr s, std::vector& defs) override; + virtual shared_ptr new_selector_factory(data_dictionary::database db, schema_ptr s, std::vector& defs) override; }; } diff --git a/cql3/single_column_relation.cc b/cql3/single_column_relation.cc index 29978c4a70..e31fe89c9a 100644 --- a/cql3/single_column_relation.cc +++ b/cql3/single_column_relation.cc @@ -57,7 +57,7 @@ namespace cql3 { expression single_column_relation::to_expression(const std::vector>& receivers, const expr::expression& raw, - database& db, + data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const { // TODO: optimize vector away, accept single column_specification @@ -68,7 +68,7 @@ single_column_relation::to_expression(const std::vector -single_column_relation::new_EQ_restriction(database& db, schema_ptr schema, prepare_context& ctx) { +single_column_relation::new_EQ_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) { const column_definition& column_def = to_column_definition(*schema, *_entity); auto reset_processing_pk_column = defer([&ctx] () noexcept { ctx.set_processing_pk_restrictions(false); }); if (column_def.is_partition_key()) { @@ -90,7 +90,7 @@ single_column_relation::new_EQ_restriction(database& db, schema_ptr schema, prep } ::shared_ptr -single_column_relation::new_IN_restriction(database& db, schema_ptr schema, prepare_context& ctx) { +single_column_relation::new_IN_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) { using namespace restrictions; const column_definition& column_def = to_column_definition(*schema, *_entity); auto reset_processing_pk_column = defer([&ctx] () noexcept { ctx.set_processing_pk_restrictions(false); }); @@ -127,7 +127,7 @@ single_column_relation::new_IN_restriction(database& db, schema_ptr schema, prep ::shared_ptr single_column_relation::new_LIKE_restriction( - database& db, schema_ptr schema, prepare_context& ctx) { + data_dictionary::database db, schema_ptr schema, prepare_context& ctx) { const column_definition& column_def = to_column_definition(*schema, *_entity); if (!column_def.type->is_string()) { throw exceptions::invalid_request_exception( diff --git a/cql3/single_column_relation.hh b/cql3/single_column_relation.hh index 2db00fc280..22fbb99dbf 100644 --- a/cql3/single_column_relation.hh +++ b/cql3/single_column_relation.hh @@ -115,7 +115,7 @@ public: protected: virtual expr::expression to_expression(const std::vector>& receivers, - const expr::expression& raw, database& db, const sstring& keyspace, + const expr::expression& raw, data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const override; #if 0 @@ -144,13 +144,13 @@ protected: } protected: - virtual ::shared_ptr new_EQ_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_EQ_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override; - virtual ::shared_ptr new_IN_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_IN_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override; - virtual ::shared_ptr new_slice_restriction(database& db, schema_ptr schema, + virtual ::shared_ptr new_slice_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, statements::bound bound, bool inclusive) override { @@ -174,7 +174,7 @@ protected: return r; } - virtual shared_ptr new_contains_restriction(database& db, schema_ptr schema, + virtual shared_ptr new_contains_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, bool is_key) override { auto&& column_def = to_column_definition(*schema, *_entity); @@ -186,7 +186,7 @@ protected: } virtual ::shared_ptr new_LIKE_restriction( - database& db, schema_ptr schema, prepare_context& ctx) override; + data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override; virtual ::shared_ptr maybe_rename_identifier(const column_identifier::raw& from, column_identifier::raw to) override { return *_entity == from diff --git a/cql3/statements/alter_keyspace_statement.cc b/cql3/statements/alter_keyspace_statement.cc index 55d66ed39e..f274620939 100644 --- a/cql3/statements/alter_keyspace_statement.cc +++ b/cql3/statements/alter_keyspace_statement.cc @@ -45,7 +45,8 @@ #include "service/migration_manager.hh" #include "service/storage_proxy.hh" #include "db/system_keyspace.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "data_dictionary/keyspace_metadata.hh" #include "cql3/query_processor.hh" #include "cql3/statements/ks_prop_defs.hh" #include "create_keyspace_statement.hh" @@ -93,7 +94,7 @@ future, std::vector< cql3::statements::alter_keyspace_statement::prepare_schema_mutations(query_processor& qp) const { try { service::storage_proxy& proxy = qp.proxy(); - auto old_ksm = proxy.get_db().local().find_keyspace(_name).metadata(); + auto old_ksm = proxy.data_dictionary().find_keyspace(_name).metadata(); const auto& tm = *proxy.get_token_metadata_ptr(); auto m = qp.get_migration_manager().prepare_keyspace_update_announcement(_attrs->as_ks_metadata_update(old_ksm, tm)); @@ -105,13 +106,13 @@ cql3::statements::alter_keyspace_statement::prepare_schema_mutations(query_proce keyspace()); return make_ready_future, std::vector>>(std::make_pair(std::move(ret), std::move(m))); - } catch (no_such_keyspace& e) { + } catch (data_dictionary::no_such_keyspace& e) { return make_exception_future, std::vector>>(exceptions::invalid_request_exception("Unknown keyspace " + _name)); } } std::unique_ptr -cql3::statements::alter_keyspace_statement::prepare(database& db, cql_stats& stats) { +cql3::statements::alter_keyspace_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/alter_keyspace_statement.hh b/cql3/statements/alter_keyspace_statement.hh index 516ee8fbd8..74eabc1522 100644 --- a/cql3/statements/alter_keyspace_statement.hh +++ b/cql3/statements/alter_keyspace_statement.hh @@ -65,7 +65,7 @@ public: future<> check_access(service::storage_proxy& proxy, const service::client_state& state) const override; void validate(service::storage_proxy& proxy, const service::client_state& state) const override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<::shared_ptr> execute(query_processor& qp, service::query_state& state, const query_options& options) const override; }; diff --git a/cql3/statements/alter_role_statement.hh b/cql3/statements/alter_role_statement.hh index c8c76d7ef4..404f418e10 100644 --- a/cql3/statements/alter_role_statement.hh +++ b/cql3/statements/alter_role_statement.hh @@ -64,7 +64,7 @@ public: , _options(std::move(options)) { } - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; diff --git a/cql3/statements/alter_service_level_statement.cc b/cql3/statements/alter_service_level_statement.cc index cccdb84dd6..7392757787 100644 --- a/cql3/statements/alter_service_level_statement.cc +++ b/cql3/statements/alter_service_level_statement.cc @@ -38,7 +38,7 @@ alter_service_level_statement::alter_service_level_statement(sstring service_lev std::unique_ptr cql3::statements::alter_service_level_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/alter_service_level_statement.hh b/cql3/statements/alter_service_level_statement.hh index 9d9f7c2887..288e737008 100644 --- a/cql3/statements/alter_service_level_statement.hh +++ b/cql3/statements/alter_service_level_statement.hh @@ -36,7 +36,7 @@ class alter_service_level_statement final : public service_level_statement { public: alter_service_level_statement(sstring service_level, shared_ptr attrs); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/alter_table_statement.cc b/cql3/statements/alter_table_statement.cc index 1627244120..15d40c06f7 100644 --- a/cql3/statements/alter_table_statement.cc +++ b/cql3/statements/alter_table_statement.cc @@ -51,7 +51,7 @@ #include #include "cql3/util.hh" #include "view_info.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "db/view/view.hh" #include "cql3/query_processor.hh" #include "cdc/cdc_extension.hh" @@ -144,7 +144,7 @@ static data_type validate_alter(const schema& schema, const column_definition& d return type; } -static void validate_column_rename(database& db, const schema& schema, const column_identifier& from, const column_identifier& to) +static void validate_column_rename(data_dictionary::database db, const schema& schema, const column_identifier& from, const column_identifier& to) { auto def = schema.get_column_definition(from.name()); if (!def) { @@ -171,7 +171,7 @@ static void validate_column_rename(database& db, const schema& schema, const col } } -void alter_table_statement::add_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const { +void alter_table_statement::add_column(const schema& schema, data_dictionary::table cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const { if (is_static) { if (!schema.is_compound()) { throw exceptions::invalid_request_exception("Static columns are not allowed in COMPACT STORAGE tables"); @@ -241,7 +241,7 @@ void alter_table_statement::add_column(const schema& schema, const table& cf, sc } } -void alter_table_statement::alter_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const { +void alter_table_statement::alter_column(const schema& schema, data_dictionary::table cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const { if (!def) { throw exceptions::invalid_request_exception(format("Column {} was not found in table {}", column_name, column_family())); } @@ -263,7 +263,7 @@ void alter_table_statement::alter_column(const schema& schema, const table& cf, } } -void alter_table_statement::drop_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const { +void alter_table_statement::drop_column(const schema& schema, data_dictionary::table cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const { if (!def) { throw exceptions::invalid_request_exception(format("Column {} was not found in table {}", column_name, column_family())); } @@ -294,8 +294,8 @@ void alter_table_statement::drop_column(const schema& schema, const table& cf, s } } -std::pair> alter_table_statement::prepare_schema_update(database& db) const { - auto s = validation::validate_column_family(db, keyspace(), column_family()); +std::pair> alter_table_statement::prepare_schema_update(data_dictionary::database db) const { + auto s = validation::validate_column_family(db.real_database(), keyspace(), column_family()); if (s->is_view()) { throw exceptions::invalid_request_exception("Cannot use ALTER TABLE on Materialized View"); } @@ -306,10 +306,10 @@ std::pair> alter_table_statement::prepare_ throw exceptions::configuration_exception("Cannot alter table id."); } - auto& cf = db.find_column_family(s); + auto cf = db.find_column_family(s); std::vector view_updates; - using column_change_fn = std::function&, const column_identifier&, const data_type, const column_definition*, bool)>; + using column_change_fn = std::function&, const column_identifier&, const data_type, const column_definition*, bool)>; auto invoke_column_change_fn = [&] (column_change_fn fn) { for (auto& [raw_name, raw_validator, is_static] : _column_changes) { @@ -414,7 +414,7 @@ std::pair> alter_table_statement::prepare_ future, std::vector>> alter_table_statement::prepare_schema_mutations(query_processor& qp) const { - database& db = qp.db(); + data_dictionary::database db = qp.db(); auto& mm = qp.get_migration_manager(); auto [cfm, view_updates] = prepare_schema_update(db); auto m = co_await mm.prepare_column_family_update_announcement(cfm.build(), false, std::move(view_updates), std::nullopt); @@ -430,7 +430,7 @@ alter_table_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -cql3::statements::alter_table_statement::prepare(database& db, cql_stats& stats) { +cql3::statements::alter_table_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/alter_table_statement.hh b/cql3/statements/alter_table_statement.hh index 5c59bbe3d7..0cbd386601 100644 --- a/cql3/statements/alter_table_statement.hh +++ b/cql3/statements/alter_table_statement.hh @@ -45,7 +45,7 @@ #include "cql3/statements/cf_prop_defs.hh" #include "cql3/cql3_type.hh" #include "cql3/column_identifier.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { @@ -83,15 +83,15 @@ public: virtual future<> check_access(service::storage_proxy& proxy, const service::client_state& state) const override; virtual void validate(service::storage_proxy& proxy, const service::client_state& state) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<::shared_ptr> execute(query_processor& qp, service::query_state& state, const query_options& options) const override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; private: - void add_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; - void alter_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; - void drop_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; - std::pair> prepare_schema_update(database& db) const; + void add_column(const schema& schema, data_dictionary::table cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; + void alter_column(const schema& schema, data_dictionary::table cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; + void drop_column(const schema& schema, data_dictionary::table cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; + std::pair> prepare_schema_update(data_dictionary::database db) const; }; } diff --git a/cql3/statements/alter_type_statement.cc b/cql3/statements/alter_type_statement.cc index af8f1f2a70..fa2cd5bb6c 100644 --- a/cql3/statements/alter_type_statement.cc +++ b/cql3/statements/alter_type_statement.cc @@ -44,9 +44,11 @@ #include "cql3/column_identifier.hh" #include "prepared_statement.hh" #include "schema_builder.hh" +#include "mutation.hh" #include "service/migration_manager.hh" #include "service/storage_proxy.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "data_dictionary/keyspace_metadata.hh" #include "boost/range/adaptor/map.hpp" #include "data_dictionary/user_types_metadata.hh" @@ -82,7 +84,7 @@ const sstring& alter_type_statement::keyspace() const return _name.get_keyspace(); } -future> alter_type_statement::prepare_announcement_mutations(database& db, service::migration_manager& mm) const { +future> alter_type_statement::prepare_announcement_mutations(data_dictionary::database db, service::migration_manager& mm) const { std::vector m; auto&& ks = db.find_keyspace(keyspace()); auto&& all_types = ks.metadata()->user_types().get_all_types(); @@ -145,7 +147,7 @@ alter_type_statement::prepare_schema_mutations(query_processor& qp) const { _name.get_string_type_name()); co_return std::make_pair(std::move(ret), std::move(m)); - } catch(no_such_keyspace& e) { + } catch(data_dictionary::no_such_keyspace& e) { co_return coroutine::make_exception(exceptions::invalid_request_exception(format("Cannot alter type in unknown keyspace {}", keyspace()))); } } @@ -158,7 +160,7 @@ alter_type_statement::add_or_alter::add_or_alter(const ut_name& name, bool is_ad { } -user_type alter_type_statement::add_or_alter::do_add(database& db, user_type to_update) const +user_type alter_type_statement::add_or_alter::do_add(data_dictionary::database db, user_type to_update) const { if (to_update->idx_of_field(_field_name->name())) { throw exceptions::invalid_request_exception(format("Cannot add new field {} to type {}: a field of the same name already exists", @@ -181,7 +183,7 @@ user_type alter_type_statement::add_or_alter::do_add(database& db, user_type to_ return user_type_impl::get_instance(to_update->_keyspace, to_update->_name, std::move(new_names), std::move(new_types), to_update->is_multi_cell()); } -user_type alter_type_statement::add_or_alter::do_alter(database& db, user_type to_update) const +user_type alter_type_statement::add_or_alter::do_alter(data_dictionary::database db, user_type to_update) const { auto idx = to_update->idx_of_field(_field_name->name()); if (!idx) { @@ -200,7 +202,7 @@ user_type alter_type_statement::add_or_alter::do_alter(database& db, user_type t return user_type_impl::get_instance(to_update->_keyspace, to_update->_name, to_update->field_names(), std::move(new_types), to_update->is_multi_cell()); } -user_type alter_type_statement::add_or_alter::make_updated_type(database& db, user_type to_update) const +user_type alter_type_statement::add_or_alter::make_updated_type(data_dictionary::database db, user_type to_update) const { return _is_add ? do_add(db, to_update) : do_alter(db, to_update); } @@ -215,7 +217,7 @@ void alter_type_statement::renames::add_rename(shared_ptr pre _renames.emplace_back(previous_name, new_name); } -user_type alter_type_statement::renames::make_updated_type(database& db, user_type to_update) const +user_type alter_type_statement::renames::make_updated_type(data_dictionary::database db, user_type to_update) const { std::vector new_names(to_update->field_names()); for (auto&& rename : _renames) { @@ -232,12 +234,12 @@ user_type alter_type_statement::renames::make_updated_type(database& db, user_ty } std::unique_ptr -alter_type_statement::add_or_alter::prepare(database& db, cql_stats& stats) { +alter_type_statement::add_or_alter::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } std::unique_ptr -alter_type_statement::renames::prepare(database& db, cql_stats& stats) { +alter_type_statement::renames::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/alter_type_statement.hh b/cql3/statements/alter_type_statement.hh index 075395b2b3..a366c57d3d 100644 --- a/cql3/statements/alter_type_statement.hh +++ b/cql3/statements/alter_type_statement.hh @@ -44,7 +44,7 @@ #include "cql3/statements/schema_altering_statement.hh" #include "cql3/cql3_type.hh" #include "cql3/ut_name.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" #include "schema.hh" namespace service { @@ -77,7 +77,7 @@ public: class add_or_alter; class renames; protected: - virtual user_type make_updated_type(database& db, user_type to_update) const = 0; + virtual user_type make_updated_type(data_dictionary::database db, user_type to_update) const = 0; private: struct base_visitor { virtual future<> operator()(view_ptr view) = 0; @@ -85,7 +85,7 @@ private: virtual future<> operator()(schema_ptr cfm, bool from_thrift, std::vector&& view_updates, std::optional ts_opt) = 0; }; - future> prepare_announcement_mutations(database& db, service::migration_manager& mm) const; + future> prepare_announcement_mutations(data_dictionary::database db, service::migration_manager& mm) const; }; class alter_type_statement::add_or_alter : public alter_type_statement { @@ -96,11 +96,11 @@ public: add_or_alter(const ut_name& name, bool is_add, const shared_ptr field_name, const shared_ptr field_type); - virtual user_type make_updated_type(database& db, user_type to_update) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual user_type make_updated_type(data_dictionary::database db, user_type to_update) const override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; private: - user_type do_add(database& db, user_type to_update) const; - user_type do_alter(database& db, user_type to_update) const; + user_type do_add(data_dictionary::database db, user_type to_update) const; + user_type do_alter(data_dictionary::database db, user_type to_update) const; }; @@ -113,8 +113,8 @@ public: void add_rename(shared_ptr previous_name, shared_ptr new_name); - virtual user_type make_updated_type(database& db, user_type to_update) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual user_type make_updated_type(data_dictionary::database db, user_type to_update) const override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/alter_view_statement.cc b/cql3/statements/alter_view_statement.cc index d0d114fada..90066539ff 100644 --- a/cql3/statements/alter_view_statement.cc +++ b/cql3/statements/alter_view_statement.cc @@ -47,7 +47,7 @@ #include "validation.hh" #include "view_info.hh" #include "db/extensions.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "cql3/query_processor.hh" namespace cql3 { @@ -63,12 +63,12 @@ alter_view_statement::alter_view_statement(cf_name view_name, std::optional alter_view_statement::check_access(service::storage_proxy& proxy, const service::client_state& state) const { try { - const database& db = proxy.local_db(); + const data_dictionary::database db = proxy.data_dictionary(); auto&& s = db.find_schema(keyspace(), column_family()); if (s->is_view()) { - return state.has_column_family_access(db, keyspace(), s->view_info()->base_name(), auth::permission::ALTER); + return state.has_column_family_access(db.real_database(), keyspace(), s->view_info()->base_name(), auth::permission::ALTER); } - } catch (const no_such_column_family& e) { + } catch (const data_dictionary::no_such_column_family& e) { // Will be validated afterwards. } return make_ready_future<>(); @@ -79,8 +79,8 @@ void alter_view_statement::validate(service::storage_proxy&, const service::clie // validated in prepare_schema_mutations() } -view_ptr alter_view_statement::prepare_view(database& db) const { - schema_ptr schema = validation::validate_column_family(db, keyspace(), column_family()); +view_ptr alter_view_statement::prepare_view(data_dictionary::database db) const { + schema_ptr schema = validation::validate_column_family(db.real_database(), keyspace(), column_family()); if (!schema->is_view()) { throw exceptions::invalid_request_exception("Cannot use ALTER MATERIALIZED VIEW on Table"); } @@ -126,7 +126,7 @@ future, std::vector< } std::unique_ptr -alter_view_statement::prepare(database& db, cql_stats& stats) { +alter_view_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/alter_view_statement.hh b/cql3/statements/alter_view_statement.hh index 3cb155dd2e..a27ba4a230 100644 --- a/cql3/statements/alter_view_statement.hh +++ b/cql3/statements/alter_view_statement.hh @@ -43,7 +43,7 @@ #include -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" #include "cql3/statements/cf_prop_defs.hh" #include "cql3/statements/schema_altering_statement.hh" @@ -58,7 +58,7 @@ namespace statements { class alter_view_statement : public schema_altering_statement { private: std::optional _properties; - view_ptr prepare_view(database& db) const; + view_ptr prepare_view(data_dictionary::database db) const; public: alter_view_statement(cf_name view_name, std::optional properties); @@ -69,7 +69,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/attach_service_level_statement.cc b/cql3/statements/attach_service_level_statement.cc index 1cadb8e800..e67d19f41c 100644 --- a/cql3/statements/attach_service_level_statement.cc +++ b/cql3/statements/attach_service_level_statement.cc @@ -37,7 +37,7 @@ attach_service_level_statement::attach_service_level_statement(sstring service_l std::unique_ptr cql3::statements::attach_service_level_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/attach_service_level_statement.hh b/cql3/statements/attach_service_level_statement.hh index 7f5572fbb1..240630ce76 100644 --- a/cql3/statements/attach_service_level_statement.hh +++ b/cql3/statements/attach_service_level_statement.hh @@ -35,7 +35,7 @@ class attach_service_level_statement final : public service_level_statement { public: attach_service_level_statement(sstring service_level, sstring role_name); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/batch_statement.cc b/cql3/statements/batch_statement.cc index d2e3dccf1f..1b6e457d09 100644 --- a/cql3/statements/batch_statement.cc +++ b/cql3/statements/batch_statement.cc @@ -42,7 +42,7 @@ #include "raw/batch_statement.hh" #include "db/config.hh" #include "db/consistency_level_validations.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include #include "cas_request.hh" #include "cql3/query_processor.hh" @@ -230,8 +230,8 @@ void batch_statement::verify_batch_size(service::storage_proxy& proxy, const std return; // We only warn for batch spanning multiple mutations } - size_t warn_threshold = proxy.get_db().local().get_config().batch_size_warn_threshold_in_kb() * 1024; - size_t fail_threshold = proxy.get_db().local().get_config().batch_size_fail_threshold_in_kb() * 1024; + size_t warn_threshold = proxy.data_dictionary().get_config().batch_size_warn_threshold_in_kb() * 1024; + size_t fail_threshold = proxy.data_dictionary().get_config().batch_size_fail_threshold_in_kb() * 1024; size_t size = 0; for (auto&m : mutations) { @@ -436,7 +436,7 @@ void batch_statement::build_cas_result_set_metadata() { namespace raw { std::unique_ptr -batch_statement::prepare(database& db, cql_stats& stats) { +batch_statement::prepare(data_dictionary::database db, cql_stats& stats) { auto&& meta = get_prepare_context(); std::optional first_ks; diff --git a/cql3/statements/cf_prop_defs.cc b/cql3/statements/cf_prop_defs.cc index 45c346b3e5..9c0bf01fd7 100644 --- a/cql3/statements/cf_prop_defs.cc +++ b/cql3/statements/cf_prop_defs.cc @@ -40,7 +40,7 @@ */ #include "cql3/statements/cf_prop_defs.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "db/extensions.hh" #include "cdc/log.hh" #include "cdc/cdc_extension.hh" @@ -94,7 +94,7 @@ schema::extensions_map cf_prop_defs::make_schema_extensions(const db::extensions return er; } -void cf_prop_defs::validate(const database& db, const schema::extensions_map& schema_extensions) const { +void cf_prop_defs::validate(const data_dictionary::database db, const schema::extensions_map& schema_extensions) const { // Skip validation if the comapction strategy class is already set as it means we've alreayd // prepared (and redoing it would set strategyClass back to null, which we don't want) if (_compaction_strategy_class) { diff --git a/cql3/statements/cf_prop_defs.hh b/cql3/statements/cf_prop_defs.hh index c74821c65c..368bded005 100644 --- a/cql3/statements/cf_prop_defs.hh +++ b/cql3/statements/cf_prop_defs.hh @@ -47,6 +47,10 @@ #include "compaction/compaction_strategy.hh" #include "utils/UUID.hh" +namespace data_dictionary { +class database; +} + namespace db { class extensions; } @@ -97,7 +101,7 @@ public: std::optional get_compaction_strategy_class() const; schema::extensions_map make_schema_extensions(const db::extensions& exts) const; - void validate(const database& db, const schema::extensions_map& schema_extensions) const; + void validate(const data_dictionary::database db, const schema::extensions_map& schema_extensions) const; std::map get_compaction_type_options() const; std::optional> get_compression_options() const; const cdc::options* get_cdc_options(const schema::extensions_map&) const; diff --git a/cql3/statements/cf_properties.hh b/cql3/statements/cf_properties.hh index df0ca3c161..389be1183f 100644 --- a/cql3/statements/cf_properties.hh +++ b/cql3/statements/cf_properties.hh @@ -94,7 +94,7 @@ public: _defined_ordering.emplace_back(alias, reversed); } - void validate(const database& db, const schema::extensions_map& schema_extensions) const { + void validate(const data_dictionary::database db, const schema::extensions_map& schema_extensions) const { _properties->validate(db, schema_extensions); } }; diff --git a/cql3/statements/create_aggregate_statement.cc b/cql3/statements/create_aggregate_statement.cc index 5dde96f1b3..dfea4952e5 100644 --- a/cql3/statements/create_aggregate_statement.cc +++ b/cql3/statements/create_aggregate_statement.cc @@ -26,7 +26,8 @@ #include "prepared_statement.hh" #include "service/migration_manager.hh" #include "service/storage_proxy.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "mutation.hh" #include "cql3/query_processor.hh" #include "gms/feature_service.hh" @@ -43,7 +44,7 @@ shared_ptr create_aggregate_statement::create(service::stor } data_type state_type = prepare_type(proxy, *_stype); - auto&& db = proxy.get_db().local(); + auto&& db = proxy.data_dictionary(); std::vector acc_types{state_type}; acc_types.insert(acc_types.end(), _arg_types.begin(), _arg_types.end()); auto state_func = dynamic_pointer_cast(functions::functions::find(functions::function_name{_name.keyspace, _sfunc}, acc_types)); @@ -64,7 +65,7 @@ shared_ptr create_aggregate_statement::create(service::stor return ::make_shared(_name, initcond, std::move(state_func), std::move(final_func)); } -std::unique_ptr create_aggregate_statement::prepare(database& db, cql_stats& stats) { +std::unique_ptr create_aggregate_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/create_aggregate_statement.hh b/cql3/statements/create_aggregate_statement.hh index 95b03e76b8..e7b49b84f6 100644 --- a/cql3/statements/create_aggregate_statement.hh +++ b/cql3/statements/create_aggregate_statement.hh @@ -36,7 +36,7 @@ namespace functions { namespace statements { class create_aggregate_statement final : public create_function_statement_base { - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; virtual shared_ptr create(service::storage_proxy& proxy, functions::function* old) const override; diff --git a/cql3/statements/create_function_statement.cc b/cql3/statements/create_function_statement.cc index a2142f4305..97a7cbe927 100644 --- a/cql3/statements/create_function_statement.cc +++ b/cql3/statements/create_function_statement.cc @@ -27,7 +27,8 @@ #include "service/migration_manager.hh" #include "service/storage_proxy.hh" #include "lang/lua.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "database.hh" // for wasm #include "cql3/query_processor.hh" namespace cql3 { @@ -47,7 +48,7 @@ shared_ptr create_function_statement::create(service::stora arg_names.push_back(arg_name->to_string()); } - auto&& db = proxy.get_db().local(); + auto&& db = proxy.data_dictionary(); if (_language == "lua") { auto cfg = lua::make_runtime_config(db.get_config()); functions::user_function::context ctx = functions::user_function::lua_context { @@ -58,7 +59,8 @@ shared_ptr create_function_statement::create(service::stora return ::make_shared(_name, _arg_types, std::move(arg_names), _body, _language, std::move(return_type), _called_on_null_input, std::move(ctx)); } else if (_language == "xwasm") { - wasm::context ctx{db.wasm_engine(), _name.name}; + // FIXME: need better way to test wasm compilation without real_database() + wasm::context ctx{db.real_database().wasm_engine(), _name.name}; try { wasm::compile(ctx, arg_names, _body); return ::make_shared(_name, _arg_types, std::move(arg_names), _body, _language, @@ -70,7 +72,7 @@ shared_ptr create_function_statement::create(service::stora return nullptr; } -std::unique_ptr create_function_statement::prepare(database& db, cql_stats& stats) { +std::unique_ptr create_function_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/create_function_statement.hh b/cql3/statements/create_function_statement.hh index ddd2be29fa..48de7d15a4 100644 --- a/cql3/statements/create_function_statement.hh +++ b/cql3/statements/create_function_statement.hh @@ -35,7 +35,7 @@ namespace functions { namespace statements { class create_function_statement final : public create_function_statement_base { - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; virtual shared_ptr create(service::storage_proxy& proxy, functions::function* old) const override; diff --git a/cql3/statements/create_index_statement.cc b/cql3/statements/create_index_statement.cc index a56cec8c23..3bc22f60f3 100644 --- a/cql3/statements/create_index_statement.cc +++ b/cql3/statements/create_index_statement.cc @@ -48,12 +48,14 @@ #include "schema.hh" #include "schema_builder.hh" #include "request_validations.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "index/target_parser.hh" #include "gms/feature_service.hh" #include "cql3/query_processor.hh" #include "cql3/index_name.hh" #include "cql3/statements/index_prop_defs.hh" +#include "index/secondary_index_manager.hh" +#include "mutation.hh" #include #include @@ -91,8 +93,8 @@ create_index_statement::validate(service::storage_proxy& proxy, const service::c } std::vector<::shared_ptr> create_index_statement::validate_while_executing(service::storage_proxy& proxy) const { - auto& db = proxy.get_db().local(); - auto schema = validation::validate_column_family(db, keyspace(), column_family()); + auto db = proxy.data_dictionary(); + auto schema = validation::validate_column_family(db.real_database(), keyspace(), column_family()); if (schema->is_counter()) { throw exceptions::invalid_request_exception("Secondary indexes are not supported on counter tables"); @@ -279,7 +281,7 @@ void create_index_statement::validate_targets_for_multi_column_index(std::vector schema_ptr create_index_statement::build_index_schema(query_processor& qp) const { auto targets = validate_while_executing(qp.proxy()); - database& db = qp.db(); + data_dictionary::database db = qp.db(); auto schema = db.find_schema(keyspace(), column_family()); sstring accepted_name = _index_name; @@ -346,7 +348,7 @@ create_index_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -create_index_statement::prepare(database& db, cql_stats& stats) { +create_index_statement::prepare(data_dictionary::database db, cql_stats& stats) { _cql_stats = &stats; return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/create_index_statement.hh b/cql3/statements/create_index_statement.hh index e14d266fdd..d7f81ed634 100644 --- a/cql3/statements/create_index_statement.hh +++ b/cql3/statements/create_index_statement.hh @@ -81,7 +81,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; private: void validate_for_local_index(const schema& schema) const; void validate_for_frozen_collection(const index_target& target) const; diff --git a/cql3/statements/create_keyspace_statement.cc b/cql3/statements/create_keyspace_statement.cc index a1df28f6bb..9042de9b75 100644 --- a/cql3/statements/create_keyspace_statement.cc +++ b/cql3/statements/create_keyspace_statement.cc @@ -43,7 +43,9 @@ #include "cql3/statements/create_keyspace_statement.hh" #include "cql3/statements/ks_prop_defs.hh" #include "prepared_statement.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "data_dictionary/keyspace_metadata.hh" +#include "mutation.hh" #include "service/migration_manager.hh" #include "service/storage_proxy.hh" #include "transport/messages/result_message.hh" @@ -135,7 +137,7 @@ future, std::vector< } std::unique_ptr -cql3::statements::create_keyspace_statement::prepare(database& db, cql_stats& stats) { +cql3::statements::create_keyspace_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } @@ -172,7 +174,7 @@ std::optional check_restricted_replication_strategy( // may have in the future - multiple racks or DCs. So depending on how // protective we are configured, let's prevent it or allow with a warning: if (replication_strategy == "org.apache.cassandra.locator.SimpleStrategy") { - switch(proxy.local_db().get_config().restrict_replication_simplestrategy()) { + switch(proxy.data_dictionary().get_config().restrict_replication_simplestrategy()) { case db::tri_mode_restriction_t::mode::TRUE: throw exceptions::configuration_exception( "SimpleStrategy replication class is not recommended, and " diff --git a/cql3/statements/create_keyspace_statement.hh b/cql3/statements/create_keyspace_statement.hh index d96fcb5a6f..1a4d5eac0a 100644 --- a/cql3/statements/create_keyspace_statement.hh +++ b/cql3/statements/create_keyspace_statement.hh @@ -97,7 +97,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<> grant_permissions_to_creator(const service::client_state&) const override; diff --git a/cql3/statements/create_role_statement.hh b/cql3/statements/create_role_statement.hh index 1ab72ad4c4..5226f03cdb 100644 --- a/cql3/statements/create_role_statement.hh +++ b/cql3/statements/create_role_statement.hh @@ -68,7 +68,7 @@ public: , _if_not_exists(if_not_exists) { } - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future<> grant_permissions_to_creator(const service::client_state&) const; diff --git a/cql3/statements/create_service_level_statement.cc b/cql3/statements/create_service_level_statement.cc index a1bea3af94..95ea4c7f09 100644 --- a/cql3/statements/create_service_level_statement.cc +++ b/cql3/statements/create_service_level_statement.cc @@ -38,7 +38,7 @@ create_service_level_statement::create_service_level_statement(sstring service_l std::unique_ptr cql3::statements::create_service_level_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/create_service_level_statement.hh b/cql3/statements/create_service_level_statement.hh index 0ae38cdd6d..7ce9dc4180 100644 --- a/cql3/statements/create_service_level_statement.hh +++ b/cql3/statements/create_service_level_statement.hh @@ -37,7 +37,7 @@ class create_service_level_statement final : public service_level_statement { public: create_service_level_statement(sstring service_level, shared_ptr attrs, bool if_not_exists); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/create_table_statement.cc b/cql3/statements/create_table_statement.cc index 92bf308a1d..9629174960 100644 --- a/cql3/statements/create_table_statement.cc +++ b/cql3/statements/create_table_statement.cc @@ -55,7 +55,7 @@ #include "auth/service.hh" #include "schema_builder.hh" #include "db/extensions.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "types/user.hh" #include "gms/feature_service.hh" #include "service/migration_manager.hh" @@ -134,13 +134,13 @@ create_table_statement::prepare_schema_mutations(query_processor& qp) const { * @return a CFMetaData instance corresponding to the values parsed from this statement * @throws InvalidRequestException on failure to validate parsed parameters */ -schema_ptr create_table_statement::get_cf_meta_data(const database& db) const { +schema_ptr create_table_statement::get_cf_meta_data(const data_dictionary::database db) const { schema_builder builder{keyspace(), column_family(), _id}; apply_properties_to(builder, db); return builder.build(_use_compact_storage ? schema_builder::compact_storage::yes : schema_builder::compact_storage::no); } -void create_table_statement::apply_properties_to(schema_builder& builder, const database& db) const { +void create_table_statement::apply_properties_to(schema_builder& builder, const data_dictionary::database db) const { auto&& columns = get_columns(); for (auto&& column : columns) { builder.with_column_ordered(column); @@ -170,7 +170,7 @@ void create_table_statement::add_column_metadata_from_aliases(schema_builder& bu } std::unique_ptr -create_table_statement::prepare(database& db, cql_stats& stats) { +create_table_statement::prepare(data_dictionary::database db, cql_stats& stats) { // Cannot happen; create_table_statement is never instantiated as a raw statement // (instead we instantiate create_table_statement::raw_statement) abort(); @@ -192,7 +192,7 @@ create_table_statement::raw_statement::raw_statement(cf_name name, bool if_not_e , _if_not_exists{if_not_exists} { } -std::unique_ptr create_table_statement::raw_statement::prepare(database& db, cql_stats& stats) { +std::unique_ptr create_table_statement::raw_statement::prepare(data_dictionary::database db, cql_stats& stats) { // Column family name const sstring& cf_name = _cf_name->get_column_family(); std::regex name_regex("\\w+"); @@ -463,7 +463,7 @@ std::optional check_restricted_table_properties( // in prepare_schema_mutations(), in the middle of execute). auto strategy = cfprops.get_compaction_strategy_class(); if (strategy && *strategy == sstables::compaction_strategy_type::date_tiered) { - switch(proxy.local_db().get_config().restrict_dtcs()) { + switch(proxy.data_dictionary().get_config().restrict_dtcs()) { case db::tri_mode_restriction_t::mode::TRUE: throw exceptions::configuration_exception( "DateTieredCompactionStrategy is deprecated, and " diff --git a/cql3/statements/create_table_statement.hh b/cql3/statements/create_table_statement.hh index 4fe205dba1..8c72cbff2b 100644 --- a/cql3/statements/create_table_statement.hh +++ b/cql3/statements/create_table_statement.hh @@ -106,14 +106,14 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<> grant_permissions_to_creator(const service::client_state&) const override; virtual future<::shared_ptr> execute(query_processor& qp, service::query_state& state, const query_options& options) const override; - schema_ptr get_cf_meta_data(const database&) const; + schema_ptr get_cf_meta_data(const data_dictionary::database) const; class raw_statement; @@ -121,7 +121,7 @@ public: private: std::vector get_columns() const; - void apply_properties_to(schema_builder& builder, const database&) const; + void apply_properties_to(schema_builder& builder, const data_dictionary::database) const; void add_column_metadata_from_aliases(schema_builder& builder, std::vector aliases, const std::vector& types, column_kind kind) const; }; @@ -144,7 +144,7 @@ private: public: raw_statement(cf_name name, bool if_not_exists); - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; cf_properties& properties() { return _properties; diff --git a/cql3/statements/create_type_statement.cc b/cql3/statements/create_type_statement.cc index 8edd1b443e..68a5baa64b 100644 --- a/cql3/statements/create_type_statement.cc +++ b/cql3/statements/create_type_statement.cc @@ -40,12 +40,14 @@ #include #include "cql3/statements/create_type_statement.hh" #include "prepared_statement.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "service/migration_manager.hh" #include "service/storage_proxy.hh" +#include "data_dictionary/keyspace_metadata.hh" #include "data_dictionary/user_types_metadata.hh" #include "cql3/query_processor.hh" #include "cql3/column_identifier.hh" +#include "mutation.hh" namespace cql3 { @@ -75,7 +77,7 @@ future<> create_type_statement::check_access(service::storage_proxy& proxy, cons return state.has_keyspace_access(proxy.local_db(), keyspace(), auth::permission::CREATE); } -inline bool create_type_statement::type_exists_in(::keyspace& ks) const +inline bool create_type_statement::type_exists_in(data_dictionary::keyspace ks) const { auto&& keyspace_types = ks.metadata()->user_types().get_all_types(); return keyspace_types.contains(_name.get_user_type_name()); @@ -115,7 +117,7 @@ const sstring& create_type_statement::keyspace() const return _name.get_keyspace(); } -user_type create_type_statement::create_type(database& db) const +user_type create_type_statement::create_type(data_dictionary::database db) const { std::vector field_names; std::vector field_types; @@ -134,7 +136,7 @@ user_type create_type_statement::create_type(database& db) const } std::optional create_type_statement::make_type(query_processor& qp) const { - database& db = qp.db(); + data_dictionary::database db = qp.db(); auto&& ks = db.find_keyspace(keyspace()); // Can happen with if_not_exists @@ -166,7 +168,7 @@ future, std::vector< co_return coroutine::make_exception(exceptions::invalid_request_exception(format("A user type of name {} already exists", _name.to_string()))); } } - } catch (no_such_keyspace& e) { + } catch (data_dictionary::no_such_keyspace& e) { co_return coroutine::exception(std::current_exception()); } @@ -174,7 +176,7 @@ future, std::vector< } std::unique_ptr -create_type_statement::prepare(database& db, cql_stats& stats) { +create_type_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/create_type_statement.hh b/cql3/statements/create_type_statement.hh index 082ddb7da9..b8d55f2c93 100644 --- a/cql3/statements/create_type_statement.hh +++ b/cql3/statements/create_type_statement.hh @@ -42,7 +42,7 @@ #include "cql3/statements/schema_altering_statement.hh" #include "cql3/cql3_type.hh" #include "cql3/ut_name.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { @@ -70,16 +70,16 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; static void check_for_duplicate_names(user_type type); private: - bool type_exists_in(::keyspace& ks) const; + bool type_exists_in(data_dictionary::keyspace ks) const; std::optional make_type(query_processor& qp) const; public: - user_type create_type(database& db) const; + user_type create_type(data_dictionary::database db) const; }; } diff --git a/cql3/statements/create_view_statement.cc b/cql3/statements/create_view_statement.cc index 2b135c5df9..5b63af7a56 100644 --- a/cql3/statements/create_view_statement.cc +++ b/cql3/statements/create_view_statement.cc @@ -64,7 +64,7 @@ #include "service/storage_proxy.hh" #include "validation.hh" #include "db/extensions.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "gms/feature_service.hh" #include "db/view/view.hh" #include "service/migration_manager.hh" @@ -143,7 +143,7 @@ static bool validate_primary_key( return new_non_pk_column; } -view_ptr create_view_statement::prepare_view(database& db) const { +view_ptr create_view_statement::prepare_view(data_dictionary::database db) const { // We need to make sure that: // - primary key includes all columns in base table's primary key // - make sure that the select statement does not have anything other than columns @@ -177,7 +177,7 @@ view_ptr create_view_statement::prepare_view(database& db) const { _base_name.get_keyspace(), keyspace())); } - schema_ptr schema = validation::validate_column_family(db, _base_name.get_keyspace(), _base_name.get_column_family()); + schema_ptr schema = validation::validate_column_family(db.real_database(), _base_name.get_keyspace(), _base_name.get_column_family()); if (schema->is_counter()) { throw exceptions::invalid_request_exception(format("Materialized views are not supported on counter tables")); @@ -187,7 +187,7 @@ view_ptr create_view_statement::prepare_view(database& db) const { throw exceptions::invalid_request_exception(format("Materialized views cannot be created against other materialized views")); } - if (cdc::get_base_table(db, *schema)) { + if (db.get_cdc_base_table(*schema)) { throw exceptions::invalid_request_exception(format("Materialized views cannot be created on CDC Log tables")); } @@ -372,7 +372,7 @@ create_view_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -create_view_statement::prepare(database& db, cql_stats& stats) { +create_view_statement::prepare(data_dictionary::database db, cql_stats& stats) { if (!_prepare_ctx.get_variable_specifications().empty()) { throw exceptions::invalid_request_exception(format("Cannot use query parameters in CREATE MATERIALIZED VIEW statements")); } diff --git a/cql3/statements/create_view_statement.hh b/cql3/statements/create_view_statement.hh index 59565b76e3..25a8878c71 100644 --- a/cql3/statements/create_view_statement.hh +++ b/cql3/statements/create_view_statement.hh @@ -51,7 +51,7 @@ private: cf_properties _properties; bool _if_not_exists; - view_ptr prepare_view(database& db) const; + view_ptr prepare_view(data_dictionary::database db) const; public: create_view_statement( @@ -72,7 +72,7 @@ public: virtual void validate(service::storage_proxy&, const service::client_state& state) const override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; // FIXME: continue here. See create_table_statement.hh and CreateViewStatement.java }; diff --git a/cql3/statements/delete_statement.cc b/cql3/statements/delete_statement.cc index 5b0827bd1a..83a612f91c 100644 --- a/cql3/statements/delete_statement.cc +++ b/cql3/statements/delete_statement.cc @@ -42,10 +42,11 @@ #include #include -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "delete_statement.hh" #include "raw/delete_statement.hh" #include "utils/overloaded_functor.hh" +#include "mutation.hh" namespace cql3 { @@ -84,7 +85,7 @@ void delete_statement::add_update_for_key(mutation& m, const query::clustering_r namespace raw { ::shared_ptr -delete_statement::prepare_internal(database& db, schema_ptr schema, prepare_context& ctx, +delete_statement::prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const { auto stmt = ::make_shared(statement_type::DELETE, ctx.bound_variables_size(), schema, std::move(attrs), stats); diff --git a/cql3/statements/delete_statement.hh b/cql3/statements/delete_statement.hh index cc70ad5d9a..13047d61bd 100644 --- a/cql3/statements/delete_statement.hh +++ b/cql3/statements/delete_statement.hh @@ -42,7 +42,7 @@ #pragma once #include "cql3/statements/modification_statement.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { diff --git a/cql3/statements/detach_service_level_statement.cc b/cql3/statements/detach_service_level_statement.cc index e0aa0c9f6f..95ae1f452a 100644 --- a/cql3/statements/detach_service_level_statement.cc +++ b/cql3/statements/detach_service_level_statement.cc @@ -36,7 +36,7 @@ detach_service_level_statement::detach_service_level_statement(sstring role_name std::unique_ptr cql3::statements::detach_service_level_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/detach_service_level_statement.hh b/cql3/statements/detach_service_level_statement.hh index 27cff8093c..10cdbaac03 100644 --- a/cql3/statements/detach_service_level_statement.hh +++ b/cql3/statements/detach_service_level_statement.hh @@ -33,7 +33,7 @@ class detach_service_level_statement final : public service_level_statement { sstring _role_name; public: detach_service_level_statement(sstring role_name); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/drop_aggregate_statement.cc b/cql3/statements/drop_aggregate_statement.cc index dd266147cd..c6b58426c4 100644 --- a/cql3/statements/drop_aggregate_statement.cc +++ b/cql3/statements/drop_aggregate_statement.cc @@ -32,7 +32,7 @@ namespace cql3 { namespace statements { -std::unique_ptr drop_aggregate_statement::prepare(database& db, cql_stats& stats) { +std::unique_ptr drop_aggregate_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/drop_aggregate_statement.hh b/cql3/statements/drop_aggregate_statement.hh index 7a3f1c3871..21352ec5cd 100644 --- a/cql3/statements/drop_aggregate_statement.hh +++ b/cql3/statements/drop_aggregate_statement.hh @@ -27,7 +27,7 @@ namespace cql3 { class query_processor; namespace statements { class drop_aggregate_statement final : public drop_function_statement_base { - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; public: diff --git a/cql3/statements/drop_function_statement.cc b/cql3/statements/drop_function_statement.cc index a488e2d4ac..60d7f37803 100644 --- a/cql3/statements/drop_function_statement.cc +++ b/cql3/statements/drop_function_statement.cc @@ -32,7 +32,7 @@ namespace cql3 { namespace statements { -std::unique_ptr drop_function_statement::prepare(database& db, cql_stats& stats) { +std::unique_ptr drop_function_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/drop_function_statement.hh b/cql3/statements/drop_function_statement.hh index 3b89f02f8b..ecbab3fadb 100644 --- a/cql3/statements/drop_function_statement.hh +++ b/cql3/statements/drop_function_statement.hh @@ -27,7 +27,7 @@ namespace cql3 { class query_processor; namespace statements { class drop_function_statement final : public drop_function_statement_base { - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; public: diff --git a/cql3/statements/drop_index_statement.cc b/cql3/statements/drop_index_statement.cc index 8387c5e037..0584a4e891 100644 --- a/cql3/statements/drop_index_statement.cc +++ b/cql3/statements/drop_index_statement.cc @@ -45,7 +45,8 @@ #include "service/migration_manager.hh" #include "service/storage_proxy.hh" #include "schema_builder.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "mutation.hh" #include "gms/feature_service.hh" #include "cql3/query_processor.hh" #include "cql3/index_name.hh" @@ -81,7 +82,7 @@ void drop_index_statement::validate(service::storage_proxy& proxy, const service { // validated in lookup_indexed_table() - auto& db = proxy.get_db().local(); + auto db = proxy.data_dictionary(); if (db.has_keyspace(keyspace())) { auto schema = db.find_indexed_table(keyspace(), _index_name); if (schema) { @@ -122,14 +123,14 @@ drop_index_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -drop_index_statement::prepare(database& db, cql_stats& stats) { +drop_index_statement::prepare(data_dictionary::database db, cql_stats& stats) { _cql_stats = &stats; return std::make_unique(make_shared(*this)); } schema_ptr drop_index_statement::lookup_indexed_table(service::storage_proxy& proxy) const { - auto& db = proxy.get_db().local(); + auto& db = proxy.data_dictionary(); if (!db.has_keyspace(keyspace())) { throw exceptions::keyspace_not_defined_exception(format("Keyspace {} does not exist", keyspace())); } diff --git a/cql3/statements/drop_index_statement.hh b/cql3/statements/drop_index_statement.hh index a3a4905667..1a8ce4da97 100644 --- a/cql3/statements/drop_index_statement.hh +++ b/cql3/statements/drop_index_statement.hh @@ -77,7 +77,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; private: schema_ptr lookup_indexed_table(service::storage_proxy& proxy) const; schema_ptr make_drop_idex_schema(query_processor& qp) const; diff --git a/cql3/statements/drop_keyspace_statement.cc b/cql3/statements/drop_keyspace_statement.cc index d46d17b506..b750a3de60 100644 --- a/cql3/statements/drop_keyspace_statement.cc +++ b/cql3/statements/drop_keyspace_statement.cc @@ -100,7 +100,7 @@ drop_keyspace_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -drop_keyspace_statement::prepare(database& db, cql_stats& stats) { +drop_keyspace_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/drop_keyspace_statement.hh b/cql3/statements/drop_keyspace_statement.hh index 9af156f262..ff6580eb64 100644 --- a/cql3/statements/drop_keyspace_statement.hh +++ b/cql3/statements/drop_keyspace_statement.hh @@ -63,7 +63,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/drop_role_statement.hh b/cql3/statements/drop_role_statement.hh index decd065c93..9d1d22e219 100644 --- a/cql3/statements/drop_role_statement.hh +++ b/cql3/statements/drop_role_statement.hh @@ -62,7 +62,7 @@ public: drop_role_statement(const cql3::role_name& name, bool if_exists) : _role(name.to_string()), _if_exists(if_exists) { } - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual void validate(service::storage_proxy&, const service::client_state&) const override; diff --git a/cql3/statements/drop_service_level_statement.cc b/cql3/statements/drop_service_level_statement.cc index 5c32842ca3..07738f13c1 100644 --- a/cql3/statements/drop_service_level_statement.cc +++ b/cql3/statements/drop_service_level_statement.cc @@ -36,7 +36,7 @@ drop_service_level_statement::drop_service_level_statement(sstring service_level std::unique_ptr cql3::statements::drop_service_level_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/drop_service_level_statement.hh b/cql3/statements/drop_service_level_statement.hh index 4d32ba506f..8d3c2499b3 100644 --- a/cql3/statements/drop_service_level_statement.hh +++ b/cql3/statements/drop_service_level_statement.hh @@ -34,7 +34,7 @@ class drop_service_level_statement final : public service_level_statement { bool _if_exists; public: drop_service_level_statement(sstring service_level, bool if_exists); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/drop_table_statement.cc b/cql3/statements/drop_table_statement.cc index 740b266783..2fd6831925 100644 --- a/cql3/statements/drop_table_statement.cc +++ b/cql3/statements/drop_table_statement.cc @@ -99,7 +99,7 @@ drop_table_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -drop_table_statement::prepare(database& db, cql_stats& stats) { +drop_table_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/drop_table_statement.hh b/cql3/statements/drop_table_statement.hh index f774e238ef..96af464185 100644 --- a/cql3/statements/drop_table_statement.hh +++ b/cql3/statements/drop_table_statement.hh @@ -62,7 +62,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/drop_type_statement.cc b/cql3/statements/drop_type_statement.cc index 55966e66d7..29f7a1d77c 100644 --- a/cql3/statements/drop_type_statement.cc +++ b/cql3/statements/drop_type_statement.cc @@ -46,8 +46,10 @@ #include "service/migration_manager.hh" #include "service/storage_proxy.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "data_dictionary/keyspace_metadata.hh" #include "data_dictionary/user_types_metadata.hh" +#include "mutation.hh" namespace cql3 { @@ -77,7 +79,7 @@ void drop_type_statement::validate(service::storage_proxy& proxy, const service: void drop_type_statement::validate_while_executing(service::storage_proxy& proxy) const { try { - auto&& ks = proxy.get_db().local().find_keyspace(keyspace()); + auto&& ks = proxy.data_dictionary().find_keyspace(keyspace()); auto&& all_types = ks.metadata()->user_types().get_all_types(); auto old = all_types.find(_name.get_user_type_name()); if (old == all_types.end()) { @@ -138,7 +140,7 @@ void drop_type_statement::validate_while_executing(service::storage_proxy& proxy } } - } catch (no_such_keyspace& e) { + } catch (data_dictionary::no_such_keyspace& e) { throw exceptions::invalid_request_exception(format("Cannot drop type in unknown keyspace {}", keyspace())); } } @@ -153,7 +155,7 @@ future, std::vector< drop_type_statement::prepare_schema_mutations(query_processor& qp) const { validate_while_executing(qp.proxy()); - database& db = qp.db(); + data_dictionary::database db = qp.db(); // Keyspace exists or we wouldn't have validated otherwise auto&& ks = db.find_keyspace(keyspace()); @@ -180,7 +182,7 @@ drop_type_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -drop_type_statement::prepare(database& db, cql_stats& stats) { +drop_type_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/drop_type_statement.hh b/cql3/statements/drop_type_statement.hh index a2ae8d4343..cc3faf1918 100644 --- a/cql3/statements/drop_type_statement.hh +++ b/cql3/statements/drop_type_statement.hh @@ -65,7 +65,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; private: void validate_while_executing(service::storage_proxy&) const; }; diff --git a/cql3/statements/drop_view_statement.cc b/cql3/statements/drop_view_statement.cc index 46fe7872ec..fde46ad50d 100644 --- a/cql3/statements/drop_view_statement.cc +++ b/cql3/statements/drop_view_statement.cc @@ -46,7 +46,7 @@ #include "service/migration_manager.hh" #include "service/storage_proxy.hh" #include "view_info.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { @@ -61,12 +61,12 @@ drop_view_statement::drop_view_statement(cf_name view_name, bool if_exists) future<> drop_view_statement::check_access(service::storage_proxy& proxy, const service::client_state& state) const { try { - const database& db = proxy.local_db(); + const data_dictionary::database db = proxy.data_dictionary(); auto&& s = db.find_schema(keyspace(), column_family()); if (s->is_view()) { - return state.has_column_family_access(db, keyspace(), s->view_info()->base_name(), auth::permission::ALTER); + return state.has_column_family_access(db.real_database(), keyspace(), s->view_info()->base_name(), auth::permission::ALTER); } - } catch (const no_such_column_family& e) { + } catch (const data_dictionary::no_such_column_family& e) { // Will be validated afterwards. } return make_ready_future<>(); @@ -101,7 +101,7 @@ drop_view_statement::prepare_schema_mutations(query_processor& qp) const { } std::unique_ptr -drop_view_statement::prepare(database& db, cql_stats& stats) { +drop_view_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(make_shared(*this)); } diff --git a/cql3/statements/drop_view_statement.hh b/cql3/statements/drop_view_statement.hh index aa9f854a57..335e7d758c 100644 --- a/cql3/statements/drop_view_statement.hh +++ b/cql3/statements/drop_view_statement.hh @@ -45,7 +45,7 @@ #include "cql3/statements/schema_altering_statement.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { @@ -68,7 +68,7 @@ public: future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/function_statement.cc b/cql3/statements/function_statement.cc index 1bd4148a94..a2d7e10b2c 100644 --- a/cql3/statements/function_statement.cc +++ b/cql3/statements/function_statement.cc @@ -23,7 +23,7 @@ #include "cql3/functions/functions.hh" #include "cql3/functions/user_function.hh" #include "db/config.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "gms/feature_service.hh" #include "service/storage_proxy.hh" @@ -53,7 +53,7 @@ data_type function_statement::prepare_type(service::storage_proxy& proxy, cql3_t if (t.is_user_type() && t.is_frozen()) { throw exceptions::invalid_request_exception("User defined argument and return types should not be frozen"); } - auto&& db = proxy.get_db().local(); + auto&& db = proxy.data_dictionary(); // At the CQL level the argument and return types should not have // the frozen keyword. // We and cassandra 3 support only frozen UDT arguments and diff --git a/cql3/statements/grant_role_statement.hh b/cql3/statements/grant_role_statement.hh index d4d9b3335e..0be5ae0e54 100644 --- a/cql3/statements/grant_role_statement.hh +++ b/cql3/statements/grant_role_statement.hh @@ -63,7 +63,7 @@ public: : _role(name.to_string()), _grantee(grantee.to_string()) { } - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<> check_access(service::storage_proxy& proxy, const service::client_state&) const override; diff --git a/cql3/statements/grant_statement.cc b/cql3/statements/grant_statement.cc index 0ecdc89b5d..cad2ba5214 100644 --- a/cql3/statements/grant_statement.cc +++ b/cql3/statements/grant_statement.cc @@ -45,7 +45,7 @@ #include "service/query_state.hh" std::unique_ptr cql3::statements::grant_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/grant_statement.hh b/cql3/statements/grant_statement.hh index efcbfacb86..71c0be9032 100644 --- a/cql3/statements/grant_statement.hh +++ b/cql3/statements/grant_statement.hh @@ -53,7 +53,7 @@ class grant_statement : public permission_altering_statement { public: using permission_altering_statement::permission_altering_statement; - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future<::shared_ptr> execute(query_processor& , service::query_state& diff --git a/cql3/statements/ks_prop_defs.cc b/cql3/statements/ks_prop_defs.cc index 4d8ced182b..30ea085b5d 100644 --- a/cql3/statements/ks_prop_defs.cc +++ b/cql3/statements/ks_prop_defs.cc @@ -40,7 +40,8 @@ */ #include "cql3/statements/ks_prop_defs.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "data_dictionary/keyspace_metadata.hh" #include "locator/token_metadata.hh" #include "locator/abstract_replication_strategy.hh" @@ -127,13 +128,13 @@ std::optional ks_prop_defs::get_replication_strategy_class() const { return _strategy_class; } -lw_shared_ptr ks_prop_defs::as_ks_metadata(sstring ks_name, const locator::token_metadata& tm) { +lw_shared_ptr ks_prop_defs::as_ks_metadata(sstring ks_name, const locator::token_metadata& tm) { auto sc = get_replication_strategy_class().value(); - return keyspace_metadata::new_keyspace(ks_name, sc, + return data_dictionary::keyspace_metadata::new_keyspace(ks_name, sc, prepare_options(sc, tm, get_replication_options()), get_boolean(KW_DURABLE_WRITES, true)); } -lw_shared_ptr ks_prop_defs::as_ks_metadata_update(lw_shared_ptr old, const locator::token_metadata& tm) { +lw_shared_ptr ks_prop_defs::as_ks_metadata_update(lw_shared_ptr old, const locator::token_metadata& tm) { std::map options; const auto& old_options = old->strategy_options(); auto sc = get_replication_strategy_class(); @@ -144,7 +145,7 @@ lw_shared_ptr ks_prop_defs::as_ks_metadata_update(lw_shared_p options = old_options; } - return keyspace_metadata::new_keyspace(old->name(), *sc, options, get_boolean(KW_DURABLE_WRITES, true)); + return data_dictionary::keyspace_metadata::new_keyspace(old->name(), *sc, options, get_boolean(KW_DURABLE_WRITES, true)); } diff --git a/cql3/statements/list_permissions_statement.cc b/cql3/statements/list_permissions_statement.cc index 28dd88937e..8c568c8523 100644 --- a/cql3/statements/list_permissions_statement.cc +++ b/cql3/statements/list_permissions_statement.cc @@ -60,7 +60,7 @@ cql3::statements::list_permissions_statement::list_permissions_statement( } std::unique_ptr cql3::statements::list_permissions_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/list_permissions_statement.hh b/cql3/statements/list_permissions_statement.hh index 79764c1a55..a4220ff3b3 100644 --- a/cql3/statements/list_permissions_statement.hh +++ b/cql3/statements/list_permissions_statement.hh @@ -63,7 +63,7 @@ private: public: list_permissions_statement(auth::permission_set, std::optional, std::optional, bool); - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; diff --git a/cql3/statements/list_roles_statement.hh b/cql3/statements/list_roles_statement.hh index 7f36be9cf3..1e0dd79818 100644 --- a/cql3/statements/list_roles_statement.hh +++ b/cql3/statements/list_roles_statement.hh @@ -64,7 +64,7 @@ public: list_roles_statement(const std::optional& grantee, bool recursive) : _grantee(grantee ? sstring(grantee->to_string()) : std::optional()), _recursive(recursive) {} - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<> check_access(service::storage_proxy& proxy, const service::client_state&) const override; diff --git a/cql3/statements/list_service_level_attachments_statement.cc b/cql3/statements/list_service_level_attachments_statement.cc index 3df4a92bc4..e5f2f15234 100644 --- a/cql3/statements/list_service_level_attachments_statement.cc +++ b/cql3/statements/list_service_level_attachments_statement.cc @@ -41,7 +41,7 @@ list_service_level_attachments_statement::list_service_level_attachments_stateme std::unique_ptr cql3::statements::list_service_level_attachments_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/list_service_level_attachments_statement.hh b/cql3/statements/list_service_level_attachments_statement.hh index a261c633bd..45c54a2278 100644 --- a/cql3/statements/list_service_level_attachments_statement.hh +++ b/cql3/statements/list_service_level_attachments_statement.hh @@ -35,7 +35,7 @@ class list_service_level_attachments_statement final : public service_level_stat public: list_service_level_attachments_statement(sstring role_name); list_service_level_attachments_statement(); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/list_service_level_statement.cc b/cql3/statements/list_service_level_statement.cc index 92400bb145..cec4166b36 100644 --- a/cql3/statements/list_service_level_statement.cc +++ b/cql3/statements/list_service_level_statement.cc @@ -38,7 +38,7 @@ list_service_level_statement::list_service_level_statement(sstring service_level std::unique_ptr cql3::statements::list_service_level_statement::prepare( - database &db, cql_stats &stats) { + data_dictionary::database db, cql_stats &stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/list_service_level_statement.hh b/cql3/statements/list_service_level_statement.hh index 90a7d2eceb..ca3045fd8d 100644 --- a/cql3/statements/list_service_level_statement.hh +++ b/cql3/statements/list_service_level_statement.hh @@ -34,7 +34,7 @@ class list_service_level_statement final : public service_level_statement { bool _describe_all; public: list_service_level_statement(sstring service_level, bool describe_all); - std::unique_ptr prepare(database &db, cql_stats &stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats &stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; virtual future<> check_access(service::storage_proxy& sp, const service::client_state&) const override; virtual future<::shared_ptr> diff --git a/cql3/statements/list_users_statement.cc b/cql3/statements/list_users_statement.cc index 86fc7535ca..0ff235c9d4 100644 --- a/cql3/statements/list_users_statement.cc +++ b/cql3/statements/list_users_statement.cc @@ -47,7 +47,7 @@ #include "transport/messages/result_message.hh" std::unique_ptr cql3::statements::list_users_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/list_users_statement.hh b/cql3/statements/list_users_statement.hh index 6b4db88c64..77c4011465 100644 --- a/cql3/statements/list_users_statement.hh +++ b/cql3/statements/list_users_statement.hh @@ -52,7 +52,7 @@ namespace statements { class list_users_statement : public authentication_statement { public: - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; void validate(service::storage_proxy&, const service::client_state&) const override; future<> check_access(service::storage_proxy& proxy, const service::client_state&) const override; diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index 10a7659516..4f05374f1c 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -53,7 +53,7 @@ #include #include "db/config.hh" #include "transport/messages/result_message.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include #include "utils/UUID_gen.hh" #include "partition_slice_builder.hh" @@ -126,11 +126,11 @@ gc_clock::duration modification_statement::get_time_to_live(const query_options& } future<> modification_statement::check_access(service::storage_proxy& proxy, const service::client_state& state) const { - const database& db = proxy.local_db(); - auto f = state.has_column_family_access(db, keyspace(), column_family(), auth::permission::MODIFY); + const data_dictionary::database db = proxy.data_dictionary(); + auto f = state.has_column_family_access(db.real_database(), keyspace(), column_family(), auth::permission::MODIFY); if (has_conditions()) { - f = f.then([this, &state, &db] { - return state.has_column_family_access(db, keyspace(), column_family(), auth::permission::SELECT); + f = f.then([this, &state, db] { + return state.has_column_family_access(db.real_database(), keyspace(), column_family(), auth::permission::SELECT); }); } return f; @@ -393,7 +393,7 @@ void modification_statement::build_cas_result_set_metadata() { } void -modification_statement::process_where_clause(database& db, std::vector where_clause, prepare_context& ctx) { +modification_statement::process_where_clause(data_dictionary::database db, std::vector where_clause, prepare_context& ctx) { _restrictions = restrictions::statement_restrictions(db, s, type, where_clause, ctx, applies_only_to_static_columns(), _selects_a_collection, false); /* @@ -463,8 +463,8 @@ modification_statement::process_where_clause(database& db, std::vector -modification_statement::prepare(database& db, cql_stats& stats) { - schema_ptr schema = validation::validate_column_family(db, keyspace(), column_family()); +modification_statement::prepare(data_dictionary::database db, cql_stats& stats) { + schema_ptr schema = validation::validate_column_family(db.real_database(), keyspace(), column_family()); auto meta = get_prepare_context(); auto statement = prepare(db, meta, stats); auto partition_key_bind_indices = meta.get_partition_key_bind_indexes(*schema); @@ -472,8 +472,8 @@ modification_statement::prepare(database& db, cql_stats& stats) { } ::shared_ptr -modification_statement::prepare(database& db, prepare_context& ctx, cql_stats& stats) const { - schema_ptr schema = validation::validate_column_family(db, keyspace(), column_family()); +modification_statement::prepare(data_dictionary::database db, prepare_context& ctx, cql_stats& stats) const { + schema_ptr schema = validation::validate_column_family(db.real_database(), keyspace(), column_family()); auto prepared_attributes = _attrs->prepare(db, keyspace(), column_family()); prepared_attributes->fill_prepare_context(ctx); @@ -506,7 +506,7 @@ modification_statement::prepare(database& db, prepare_context& ctx, cql_stats& s } void -modification_statement::prepare_conditions(database& db, const schema& schema, prepare_context& ctx, +modification_statement::prepare_conditions(data_dictionary::database db, const schema& schema, prepare_context& ctx, cql3::statements::modification_statement& stmt) const { if (_if_not_exists || _if_exists || !_conditions.empty()) { diff --git a/cql3/statements/modification_statement.hh b/cql3/statements/modification_statement.hh index 205efa85c8..68b67b9f41 100644 --- a/cql3/statements/modification_statement.hh +++ b/cql3/statements/modification_statement.hh @@ -194,7 +194,7 @@ public: return _is_raw_counter_shard_write.value_or(false); } - void process_where_clause(database& db, std::vector where_clause, prepare_context& ctx); + void process_where_clause(data_dictionary::database db, std::vector where_clause, prepare_context& ctx); // CAS statement returns a result set. Prepare result set metadata // so that get_result_metadata() returns a meaningful value. diff --git a/cql3/statements/raw/batch_statement.hh b/cql3/statements/raw/batch_statement.hh index 688e76dc8f..a4594ae27b 100644 --- a/cql3/statements/raw/batch_statement.hh +++ b/cql3/statements/raw/batch_statement.hh @@ -76,7 +76,7 @@ public: } } - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/raw/delete_statement.hh b/cql3/statements/raw/delete_statement.hh index e0147a826a..6c88679037 100644 --- a/cql3/statements/raw/delete_statement.hh +++ b/cql3/statements/raw/delete_statement.hh @@ -44,7 +44,7 @@ #include "cql3/statements/raw/modification_statement.hh" #include "cql3/attributes.hh" #include "cql3/operation.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { @@ -68,7 +68,7 @@ public: conditions_vector conditions, bool if_exists); protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const override; }; diff --git a/cql3/statements/raw/insert_statement.hh b/cql3/statements/raw/insert_statement.hh index 8d6ffbb707..4c61db5647 100644 --- a/cql3/statements/raw/insert_statement.hh +++ b/cql3/statements/raw/insert_statement.hh @@ -44,7 +44,7 @@ #include "cql3/statements/raw/modification_statement.hh" #include "cql3/column_identifier.hh" #include "cql3/expr/expression.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" #include @@ -75,7 +75,7 @@ public: std::vector column_values, bool if_not_exists); - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const override; }; @@ -96,7 +96,7 @@ public: */ insert_json_statement(cf_name name, std::unique_ptr attrs, expr::expression json_value, bool if_not_exists, bool default_unset); - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const override; }; diff --git a/cql3/statements/raw/modification_statement.hh b/cql3/statements/raw/modification_statement.hh index b9ac799f33..bcd0f925b0 100644 --- a/cql3/statements/raw/modification_statement.hh +++ b/cql3/statements/raw/modification_statement.hh @@ -72,16 +72,16 @@ protected: modification_statement(cf_name name, std::unique_ptr attrs, conditions_vector conditions, bool if_not_exists, bool if_exists); public: - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; - ::shared_ptr prepare(database& db, prepare_context& ctx, cql_stats& stats) const; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; + ::shared_ptr prepare(data_dictionary::database db, prepare_context& ctx, cql_stats& stats) const; protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const = 0; // Helper function used by child classes to prepare conditions for a prepared statement. // Must be called before processing WHERE clause, because to perform sanity checks there // we need to know what kinds of conditions (static, regular) the statement has. - void prepare_conditions(database& db, const schema& schema, prepare_context& ctx, + void prepare_conditions(data_dictionary::database db, const schema& schema, prepare_context& ctx, cql3::statements::modification_statement& stmt) const; }; diff --git a/cql3/statements/raw/parsed_statement.hh b/cql3/statements/raw/parsed_statement.hh index 3cba0795f5..decb40e392 100644 --- a/cql3/statements/raw/parsed_statement.hh +++ b/cql3/statements/raw/parsed_statement.hh @@ -41,6 +41,7 @@ #pragma once +#include "data_dictionary/data_dictionary.hh" #include "cql3/prepare_context.hh" #include "cql3/column_specification.hh" @@ -49,8 +50,6 @@ #include #include -class database; - namespace cql3 { class column_identifier; @@ -74,7 +73,7 @@ public: void set_bound_variables(const std::vector<::shared_ptr>& bound_names); - virtual std::unique_ptr prepare(database& db, cql_stats& stats) = 0; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) = 0; }; } diff --git a/cql3/statements/raw/select_statement.hh b/cql3/statements/raw/select_statement.hh index 0f31fbd658..0e27a0cfc1 100644 --- a/cql3/statements/raw/select_statement.hh +++ b/cql3/statements/raw/select_statement.hh @@ -127,14 +127,14 @@ public: std::vector<::shared_ptr> group_by_columns, std::unique_ptr attrs); - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override { + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override { return prepare(db, stats, false); } - std::unique_ptr prepare(database& db, cql_stats& stats, bool for_view); + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats, bool for_view); private: - void maybe_jsonize_select_clause(database& db, schema_ptr schema); + void maybe_jsonize_select_clause(data_dictionary::database db, schema_ptr schema); ::shared_ptr prepare_restrictions( - database& db, + data_dictionary::database db, schema_ptr schema, prepare_context& ctx, ::shared_ptr selection, @@ -142,7 +142,7 @@ private: bool allow_filtering = false); /** Returns an expression for the limit or nullopt if no limit is set */ - std::optional prepare_limit(database& db, prepare_context& ctx, const std::optional& limit); + std::optional prepare_limit(data_dictionary::database db, prepare_context& ctx, const std::optional& limit); // Checks whether it is legal to have ORDER BY in this statement static void verify_ordering_is_allowed(const restrictions::statement_restrictions& restrictions); @@ -173,7 +173,7 @@ private: db::tri_mode_restriction_t::mode strict_allow_filtering, std::vector& warnings); - void ensure_filtering_columns_retrieval(database& db, + void ensure_filtering_columns_retrieval(data_dictionary::database db, selection::selection& selection, const restrictions::statement_restrictions& restrictions); diff --git a/cql3/statements/raw/update_statement.hh b/cql3/statements/raw/update_statement.hh index 889cec1423..2c1ad7aa9c 100644 --- a/cql3/statements/raw/update_statement.hh +++ b/cql3/statements/raw/update_statement.hh @@ -46,7 +46,7 @@ #include "cql3/operation.hh" #include "cql3/relation.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" #include @@ -80,7 +80,7 @@ public: std::vector where_clause, conditions_vector conditions, bool if_exists); protected: - virtual ::shared_ptr prepare_internal(database& db, schema_ptr schema, + virtual ::shared_ptr prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const override; }; diff --git a/cql3/statements/raw/use_statement.hh b/cql3/statements/raw/use_statement.hh index 4027f89d1c..19b6dab0f6 100644 --- a/cql3/statements/raw/use_statement.hh +++ b/cql3/statements/raw/use_statement.hh @@ -60,7 +60,7 @@ private: public: use_statement(sstring keyspace); - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; }; } diff --git a/cql3/statements/revoke_role_statement.hh b/cql3/statements/revoke_role_statement.hh index 968a498ba0..e1e116ab8a 100644 --- a/cql3/statements/revoke_role_statement.hh +++ b/cql3/statements/revoke_role_statement.hh @@ -63,7 +63,7 @@ public: : _role(name.to_string()), _revokee(revokee.to_string()) { } - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual future<> check_access(service::storage_proxy& proxy, const service::client_state&) const override; diff --git a/cql3/statements/revoke_statement.cc b/cql3/statements/revoke_statement.cc index 49e8bea1ee..544b90cd34 100644 --- a/cql3/statements/revoke_statement.cc +++ b/cql3/statements/revoke_statement.cc @@ -45,7 +45,7 @@ #include "service/query_state.hh" std::unique_ptr cql3::statements::revoke_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/revoke_statement.hh b/cql3/statements/revoke_statement.hh index de9986ba4b..21c29878b0 100644 --- a/cql3/statements/revoke_statement.hh +++ b/cql3/statements/revoke_statement.hh @@ -53,7 +53,7 @@ class revoke_statement : public permission_altering_statement { public: using permission_altering_statement::permission_altering_statement; - std::unique_ptr prepare(database& db, cql_stats& stats) override; + std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; future<::shared_ptr> execute(query_processor& , service::query_state& diff --git a/cql3/statements/role-management-statements.cc b/cql3/statements/role-management-statements.cc index dbc8f8ef03..9ce7a282cf 100644 --- a/cql3/statements/role-management-statements.cc +++ b/cql3/statements/role-management-statements.cc @@ -91,7 +91,7 @@ void validate_cluster_support(service::storage_proxy&) { // std::unique_ptr create_role_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } @@ -160,7 +160,7 @@ create_role_statement::execute(query_processor&, // std::unique_ptr alter_role_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } @@ -241,7 +241,7 @@ alter_role_statement::execute(query_processor&, service::query_state& state, con // std::unique_ptr drop_role_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } @@ -298,7 +298,7 @@ drop_role_statement::execute(query_processor&, service::query_state& state, cons // std::unique_ptr list_roles_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } @@ -433,7 +433,7 @@ list_roles_statement::execute(query_processor&, service::query_state& state, con // std::unique_ptr grant_role_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } @@ -461,7 +461,7 @@ grant_role_statement::execute(query_processor&, service::query_state& state, con // std::unique_ptr revoke_role_statement::prepare( - database& db, cql_stats& stats) { + data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/schema_altering_statement.cc b/cql3/statements/schema_altering_statement.cc index e15690cadd..2a4e424031 100644 --- a/cql3/statements/schema_altering_statement.cc +++ b/cql3/statements/schema_altering_statement.cc @@ -42,7 +42,8 @@ #include #include "cql3/statements/schema_altering_statement.hh" #include "locator/abstract_replication_strategy.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" +#include "mutation.hh" #include "cql3/query_processor.hh" #include "transport/messages/result_message.hh" #include "service/raft/raft_group_registry.hh" @@ -127,7 +128,7 @@ schema_altering_statement::execute(query_processor& qp, service::query_state& st bool internal = state.get_client_state().is_internal(); if (internal) { auto replication_type = locator::replication_strategy_type::everywhere_topology; - database& db = qp.db(); + data_dictionary::database db = qp.db(); if (_cf_name && _cf_name->has_keyspace()) { const auto& ks = db.find_keyspace(_cf_name->get_keyspace()); replication_type = ks.get_replication_strategy().get_type(); diff --git a/cql3/statements/schema_altering_statement.hh b/cql3/statements/schema_altering_statement.hh index a26029bc83..1df6dc694a 100644 --- a/cql3/statements/schema_altering_statement.hh +++ b/cql3/statements/schema_altering_statement.hh @@ -74,7 +74,7 @@ protected: schema_altering_statement(cf_name name, timeout_config_selector timeout_selector = &timeout_config::other_timeout); /** - * When a new database object (keyspace, table) is created, the creator needs to be granted all applicable + * When a new data_dictionary::database object (keyspace, table) is created, the creator needs to be granted all applicable * permissions on it. * * By default, this function does nothing. diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc index 978f9ac0ec..bd727b3dd7 100644 --- a/cql3/statements/select_statement.cc +++ b/cql3/statements/select_statement.cc @@ -62,7 +62,7 @@ #include "cql3/untyped_result_set.hh" #include "db/timeout_clock.hh" #include "db/consistency_level_validations.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "test/lib/select_statement_utils.hh" #include @@ -181,11 +181,11 @@ uint32_t select_statement::get_bound_terms() const { future<> select_statement::check_access(service::storage_proxy& proxy, const service::client_state& state) const { try { - const database& db = proxy.local_db(); + const data_dictionary::database db = proxy.data_dictionary(); auto&& s = db.find_schema(keyspace(), column_family()); auto& cf_name = s->is_view() ? s->view_info()->base_name() : column_family(); - return state.has_column_family_access(db, keyspace(), cf_name, auth::permission::SELECT); - } catch (const no_such_column_family& e) { + return state.has_column_family_access(db.real_database(), keyspace(), cf_name, auth::permission::SELECT); + } catch (const data_dictionary::no_such_column_family& e) { // Will be validated afterwards. return make_ready_future<>(); } @@ -840,7 +840,7 @@ primary_key_select_statement::primary_key_select_statement(schema_ptr schema, ui } ::shared_ptr -indexed_table_select_statement::prepare(database& db, +indexed_table_select_statement::prepare(data_dictionary::database db, schema_ptr schema, uint32_t bound_terms, lw_shared_ptr parameters, @@ -1349,7 +1349,7 @@ select_statement::select_statement(cf_name cf_name, validate_attrs(*_attrs); } -void select_statement::maybe_jsonize_select_clause(database& db, schema_ptr schema) { +void select_statement::maybe_jsonize_select_clause(data_dictionary::database db, schema_ptr schema) { // Fill wildcard clause with explicit column identifiers for as_json function if (_parameters->is_json()) { if (_select_clause.empty()) { @@ -1388,8 +1388,8 @@ void select_statement::maybe_jsonize_select_clause(database& db, schema_ptr sche } } -std::unique_ptr select_statement::prepare(database& db, cql_stats& stats, bool for_view) { - schema_ptr schema = validation::validate_column_family(db, keyspace(), column_family()); +std::unique_ptr select_statement::prepare(data_dictionary::database db, cql_stats& stats, bool for_view) { + schema_ptr schema = validation::validate_column_family(db.real_database(), keyspace(), column_family()); prepare_context& ctx = get_prepare_context(); maybe_jsonize_select_clause(db, schema); @@ -1462,7 +1462,7 @@ std::unique_ptr select_statement::prepare(database& db, cql_ } ::shared_ptr -select_statement::prepare_restrictions(database& db, +select_statement::prepare_restrictions(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, ::shared_ptr selection, @@ -1482,7 +1482,7 @@ select_statement::prepare_restrictions(database& db, /** Returns a expr::expression for the limit or nullopt if no limit is set */ std::optional -select_statement::prepare_limit(database& db, prepare_context& ctx, const std::optional& limit) +select_statement::prepare_limit(data_dictionary::database db, prepare_context& ctx, const std::optional& limit) { if (!limit.has_value()) { return std::nullopt; @@ -1738,7 +1738,7 @@ void select_statement::check_needs_filtering( * The columns are added with a meta-data indicating they are not to be returned * to the user. */ -void select_statement::ensure_filtering_columns_retrieval(database& db, +void select_statement::ensure_filtering_columns_retrieval(data_dictionary::database db, selection::selection& selection, const restrictions::statement_restrictions& restrictions) { for (auto&& cdef : restrictions.get_column_defs_for_filtering(db)) { diff --git a/cql3/statements/select_statement.hh b/cql3/statements/select_statement.hh index 6bad483f98..a8627204d9 100644 --- a/cql3/statements/select_statement.hh +++ b/cql3/statements/select_statement.hh @@ -197,7 +197,7 @@ class indexed_table_select_statement : public select_statement { public: static constexpr size_t max_base_table_query_concurrency = 4096; - static ::shared_ptr prepare(database& db, + static ::shared_ptr prepare(data_dictionary::database db, schema_ptr schema, uint32_t bound_terms, lw_shared_ptr parameters, diff --git a/cql3/statements/sl_prop_defs.cc b/cql3/statements/sl_prop_defs.cc index f3a7d5ccb5..b1d4b797f0 100644 --- a/cql3/statements/sl_prop_defs.cc +++ b/cql3/statements/sl_prop_defs.cc @@ -20,7 +20,7 @@ */ #include "cql3/statements/sl_prop_defs.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "duration.hh" #include "concrete_types.hh" #include diff --git a/cql3/statements/truncate_statement.cc b/cql3/statements/truncate_statement.cc index b6420547b0..c642a1d36a 100644 --- a/cql3/statements/truncate_statement.cc +++ b/cql3/statements/truncate_statement.cc @@ -42,7 +42,7 @@ #include "cql3/statements/truncate_statement.hh" #include "cql3/statements/prepared_statement.hh" #include "cql3/cql_statement.hh" -#include "database.hh" +#include "data_dictionary/data_dictionary.hh" #include "cql3/query_processor.hh" #include "service/storage_proxy.hh" #include @@ -62,7 +62,7 @@ uint32_t truncate_statement::get_bound_terms() const return 0; } -std::unique_ptr truncate_statement::prepare(database& db,cql_stats& stats) +std::unique_ptr truncate_statement::prepare(data_dictionary::database db,cql_stats& stats) { return std::make_unique(::make_shared(*this)); } diff --git a/cql3/statements/truncate_statement.hh b/cql3/statements/truncate_statement.hh index 9ffa6a0b90..4994ba83a5 100644 --- a/cql3/statements/truncate_statement.hh +++ b/cql3/statements/truncate_statement.hh @@ -56,7 +56,7 @@ public: virtual uint32_t get_bound_terms() const override; - virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; + virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; virtual bool depends_on_keyspace(const sstring& ks_name) const override; diff --git a/cql3/statements/update_statement.cc b/cql3/statements/update_statement.cc index fe42c1e71d..52632ae19b 100644 --- a/cql3/statements/update_statement.cc +++ b/cql3/statements/update_statement.cc @@ -297,7 +297,7 @@ insert_statement::insert_statement(cf_name name, { } ::shared_ptr -insert_statement::prepare_internal(database& db, schema_ptr schema, +insert_statement::prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const { auto stmt = ::make_shared(statement_type::INSERT, ctx.bound_variables_size(), schema, std::move(attrs), stats); @@ -356,7 +356,7 @@ insert_json_statement::insert_json_statement(cf_name name, , _default_unset(default_unset) { } ::shared_ptr -insert_json_statement::prepare_internal(database& db, schema_ptr schema, +insert_json_statement::prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const { // FIXME: handle _if_not_exists. For now, mark it used to quiet the compiler. #8682 @@ -381,7 +381,7 @@ update_statement::update_statement(cf_name name, { } ::shared_ptr -update_statement::prepare_internal(database& db, schema_ptr schema, +update_statement::prepare_internal(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, std::unique_ptr attrs, cql_stats& stats) const { auto stmt = ::make_shared(statement_type::UPDATE, ctx.bound_variables_size(), schema, std::move(attrs), stats); diff --git a/cql3/statements/update_statement.hh b/cql3/statements/update_statement.hh index b84bf508d9..4965094ede 100644 --- a/cql3/statements/update_statement.hh +++ b/cql3/statements/update_statement.hh @@ -44,7 +44,7 @@ #include "cql3/statements/modification_statement.hh" #include "cql3/attributes.hh" -#include "database_fwd.hh" +#include "data_dictionary/data_dictionary.hh" namespace cql3 { diff --git a/cql3/statements/use_statement.cc b/cql3/statements/use_statement.cc index 3bac447228..2ae5c4f066 100644 --- a/cql3/statements/use_statement.cc +++ b/cql3/statements/use_statement.cc @@ -67,7 +67,7 @@ use_statement::use_statement(sstring keyspace) { } -std::unique_ptr use_statement::prepare(database& db, cql_stats& stats) +std::unique_ptr use_statement::prepare(data_dictionary::database db, cql_stats& stats) { return std::make_unique(::make_shared(_keyspace)); } @@ -96,7 +96,7 @@ void use_statement::validate(service::storage_proxy&, const service::client_stat future<::shared_ptr> use_statement::execute(query_processor& qp, service::query_state& state, const query_options& options) const { - state.get_client_state().set_keyspace(qp.db(), _keyspace); + state.get_client_state().set_keyspace(qp.db().real_database(), _keyspace); auto result =::make_shared(_keyspace); return make_ready_future<::shared_ptr>(result); } diff --git a/cql3/token_relation.cc b/cql3/token_relation.cc index ec0910d1fb..a7a06846fb 100644 --- a/cql3/token_relation.cc +++ b/cql3/token_relation.cc @@ -79,7 +79,7 @@ std::vector> cql3::token_relation::to_ } ::shared_ptr cql3::token_relation::new_EQ_restriction( - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, prepare_context& ctx) { auto column_defs = get_column_definitions(*schema); auto e = to_expression(to_receivers(*schema, column_defs), _value, db, @@ -91,7 +91,7 @@ std::vector> cql3::token_relation::to_ } ::shared_ptr cql3::token_relation::new_IN_restriction( - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, prepare_context& ctx) { throw exceptions::invalid_request_exception( format("{} cannot be used with the token function", @@ -99,7 +99,7 @@ std::vector> cql3::token_relation::to_ } ::shared_ptr cql3::token_relation::new_slice_restriction( - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, prepare_context& ctx, statements::bound bound, bool inclusive) { @@ -113,7 +113,7 @@ std::vector> cql3::token_relation::to_ } ::shared_ptr cql3::token_relation::new_contains_restriction( - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, prepare_context& ctx, bool isKey) { throw exceptions::invalid_request_exception( format("{} cannot be used with the token function", @@ -121,7 +121,7 @@ std::vector> cql3::token_relation::to_ } ::shared_ptr cql3::token_relation::new_LIKE_restriction( - database&, schema_ptr, prepare_context&) { + data_dictionary::database, schema_ptr, prepare_context&) { throw exceptions::invalid_request_exception("LIKE cannot be used with the token function"); } @@ -131,7 +131,7 @@ sstring cql3::token_relation::to_string() const { cql3::expr::expression cql3::token_relation::to_expression( const std::vector>& receivers, - const expr::expression& raw, database& db, const sstring& keyspace, + const expr::expression& raw, data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const { auto e = expr::prepare_expression(raw, db, keyspace, receivers.front()); expr::fill_prepare_context(e, ctx); diff --git a/cql3/token_relation.hh b/cql3/token_relation.hh index 507d648cca..a91054da95 100644 --- a/cql3/token_relation.hh +++ b/cql3/token_relation.hh @@ -95,25 +95,25 @@ public: return true; } - ::shared_ptr new_EQ_restriction(database& db, + ::shared_ptr new_EQ_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override; - ::shared_ptr new_IN_restriction(database& db, + ::shared_ptr new_IN_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override; - ::shared_ptr new_slice_restriction(database& db, + ::shared_ptr new_slice_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx, statements::bound bound, bool inclusive) override; ::shared_ptr new_contains_restriction( - database& db, schema_ptr schema, + data_dictionary::database db, schema_ptr schema, prepare_context& ctx, bool isKey) override; - ::shared_ptr new_LIKE_restriction(database& db, + ::shared_ptr new_LIKE_restriction(data_dictionary::database db, schema_ptr schema, prepare_context& ctx) override; @@ -124,7 +124,7 @@ public: protected: expr::expression to_expression(const std::vector>& receivers, const expr::expression& raw, - database& db, + data_dictionary::database db, const sstring& keyspace, prepare_context& ctx) const override; }; diff --git a/db/schema_tables.cc b/db/schema_tables.cc index 844cbb9b10..7864fd1612 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -231,7 +231,7 @@ using namespace v3; using days = std::chrono::duration>; future<> save_system_schema(cql3::query_processor& qp, const sstring & ksname) { - auto& ks = qp.db().find_keyspace(ksname); + auto ks = qp.db().find_keyspace(ksname); auto ksm = ks.metadata(); // delete old, possibly obsolete entries in schema tables diff --git a/db/system_distributed_keyspace.cc b/db/system_distributed_keyspace.cc index 498d91c944..b66e48160b 100644 --- a/db/system_distributed_keyspace.cc +++ b/db/system_distributed_keyspace.cc @@ -266,7 +266,7 @@ future<> system_distributed_keyspace::start() { } _started = true; - co_await add_new_columns_if_missing(_qp.db(), _mm); + co_await add_new_columns_if_missing(_qp.db().real_database(), _mm); } future<> system_distributed_keyspace::stop() { @@ -393,7 +393,7 @@ system_distributed_keyspace::insert_cdc_topology_description( cdc::generation_id_v1 gen_id, const cdc::topology_description& description, context ctx) { - check_exists(NAME, CDC_TOPOLOGY_DESCRIPTION, _qp.db()); + check_exists(NAME, CDC_TOPOLOGY_DESCRIPTION, _qp.db().real_database()); return _qp.execute_internal( format("INSERT INTO {}.{} (time, description) VALUES (?,?)", NAME, CDC_TOPOLOGY_DESCRIPTION), quorum_if_many(ctx.num_token_owners), @@ -406,7 +406,7 @@ future> system_distributed_keyspace::read_cdc_topology_description( cdc::generation_id_v1 gen_id, context ctx) { - check_exists(NAME, CDC_TOPOLOGY_DESCRIPTION, _qp.db()); + check_exists(NAME, CDC_TOPOLOGY_DESCRIPTION, _qp.db().real_database()); return _qp.execute_internal( format("SELECT description FROM {}.{} WHERE time = ?", NAME, CDC_TOPOLOGY_DESCRIPTION), quorum_if_many(ctx.num_token_owners), @@ -496,7 +496,7 @@ system_distributed_keyspace::insert_cdc_generation( const size_t concurrency = 10; - auto ms = co_await get_cdc_generation_mutations(_qp.db(), id, ctx.num_token_owners, concurrency, desc); + auto ms = co_await get_cdc_generation_mutations(_qp.db().real_database(), id, ctx.num_token_owners, concurrency, desc); co_await max_concurrent_for_each(ms, concurrency, [&] (mutation& m) -> future<> { co_await _sp.mutate( { std::move(m) }, @@ -591,7 +591,7 @@ system_distributed_keyspace::create_cdc_desc( context ctx) { using namespace std::chrono_literals; - auto ms = co_await get_cdc_streams_descriptions_v2_mutation(_qp.db(), time, desc); + auto ms = co_await get_cdc_streams_descriptions_v2_mutation(_qp.db().real_database(), time, desc); co_await max_concurrent_for_each(ms, 20, [&] (mutation& m) -> future<> { // We use the storage_proxy::mutate API since CQL is not the best for handling large batches. co_await _sp.mutate( diff --git a/db/system_keyspace.cc b/db/system_keyspace.cc index fbc2f9d6da..8a87cb4eff 100644 --- a/db/system_keyspace.cc +++ b/db/system_keyspace.cc @@ -1661,7 +1661,7 @@ future<> system_keyspace::force_blocking_flush(sstring cfname) { assert(qctx); return qctx->_qp.invoke_on_all([cfname = std::move(cfname)] (cql3::query_processor& qp) { // if (!Boolean.getBoolean("cassandra.unsafesystem")) - return qp.db().flush(NAME, cfname); + return qp.db().real_database().flush(NAME, cfname); // FIXME: get real database in another way }); } diff --git a/db/view/view.cc b/db/view/view.cc index 286bca3ca3..4ddc873767 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -123,7 +123,7 @@ cql3::statements::select_statement& view_info::select_statement() const { raw->prepare_keyspace(_schema.ks_name()); raw->set_bound_variables({}); cql3::cql_stats ignored; - auto prepared = raw->prepare(service::get_local_storage_proxy().get_db().local(), ignored, true); + auto prepared = raw->prepare(service::get_local_storage_proxy().data_dictionary(), ignored, true); _select_statement = static_pointer_cast(prepared->statement); } return *_select_statement; diff --git a/main.cc b/main.cc index 29ccf2fb87..632db5586d 100644 --- a/main.cc +++ b/main.cc @@ -937,7 +937,8 @@ int main(int ac, char** av) { supervisor::notify("starting query processor"); cql3::query_processor::memory_config qp_mcfg = {memory::stats().total_memory() / 256, memory::stats().total_memory() / 2560}; debug::the_query_processor = &qp; - qp.start(std::ref(proxy), std::ref(db), std::ref(mm_notifier), std::ref(mm), qp_mcfg, std::ref(cql_config)).get(); + auto local_data_dict = seastar::sharded_parameter([] (const database& db) { return db.as_data_dictionary(); }, std::ref(db)); + qp.start(std::ref(proxy), std::move(local_data_dict), std::ref(mm_notifier), std::ref(mm), qp_mcfg, std::ref(cql_config)).get(); // #293 - do not stop anything // engine().at_exit([&qp] { return qp.stop(); }); supervisor::notify("initializing batchlog manager"); diff --git a/service/migration_manager.cc b/service/migration_manager.cc index ffec6f9d59..bf57865331 100644 --- a/service/migration_manager.cc +++ b/service/migration_manager.cc @@ -934,7 +934,7 @@ future> migration_manager::prepare_view_update_announcemen #if 0 view.metadata.validate(); #endif - auto& db = get_local_storage_proxy().get_db().local(); + auto db = get_local_storage_proxy().data_dictionary(); try { auto&& keyspace = db.find_keyspace(view->ks_name()).metadata(); auto& old_view = keyspace->cf_meta_data().at(view->cf_name()); diff --git a/table_helper.cc b/table_helper.cc index 59263b1bc2..22252dae9d 100644 --- a/table_helper.cc +++ b/table_helper.cc @@ -28,7 +28,7 @@ #include "service/migration_manager.hh" future<> table_helper::setup_table(cql3::query_processor& qp) const { - auto& db = qp.db(); + auto db = qp.db(); if (db.has_schema(_keyspace, _name)) { return make_ready_future<>(); @@ -124,7 +124,7 @@ future<> table_helper::setup_keyspace(cql3::query_processor& qp, const sstring& } } return seastar::async([&qp, &keyspace_name, replication_factor, &qs, tables] { - database& db = qp.db(); + data_dictionary::database db = qp.db(); // Create a keyspace if (!db.has_keyspace(keyspace_name)) { @@ -135,7 +135,7 @@ future<> table_helper::setup_keyspace(cql3::query_processor& qp, const sstring& qp.get_migration_manager().announce_new_keyspace(ksm, api::min_timestamp).get(); } - qs.get_client_state().set_keyspace(db, keyspace_name); + qs.get_client_state().set_keyspace(db.real_database(), keyspace_name); // Create tables diff --git a/test/boost/statement_restrictions_test.cc b/test/boost/statement_restrictions_test.cc index 3d571bef9f..6714b188e2 100644 --- a/test/boost/statement_restrictions_test.cc +++ b/test/boost/statement_restrictions_test.cc @@ -41,7 +41,7 @@ query::clustering_row_ranges slice( const sstring& table_name = "t", const sstring& keyspace_name = "ks") { prepare_context ctx; return restrictions::statement_restrictions( - env.local_db(), + env.data_dictionary(), env.local_db().find_schema(keyspace_name, table_name), statements::statement_type::SELECT, where_clause, diff --git a/test/lib/cql_test_env.cc b/test/lib/cql_test_env.cc index 33f924db3e..fb1a10504d 100644 --- a/test/lib/cql_test_env.cc +++ b/test/lib/cql_test_env.cc @@ -638,7 +638,8 @@ public: auto stop_mm = defer([&mm] { mm.stop().get(); }); cql3::query_processor::memory_config qp_mcfg = {memory::stats().total_memory() / 256, memory::stats().total_memory() / 2560}; - qp.start(std::ref(proxy), std::ref(db), std::ref(mm_notif), std::ref(mm), qp_mcfg, std::ref(cql_config)).get(); + auto local_data_dict = seastar::sharded_parameter([] (const database& db) { return db.as_data_dictionary(); }, std::ref(db)); + qp.start(std::ref(proxy), std::move(local_data_dict), std::ref(mm_notif), std::ref(mm), qp_mcfg, std::ref(cql_config)).get(); auto stop_qp = defer([&qp] { qp.stop().get(); }); // In main.cc we call db::system_keyspace::setup which calls diff --git a/tools/schema_loader.cc b/tools/schema_loader.cc index c89591d1e4..68bc873f94 100644 --- a/tools/schema_loader.cc +++ b/tools/schema_loader.cc @@ -103,7 +103,7 @@ std::vector do_load_schemas(std::string_view schema_str) { } auto raw_statement = cql3::query_processor::parse_statement( fmt::format("CREATE KEYSPACE {} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': '1'}}", name)); - auto prepared_statement = raw_statement->prepare(db, cql_stats); + auto prepared_statement = raw_statement->prepare(db.as_data_dictionary(), cql_stats); auto* statement = prepared_statement->statement.get(); auto p = dynamic_cast(statement); assert(p); @@ -119,16 +119,16 @@ std::vector do_load_schemas(std::string_view schema_str) { throw std::runtime_error(format("tools:do_load_schemas(): failed to parse CQL statements: {}", std::current_exception())); } for (auto& raw_statement : raw_statements) { - auto prepared_statement = raw_statement->prepare(db, cql_stats); + auto prepared_statement = raw_statement->prepare(db.as_data_dictionary(), cql_stats); auto* statement = prepared_statement->statement.get(); if (auto p = dynamic_cast(statement)) { db.create_keyspace(p->get_keyspace_metadata(*token_metadata.local().get()), erm_factory.local()).get(); } else if (auto p = dynamic_cast(statement)) { - auto type = p->create_type(db); + auto type = p->create_type(db.as_data_dictionary()); find_or_create_keyspace(p->keyspace()).add_user_type(std::move(type)); } else if (auto p = dynamic_cast(statement)) { - schemas.push_back(p->get_cf_meta_data(db)); + schemas.push_back(p->get_cf_meta_data(db.as_data_dictionary())); } else if (auto p = dynamic_cast(statement)) { if (p->keyspace() != db::schema_tables::NAME && p->column_family() != db::schema_tables::DROPPED_COLUMNS) { throw std::runtime_error(fmt::format("tools::do_load_schemas(): expected modification statement to be against {}.{}, but it is against {}.{}",