Skip to content

Commit 0fd6c3a

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 dee5cb1 commit 0fd6c3a

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
@@ -1513,19 +1513,31 @@ get_feature_state(Node) ->
15131513
%% @private
15141514

15151515
khepri_db_migration_enable(#{feature_name := FeatureName}) ->
1516-
maybe
1517-
ok ?= sync_cluster_membership_from_mnesia(FeatureName),
1518-
?LOG_INFO(
1519-
"Feature flag `~s`: unregistering legacy projections",
1520-
[FeatureName],
1521-
#{domain => ?RMQLOG_DOMAIN_DB}),
1522-
ok ?= unregister_legacy_projections(),
1523-
?LOG_INFO(
1524-
"Feature flag `~s`: registering projections",
1525-
[FeatureName],
1526-
#{domain => ?RMQLOG_DOMAIN_DB}),
1527-
ok ?= register_projections(),
1528-
migrate_mnesia_tables(FeatureName)
1516+
Members = locally_known_members(),
1517+
case length(Members) < 2 of
1518+
true ->
1519+
maybe
1520+
ok ?= sync_cluster_membership_from_mnesia(FeatureName),
1521+
?LOG_INFO(
1522+
"Feature flag `~s`: unregistering legacy projections",
1523+
[FeatureName],
1524+
#{domain => ?RMQLOG_DOMAIN_DB}),
1525+
ok ?= unregister_legacy_projections(),
1526+
?LOG_INFO(
1527+
"Feature flag `~s`: registering projections",
1528+
[FeatureName],
1529+
#{domain => ?RMQLOG_DOMAIN_DB}),
1530+
ok ?= register_projections(),
1531+
migrate_mnesia_tables(FeatureName)
1532+
end;
1533+
false ->
1534+
?LOG_INFO(
1535+
"Feature flag `~s`: node ~0p already clustered (feature flag "
1536+
"enabled as part of clustering?); "
1537+
"skipping Mnesia->Khepri migration",
1538+
[node()],
1539+
#{domain => ?RMQLOG_DOMAIN_DB}),
1540+
ok
15291541
end.
15301542

15311543
%% @private

0 commit comments

Comments
 (0)