diff --git a/db/schema_tables.cc b/db/schema_tables.cc index bf9c6ac04d..5d94b54992 100644 --- a/db/schema_tables.cc +++ b/db/schema_tables.cc @@ -822,6 +822,14 @@ future<> merge_schema(distributed& proxy, gms::feature_s }); } +future<> recalculate_schema_version(distributed& proxy, gms::feature_service& feat) { + return merge_lock().then([&proxy, &feat] { + return update_schema_version_and_announce(proxy, feat.cluster_schema_features()); + }).finally([] { + return merge_unlock(); + }); +} + future<> merge_schema(distributed& proxy, std::vector mutations, bool do_flush) { return merge_lock().then([&proxy, mutations = std::move(mutations), do_flush] () mutable { diff --git a/db/schema_tables.hh b/db/schema_tables.hh index f828c00c45..51345cf6a9 100644 --- a/db/schema_tables.hh +++ b/db/schema_tables.hh @@ -170,6 +170,13 @@ future<> merge_schema(distributed& proxy, gms::feature_s future<> merge_schema(distributed& proxy, std::vector mutations, bool do_flush); +// Recalculates the local schema version and publishes it in gossip. +// +// It is safe to call concurrently with recalculate_schema_version() and merge_schema() in which case it +// is guaranteed that the schema version we end up with after all calls will reflect the most recent state +// of feature_service and schema tables. +future<> recalculate_schema_version(distributed& proxy, gms::feature_service& feat); + future> merge_keyspaces(distributed& proxy, schema_result&& before, schema_result&& after); std::vector make_create_keyspace_mutations(lw_shared_ptr keyspace, api::timestamp_type timestamp, bool with_tables_and_types_and_functions = true); diff --git a/service/migration_manager.cc b/service/migration_manager.cc index 1d3cdce603..3d13653775 100644 --- a/service/migration_manager.cc +++ b/service/migration_manager.cc @@ -92,7 +92,7 @@ void migration_manager::init_messaging_service() //FIXME: future discarded. (void)with_gate(_background_tasks, [this] { mlogger.debug("features changed, recalculating schema version"); - return update_schema_version_and_announce(get_storage_proxy(), _feat.cluster_schema_features()); + return db::schema_tables::recalculate_schema_version(get_storage_proxy(), _feat); }); };