Skip to content

Commit c8c5fa3

Browse files
committed
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.
1 parent a151171 commit c8c5fa3

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,19 +1528,31 @@ get_feature_state(Node) ->
15281528
%% @private
15291529

15301530
khepri_db_migration_enable(#{feature_name := FeatureName}) ->
1531-
maybe
1532-
ok ?= sync_cluster_membership_from_mnesia(FeatureName),
1533-
?LOG_INFO(
1534-
"Feature flag `~s`: unregistering legacy projections",
1535-
[FeatureName],
1536-
#{domain => ?RMQLOG_DOMAIN_DB}),
1537-
ok ?= unregister_legacy_projections(),
1538-
?LOG_INFO(
1539-
"Feature flag `~s`: registering projections",
1540-
[FeatureName],
1541-
#{domain => ?RMQLOG_DOMAIN_DB}),
1542-
ok ?= register_projections(),
1543-
migrate_mnesia_tables(FeatureName)
1531+
Members = locally_known_members(),
1532+
case length(Members) < 2 of
1533+
true ->
1534+
maybe
1535+
ok ?= sync_cluster_membership_from_mnesia(FeatureName),
1536+
?LOG_INFO(
1537+
"Feature flag `~s`: unregistering legacy projections",
1538+
[FeatureName],
1539+
#{domain => ?RMQLOG_DOMAIN_DB}),
1540+
ok ?= unregister_legacy_projections(),
1541+
?LOG_INFO(
1542+
"Feature flag `~s`: registering projections",
1543+
[FeatureName],
1544+
#{domain => ?RMQLOG_DOMAIN_DB}),
1545+
ok ?= register_projections(),
1546+
migrate_mnesia_tables(FeatureName)
1547+
end;
1548+
false ->
1549+
?LOG_INFO(
1550+
"Feature flag `~s`: node ~0p already clustered (feature flag "
1551+
"enabled as part of clustering?); "
1552+
"skipping Mnesia->Khepri migration",
1553+
[node()],
1554+
#{domain => ?RMQLOG_DOMAIN_DB}),
1555+
ok
15441556
end.
15451557

15461558
%% @private

0 commit comments

Comments
 (0)