Khepri: Don't sync cluster if the node is already clustered in `khepri_db` enable function

[Why]
The feature flag enable function is called during the initial migration
or when a node is later added to a cluster.

In this latter situation, the cluster is already formed and the Mnesia
tables were already migrated. Syncing the cluster in this specific
situation might kick another node that is currently unreachable.

[How]
If the node running the enable function is already clustered, we skip
the cluster sync.
This commit is contained in:
Jean-Sébastien Pédron 2025-03-17 12:21:58 +01:00
parent f5805b83d2
commit 4811fd44fd
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC
1 changed files with 25 additions and 13 deletions

View File

@ -1513,19 +1513,31 @@ get_feature_state(Node) ->
%% @private
khepri_db_migration_enable(#{feature_name := FeatureName}) ->
maybe
ok ?= sync_cluster_membership_from_mnesia(FeatureName),
?LOG_INFO(
"Feature flag `~s`: unregistering legacy projections",
[FeatureName],
#{domain => ?RMQLOG_DOMAIN_DB}),
ok ?= unregister_legacy_projections(),
?LOG_INFO(
"Feature flag `~s`: registering projections",
[FeatureName],
#{domain => ?RMQLOG_DOMAIN_DB}),
ok ?= register_projections(),
migrate_mnesia_tables(FeatureName)
Members = locally_known_members(),
case length(Members) < 2 of
true ->
maybe
ok ?= sync_cluster_membership_from_mnesia(FeatureName),
?LOG_INFO(
"Feature flag `~s`: unregistering legacy projections",
[FeatureName],
#{domain => ?RMQLOG_DOMAIN_DB}),
ok ?= unregister_legacy_projections(),
?LOG_INFO(
"Feature flag `~s`: registering projections",
[FeatureName],
#{domain => ?RMQLOG_DOMAIN_DB}),
ok ?= register_projections(),
migrate_mnesia_tables(FeatureName)
end;
false ->
?LOG_INFO(
"Feature flag `~s`: node ~0p already clustered (feature flag "
"enabled as part of clustering?); "
"skipping Mnesia->Khepri migration",
[node()],
#{domain => ?RMQLOG_DOMAIN_DB}),
ok
end.
%% @private