diff --git a/thrift/handler.cc b/thrift/handler.cc index 3ccb2f46f3..0012dbd8c6 100644 --- a/thrift/handler.cc +++ b/thrift/handler.cc @@ -488,21 +488,7 @@ public: void system_add_keyspace(tcxx::function cob, tcxx::function exn_cob, const KsDef& ks_def) { return with_cob(std::move(cob), std::move(exn_cob), [&] { - thrift_validation::validate_ks_def(ks_def); - std::vector cf_defs; - cf_defs.reserve(ks_def.cf_defs.size()); - for (const CfDef& cf_def : ks_def.cf_defs) { - if (cf_def.keyspace != ks_def.name) { - throw make_exception("CfDef (%s) had a keyspace definition that did not match KsDef", cf_def.keyspace); - } - cf_defs.emplace_back(schema_from_thrift(cf_def, ks_def.name)); - } - auto ksm = make_lw_shared( - to_sstring(ks_def.name), - to_sstring(ks_def.strategy_class), - std::map{ks_def.strategy_options.begin(), ks_def.strategy_options.end()}, - ks_def.durable_writes, - std::move(cf_defs)); + auto ksm = keyspace_from_thrift(ks_def); return service::get_local_migration_manager().announce_new_keyspace(std::move(ksm), false).then([this] { return std::string(_db.local().get_version().to_sstring()); }); @@ -774,6 +760,23 @@ private: } return builder.build(schema_builder::compact_storage::yes); } + static lw_shared_ptr keyspace_from_thrift(const KsDef& ks_def) { + thrift_validation::validate_ks_def(ks_def); + std::vector cf_defs; + cf_defs.reserve(ks_def.cf_defs.size()); + for (const CfDef& cf_def : ks_def.cf_defs) { + if (cf_def.keyspace != ks_def.name) { + throw make_exception("CfDef (%s) had a keyspace definition that did not match KsDef", cf_def.keyspace); + } + cf_defs.emplace_back(schema_from_thrift(cf_def, ks_def.name)); + } + return make_lw_shared( + to_sstring(ks_def.name), + to_sstring(ks_def.strategy_class), + std::map{ks_def.strategy_options.begin(), ks_def.strategy_options.end()}, + ks_def.durable_writes, + std::move(cf_defs)); + } static column_family& lookup_column_family(database& db, const sstring& ks_name, const sstring& cf_name) { try { return db.find_column_family(ks_name, cf_name);