Skip to content

Commit bad9b97

Browse files
committed
rabbit_feature_flags: Sync enabled feature flags differently on virgin node
If a virgin node starts as clustered (thanks to peer discovery), we need to mark feature flags already enabled remotely as enabled locally too. We can't do a regular cluster sync because remote nodes may have required feature flags which are disabled locally on the virgin node. Therefore, those nodes don't have the migration code for these feature flags anymore and the feature flags' state can't be changed. By doing this special sync, we allow a clustered virgin node to join a cluster with remote nodes having required feature flags.
1 parent 5a8530c commit bad9b97

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

deps/rabbit/src/rabbit_feature_flags.erl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,44 @@ sync_cluster_v1([], NodeIsVirgin, _) ->
18721872
"current state"),
18731873
ok
18741874
end;
1875-
sync_cluster_v1(Nodes, _, Timeout) ->
1875+
sync_cluster_v1(Nodes, true = _NodeIsVirgin, Timeout) ->
1876+
[Node | _] = Nodes,
1877+
rabbit_log_feature_flags:debug(
1878+
"Feature flags: marking feature flags enabled remotely as enabled "
1879+
"locally because this node is virgin; using ~s as the remote node",
1880+
[Node]),
1881+
?assertNotEqual(node(), Node),
1882+
Ret1 = rpc:call(Node, ?MODULE, list, [enabled], Timeout),
1883+
case Ret1 of
1884+
FeatureFlags when is_map(FeatureFlags) ->
1885+
FeatureNames = lists:sort(maps:keys(FeatureFlags)),
1886+
rabbit_log_feature_flags:error(
1887+
"Feature flags: list of feature flags to automatically mark as "
1888+
"enabled on this virgin node: ~0p",
1889+
[FeatureNames]),
1890+
Ret2 =
1891+
lists:foldl(
1892+
fun
1893+
(FeatureName, ok) ->
1894+
case is_supported_locally(FeatureName) of
1895+
true -> mark_as_enabled_locally(FeatureName, true);
1896+
false -> ok
1897+
end;
1898+
(_, Acc) ->
1899+
Acc
1900+
end, ok, FeatureNames),
1901+
case Ret2 of
1902+
ok -> sync_cluster_v1(Nodes, false, Timeout);
1903+
_ -> Ret2
1904+
end;
1905+
{badrpc, _} = Reason ->
1906+
rabbit_log_feature_flags:error(
1907+
"Feature flags: failed to query remotely enabled feature flags "
1908+
"on node ~s: ~p",
1909+
[Node, Reason]),
1910+
{error, Reason}
1911+
end;
1912+
sync_cluster_v1(Nodes, _NodeIsVirgin, Timeout) ->
18761913
case sync_feature_flags_v2_first(Nodes, Timeout) of
18771914
true ->
18781915
?LOG_DEBUG(

0 commit comments

Comments
 (0)