schema: Replace keyspace's schema_ptr on CF update
This patch ensures we replace the schema_ptr held by its respective keyspace object when a column family is being updated. Signed-off-by: Duarte Nunes <duarte@scylladb.com> Message-Id: <20160623085710.26168-1-duarte@scylladb.com>
This commit is contained in:
committed by
Tomasz Grabiec
parent
3fa7bb1292
commit
aacc7193f2
@@ -1590,7 +1590,7 @@ void database::add_column_family(schema_ptr schema, column_family::config cfg) {
|
||||
if (_ks_cf_to_uuid.count(kscf) != 0) {
|
||||
throw std::invalid_argument("Column family " + schema->cf_name() + " exists");
|
||||
}
|
||||
ks->second.add_column_family(schema);
|
||||
ks->second.add_or_update_column_family(schema);
|
||||
cf->start();
|
||||
_column_families.emplace(uuid, std::move(cf));
|
||||
_ks_cf_to_uuid.emplace(std::move(kscf), uuid);
|
||||
|
||||
@@ -761,8 +761,8 @@ public:
|
||||
const lw_shared_ptr<user_types_metadata>& user_types() const {
|
||||
return _user_types;
|
||||
}
|
||||
void add_column_family(const schema_ptr& s) {
|
||||
_cf_meta_data.emplace(s->cf_name(), s);
|
||||
void add_or_update_column_family(const schema_ptr& s) {
|
||||
_cf_meta_data[s->cf_name()] = s;
|
||||
}
|
||||
void remove_column_family(const schema_ptr& s) {
|
||||
_cf_meta_data.erase(s->cf_name());
|
||||
@@ -822,8 +822,8 @@ public:
|
||||
const locator::abstract_replication_strategy& get_replication_strategy() const;
|
||||
column_family::config make_column_family_config(const schema& s) const;
|
||||
future<> make_directory_for_column_family(const sstring& name, utils::UUID uuid);
|
||||
void add_column_family(const schema_ptr& s) {
|
||||
_metadata->add_column_family(s);
|
||||
void add_or_update_column_family(const schema_ptr& s) {
|
||||
_metadata->add_or_update_column_family(s);
|
||||
}
|
||||
void add_user_type(const user_type ut) {
|
||||
_metadata->add_user_type(ut);
|
||||
|
||||
@@ -696,12 +696,14 @@ future<std::set<sstring>> merge_keyspaces(distributed<service::storage_proxy>& p
|
||||
|
||||
static future<> update_column_family(database& db, schema_ptr new_schema) {
|
||||
column_family& cfm = db.find_column_family(new_schema->id());
|
||||
keyspace& ks = db.find_keyspace(new_schema->ks_name());
|
||||
|
||||
bool columns_changed = !cfm.schema()->equal_columns(*new_schema);
|
||||
|
||||
auto s = local_schema_registry().learn(new_schema);
|
||||
s->registry_entry()->mark_synced();
|
||||
cfm.set_schema(std::move(s));
|
||||
ks.metadata()->add_or_update_column_family(new_schema);
|
||||
|
||||
return service::get_local_migration_manager().notify_update_column_family(cfm.schema(), columns_changed);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,38 @@ SEASTAR_TEST_CASE(test_new_schema_with_no_structural_change_is_propagated) {
|
||||
});
|
||||
}
|
||||
|
||||
SEASTAR_TEST_CASE(test_schema_is_updated_in_keyspace) {
|
||||
return do_with_cql_env([](cql_test_env& e) {
|
||||
return seastar::async([&] {
|
||||
auto builder = schema_builder("tests", "table")
|
||||
.with_column("pk", bytes_type, column_kind::partition_key)
|
||||
.with_column("v1", bytes_type);
|
||||
|
||||
e.execute_cql("create keyspace tests with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };").get();
|
||||
|
||||
auto old_schema = builder.build();
|
||||
|
||||
service::get_local_migration_manager().announce_new_column_family(old_schema, false).get();
|
||||
|
||||
auto s = e.local_db().find_schema(old_schema->id());
|
||||
BOOST_REQUIRE_EQUAL(*old_schema, *s);
|
||||
BOOST_REQUIRE_EQUAL(864000, s->gc_grace_seconds().count());
|
||||
BOOST_REQUIRE_EQUAL(*s, *e.local_db().find_keyspace(s->ks_name()).metadata()->cf_meta_data().at(s->cf_name()));
|
||||
|
||||
builder.set_gc_grace_seconds(1);
|
||||
auto new_schema = builder.build();
|
||||
|
||||
service::get_local_migration_manager().announce_column_family_update(new_schema, false).get();
|
||||
|
||||
s = e.local_db().find_schema(old_schema->id());
|
||||
BOOST_REQUIRE_NE(*old_schema, *s);
|
||||
BOOST_REQUIRE_EQUAL(*new_schema, *s);
|
||||
BOOST_REQUIRE_EQUAL(1, s->gc_grace_seconds().count());
|
||||
BOOST_REQUIRE_EQUAL(*s, *e.local_db().find_keyspace(s->ks_name()).metadata()->cf_meta_data().at(s->cf_name()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
SEASTAR_TEST_CASE(test_tombstones_are_ignored_in_version_calculation) {
|
||||
return do_with_cql_env([](cql_test_env& e) {
|
||||
return seastar::async([&] {
|
||||
|
||||
Reference in New Issue
Block a user