diff --git a/cql3/statements/create_keyspace_statement.cc b/cql3/statements/create_keyspace_statement.cc
index ebdd9e4955..16787f5952 100644
--- a/cql3/statements/create_keyspace_statement.cc
+++ b/cql3/statements/create_keyspace_statement.cc
@@ -39,6 +39,7 @@
* along with Scylla. If not, see .
*/
+#include
#include "cql3/statements/create_keyspace_statement.hh"
#include "cql3/statements/ks_prop_defs.hh"
#include "prepared_statement.hh"
@@ -110,26 +111,47 @@ void create_keyspace_statement::validate(service::storage_proxy&, const service:
#endif
}
-future> create_keyspace_statement::announce_migration(query_processor& qp) const
-{
- return make_ready_future<>().then([this, p = qp.proxy().shared_from_this(), &mm = qp.get_migration_manager()] {
- const auto& tm = *p->get_token_metadata_ptr();
- return mm.announce_new_keyspace(_attrs->as_ks_metadata(_name, tm));
- }).then_wrapped([this] (auto&& f) {
- try {
- f.get();
- using namespace cql_transport;
- return ::make_shared(
- event::schema_change::change_type::CREATED,
- event::schema_change::target_type::KEYSPACE,
- this->keyspace());
- } catch (const exceptions::already_exists_exception& e) {
- if (_if_not_exists) {
- return ::shared_ptr();
- }
- throw e;
+future, std::vector>> create_keyspace_statement::prepare_schema_mutations(query_processor& qp) const {
+ using namespace cql_transport;
+ auto p = qp.proxy().shared_from_this();
+ const auto& tm = *p->get_token_metadata_ptr();
+ ::shared_ptr ret;
+ std::vector m;
+
+ try {
+ m = qp.get_migration_manager().prepare_new_keyspace_announcement(_attrs->as_ks_metadata(_name, tm), api::new_timestamp());
+
+ ret = ::make_shared(
+ event::schema_change::change_type::CREATED,
+ event::schema_change::target_type::KEYSPACE,
+ keyspace());
+ } catch (const exceptions::already_exists_exception& e) {
+ if (!_if_not_exists) {
+ co_return coroutine::exception(std::current_exception());
}
- });
+ }
+
+ co_return std::make_pair(std::move(ret), std::move(m));
+}
+
+
+future> create_keyspace_statement::announce_migration(query_processor& qp) const {
+ auto p = qp.proxy().shared_from_this();
+ const auto& tm = *p->get_token_metadata_ptr();
+ try {
+ co_await qp.get_migration_manager().announce_new_keyspace(_attrs->as_ks_metadata(_name, tm));
+
+ using namespace cql_transport;
+ co_return ::make_shared(
+ event::schema_change::change_type::CREATED,
+ event::schema_change::target_type::KEYSPACE,
+ keyspace());
+ } catch (const exceptions::already_exists_exception& e) {
+ if (_if_not_exists) {
+ co_return ::shared_ptr();
+ }
+ co_return coroutine::exception(std::current_exception());
+ }
}
std::unique_ptr
diff --git a/cql3/statements/create_keyspace_statement.hh b/cql3/statements/create_keyspace_statement.hh
index c828dafccb..191265b53f 100644
--- a/cql3/statements/create_keyspace_statement.hh
+++ b/cql3/statements/create_keyspace_statement.hh
@@ -94,6 +94,9 @@ public:
virtual future> announce_migration(query_processor& qp) const override;
+ future, std::vector>> prepare_schema_mutations(query_processor& qp) const override;
+ virtual bool has_prepare_schema_mutations() const override { return true; }
+
virtual std::unique_ptr prepare(database& db, cql_stats& stats) override;
virtual future<> grant_permissions_to_creator(const service::client_state&) const override;