Skip to content

Commit

Permalink
Refactor fetch rumor on pre sync
Browse files Browse the repository at this point in the history
  • Loading branch information
systream committed May 2, 2023
1 parent 99e0bf0 commit 5c5a34e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/simple_gossip_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,26 @@ fetch_gossip(Nodes, StoredRumor) ->
{ok, NewRumor} when NewRumor#rumor.gossip_version > StoredRumor#rumor.gossip_version ->
?LOG_INFO("PreSync rumor from ~p gossip vsn: ~p", [Node, NewRumor#rumor.gossip_version]),
simple_gossip_rumor:check_node_exclude(NewRumor);
{ok, NewRumor} when NewRumor#rumor.gossip_version =< StoredRumor#rumor.gossip_version ->
?LOG_INFO("Cannot get fresh gossip From ~p Reason: older gossip vsn ~p > ~p",
[Node, NewRumor#rumor.gossip_version, StoredRumor#rumor.gossip_version]),
maybe_fetch_gossip(Nodes -- [Node], StoredRumor);
Else ->
?LOG_WARNING("Cannot get fresh gossip From ~p Reason: ~p", [Node, Else]),
case Nodes -- [Node] of
[] ->
?LOG_WARNING("No more nodes available for pre syncing rumor, using localy stored"),
StoredRumor;
NewNodes ->
fetch_gossip(NewNodes, StoredRumor)
end
maybe_fetch_gossip(Nodes -- [Node], StoredRumor)
end;
_ ->
% from nowhere to sync
StoredRumor
end.

-spec maybe_fetch_gossip([node()], rumor()) -> rumor().
maybe_fetch_gossip([], StoredRumor) ->
?LOG_WARNING("No more nodes available for pre syncing rumor, using localy stored"),
StoredRumor;
maybe_fetch_gossip(NewNodes, StoredRumor) ->
fetch_gossip(NewNodes, StoredRumor).

%%--------------------------------------------------------------------
%% @private
%% @doc
Expand Down

0 comments on commit 5c5a34e

Please sign in to comment.