diff --git a/database.cc b/database.cc index 5fc5a2360f..ae2124b099 100644 --- a/database.cc +++ b/database.cc @@ -429,11 +429,11 @@ void database::add_keyspace(sstring name, keyspace k) { } future<> -create_keyspace(distributed& db, sstring name) { - return make_directory(db.local()._cfg->data_file_directories() + "/" + name).then([name, &db] { - return db.invoke_on_all([&name] (database& db) { - auto cfg = db.make_keyspace_config(name); - db.add_keyspace(name, keyspace(cfg)); +create_keyspace(distributed& db, const keyspace_metadata& ksm) { + return make_directory(db.local()._cfg->data_file_directories() + "/" + ksm.name()).then([&ksm, &db] { + return db.invoke_on_all([&ksm] (database& db) { + auto cfg = db.make_keyspace_config(ksm); + db.add_keyspace(ksm.name(), keyspace(cfg)); }); }); // FIXME: rollback on error, or keyspace directory remains on disk, poisoning @@ -588,12 +588,12 @@ schema_ptr database::find_schema(const utils::UUID& uuid) const throw (no_such_c } keyspace& -database::find_or_create_keyspace(const sstring& name) { - auto i = _keyspaces.find(name); +database::find_or_create_keyspace(const keyspace_metadata& ksm) { + auto i = _keyspaces.find(ksm.name()); if (i != _keyspaces.end()) { return i->second; } - return _keyspaces.emplace(name, keyspace(make_keyspace_config(name))).first->second; + return _keyspaces.emplace(ksm.name(), keyspace(make_keyspace_config(ksm))).first->second; } void @@ -755,9 +755,9 @@ future<> database::apply(const frozen_mutation& m) { } keyspace::config -database::make_keyspace_config(sstring name) const { +database::make_keyspace_config(const keyspace_metadata& ksm) const { keyspace::config cfg; - cfg.datadir = sprint("%s/%s", _cfg->data_file_directories(), name); + cfg.datadir = sprint("%s/%s", _cfg->data_file_directories(), ksm.name()); return cfg; } diff --git a/database.hh b/database.hh index 0c026714c9..70be40724b 100644 --- a/database.hh +++ b/database.hh @@ -255,7 +255,7 @@ public: const utils::UUID& find_uuid(const schema_ptr&) const throw (std::out_of_range); /* below, find* throws no_such_ on fail */ - keyspace& find_or_create_keyspace(const sstring& name); + keyspace& find_or_create_keyspace(const keyspace_metadata&); keyspace& find_keyspace(const sstring& name) throw (no_such_keyspace); const keyspace& find_keyspace(const sstring& name) const throw (no_such_keyspace); bool has_keyspace(const sstring& name) const; @@ -275,14 +275,14 @@ public: unsigned shard_of(const frozen_mutation& m); future> query(const query::read_command& cmd); future<> apply(const frozen_mutation&); - keyspace::config make_keyspace_config(sstring name) const; + keyspace::config make_keyspace_config(const keyspace_metadata& ksm) const; friend std::ostream& operator<<(std::ostream& out, const database& db); - friend future<> create_keyspace(distributed&, sstring); + friend future<> create_keyspace(distributed&, const keyspace_metadata&); }; // Creates a keyspace. Keyspaces have a non-sharded // component (the directory), so a global function is needed. -future<> create_keyspace(distributed& db, sstring name); +future<> create_keyspace(distributed& db, const keyspace_metadata&); // FIXME: stub class secondary_index_manager {}; diff --git a/db/legacy_schema_tables.cc b/db/legacy_schema_tables.cc index 22649637ca..51cfdf0a2a 100644 --- a/db/legacy_schema_tables.cc +++ b/db/legacy_schema_tables.cc @@ -586,7 +586,7 @@ std::vector ALL { KEYSPACES, COLUMNFAMILIES, COLUMNS, TRIGGERS, USE return proxy.get_db().invoke_on_all([&created, altered = std::move(altered)] (database& db) { for (auto&& kv : created) { auto ksm = create_keyspace_from_schema_partition(kv); - keyspace k(db.make_keyspace_config(ksm->name())); + keyspace k(db.make_keyspace_config(*ksm)); k.create_replication_strategy(*ksm); db.add_keyspace(ksm->name(), std::move(k)); } diff --git a/db/system_keyspace.cc b/db/system_keyspace.cc index 948126c814..ecaff4bbe3 100644 --- a/db/system_keyspace.cc +++ b/db/system_keyspace.cc @@ -1001,7 +1001,12 @@ std::vector all_tables() { } void make(database& db) { - auto kscfg = db.make_keyspace_config("system"); + keyspace_metadata ksm{"system", + "org.apache.cassandra.locator.SimpleStrategy", + std::unordered_map{}, + false + }; + auto kscfg = db.make_keyspace_config(ksm); keyspace ks{std::move(kscfg)}; db.add_keyspace("system", std::move(ks)); for (auto&& table : all_tables()) { diff --git a/tests/urchin/cql_query_test.cc b/tests/urchin/cql_query_test.cc index 76d6b95bee..218c13a0c9 100644 --- a/tests/urchin/cql_query_test.cc +++ b/tests/urchin/cql_query_test.cc @@ -791,8 +791,13 @@ SEASTAR_TEST_CASE(test_user_type) { {int32_type, long_type, utf8_type}); }; return do_with_cql_env([make_user_type] (cql_test_env& e) { + keyspace_metadata ksm{"ks", + "org.apache.cassandra.locator.SimpleStrategy", + std::unordered_map{}, + false + }; // We don't have "CREATE TYPE" yet, so we must insert the type manually - e.local_db().find_or_create_keyspace("ks")._user_types.add_type(make_user_type()); + e.local_db().find_or_create_keyspace(ksm)._user_types.add_type(make_user_type()); return e.create_table([make_user_type] (auto ks_name) { // CQL: "create table cf (id int primary key, t ut1)"; return schema({}, ks_name, "cf", diff --git a/tests/urchin/cql_test_env.cc b/tests/urchin/cql_test_env.cc index fc23233797..4746c7596c 100644 --- a/tests/urchin/cql_test_env.cc +++ b/tests/urchin/cql_test_env.cc @@ -92,14 +92,14 @@ public: return _db->invoke_on_all([schema_maker, id, this] (database& db) { auto cf_schema = make_lw_shared(schema_maker(ks_name)); cf_schema->set_id(id); - auto& ks = db.find_or_create_keyspace(ks_name); - auto cfg = ks.make_column_family_config(*cf_schema); - db.add_column_family(column_family(std::move(cf_schema), std::move(cfg))); keyspace_metadata ksm(ks_name, "org.apache.cassandra.locator.SimpleStrategy", std::unordered_map(), false ); + auto& ks = db.find_or_create_keyspace(ksm); + auto cfg = ks.make_column_family_config(*cf_schema); + db.add_column_family(column_family(std::move(cf_schema), std::move(cfg))); ks.create_replication_strategy(ksm); }); } diff --git a/thrift/handler.cc b/thrift/handler.cc index 88b26d85ab..828055e7b2 100644 --- a/thrift/handler.cc +++ b/thrift/handler.cc @@ -428,7 +428,12 @@ public: boost::for_each(ks_def.cf_defs, [&cf_ids] (auto&&) { cf_ids.push_back(utils::UUID_gen::get_time_UUID()); }); - create_keyspace(_db, ks_def.name).then([this, ks_def, cf_ids] { + keyspace_metadata ksm(to_sstring(ks_def.name), + to_sstring(ks_def.strategy_class), + std::unordered_map{ks_def.strategy_options.begin(), ks_def.strategy_options.end()}, + ks_def.durable_writes, + std::vector{}); // FIXME + create_keyspace(_db, ksm).then([this, ks_def, cf_ids] { return parallel_for_each(boost::combine(ks_def.cf_defs, cf_ids), [this, ks_def, cf_ids] (auto&& cf_def_and_id) { // We create the directory on the local shard, since the same directory is // used for all shards.