diff --git a/cql3/statements/schema_altering_statement.cc b/cql3/statements/schema_altering_statement.cc index e2fdd60056..0535556061 100644 --- a/cql3/statements/schema_altering_statement.cc +++ b/cql3/statements/schema_altering_statement.cc @@ -39,11 +39,14 @@ * along with Scylla. If not, see . */ +#include #include "cql3/statements/schema_altering_statement.hh" #include "locator/abstract_replication_strategy.hh" #include "database.hh" #include "cql3/query_processor.hh" #include "transport/messages/result_message.hh" +#include "service/raft/raft_group_registry.hh" +#include "service/migration_manager.hh" namespace cql3 { @@ -89,19 +92,39 @@ void schema_altering_statement::prepare_keyspace(const service::client_state& st } } +future, std::vector>> +schema_altering_statement::prepare_schema_mutations(query_processor& qp) const { + assert(false); + co_return std::make_pair(::shared_ptr(), std::vector()); +} + +bool schema_altering_statement::has_prepare_schema_mutations() const { + return false; +} + future<::shared_ptr> schema_altering_statement::execute0(query_processor& qp, service::query_state& state, const query_options& options) const { + auto& mm = qp.get_migration_manager(); + ::shared_ptr ce; + + if (has_prepare_schema_mutations()) { + auto [ret, m] = co_await prepare_schema_mutations(qp); + + if (!m.empty()) { + co_await mm.announce(std::move(m)); + } + + ce = std::move(ret); + } else { + ce = co_await announce_migration(qp); + } // If an IF [NOT] EXISTS clause was used, this may not result in an actual schema change. To avoid doing // extra work in the drivers to handle schema changes, we return an empty message in this case. (CASSANDRA-7600) - return announce_migration(qp).then([this] (auto ce) { - ::shared_ptr result; - if (!ce) { - result = ::make_shared(); - } else { - result = ::make_shared(ce); - } - return make_ready_future<::shared_ptr>(result); - }); + if (!ce) { + co_return ::make_shared(); + } else { + co_return ::make_shared(ce); + } } future<::shared_ptr> diff --git a/cql3/statements/schema_altering_statement.hh b/cql3/statements/schema_altering_statement.hh index e729c2a14a..25d290e205 100644 --- a/cql3/statements/schema_altering_statement.hh +++ b/cql3/statements/schema_altering_statement.hh @@ -49,6 +49,8 @@ #include +class mutation; + namespace cql3 { class query_processor; @@ -88,6 +90,8 @@ protected: virtual void prepare_keyspace(const service::client_state& state) override; virtual future<::shared_ptr> announce_migration(query_processor& qp) const = 0; + virtual future, std::vector>> prepare_schema_mutations(query_processor& qp) const; + virtual bool has_prepare_schema_mutations() const; virtual future<::shared_ptr> execute(query_processor& qp, service::query_state& state, const query_options& options) const override;