Merge pull request #11112 from zmstone/0621-fix-conf-sync-release-version-detect

fix(emqx_conf_app): fix release version detect during cluster conf sync
This commit is contained in:
Zaiming (Stone) Shi 2023-06-21 10:15:12 +02:00 committed by GitHub
commit 1efeb56974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 12 deletions

View File

@ -134,7 +134,7 @@ sync_cluster_conf2(Nodes) ->
msg => "ignored_nodes_when_sync_cluster_conf"
},
?SLOG(warning, Warning);
true ->
true when Failed =/= [] ->
%% There are core nodes running but no one was able to reply.
?SLOG(error, #{
msg => "failed_to_sync_cluster_conf",
@ -142,6 +142,14 @@ sync_cluster_conf2(Nodes) ->
failed => Failed,
not_ready => NotReady
});
true ->
%% There are core nodes booting up
?SLOG(info, #{
msg => "peer_not_ready_for_config_sync",
reason => "The 'not_ready' peer node(s) are loading configs",
nodes => Nodes,
not_ready => NotReady
});
false ->
ok
end,
@ -180,17 +188,7 @@ sync_cluster_conf2(Nodes) ->
%% @private Filter out the nodes which are running a newer version than this node.
sync_cluster_conf3(Ready) ->
NotNewer = fun({ok, #{release := RemoteRelease}}) ->
try
emqx_release:vsn_compare(RemoteRelease) =/= newer
catch
_:_ ->
%% If the version is not valid (without v or e prefix),
%% we know it's older than v5.1.0/e5.1.0
true
end
end,
case lists:filter(NotNewer, Ready) of
case lists:filter(fun is_older_or_same_version/1, Ready) of
[] ->
%% All available core nodes are running a newer version than this node.
%% Start this node without syncing cluster config from them.
@ -213,6 +211,19 @@ sync_cluster_conf3(Ready) ->
sync_cluster_conf4(Ready2)
end.
is_older_or_same_version({ok, #{release := RemoteRelease}}) ->
try
emqx_release:vsn_compare(RemoteRelease) =/= newer
catch
_:_ ->
%% If the version is not valid (without v or e prefix),
%% we know it's older than v5.1.0/e5.1.0
true
end;
is_older_or_same_version(_) ->
%% older version has no 'release' field
true.
%% @private Some core nodes are running and replied with their configs successfully.
%% Try to sort the results and save the first one for local use.
sync_cluster_conf4(Ready) ->