fix: bpapi undef on old node

This commit is contained in:
zhongwencool 2024-03-22 17:02:09 +08:00
parent dda630ccbd
commit 45eedbb9c6
1 changed files with 28 additions and 1 deletions

View File

@ -86,7 +86,34 @@ supported_version(API) ->
-spec announce(node(), atom()) -> ok.
announce(Node, App) ->
{ok, Data} = file:consult(?MODULE:versions_file(App)),
{atomic, ok} = mria:transaction(?COMMON_SHARD, fun ?MODULE:announce_fun/2, [Node, Data]),
%% replicant(5.6.0) will call old core(<5.6.0) announce_fun/2 is undef on old core
%% so we just use anonymous function to update.
try
{atomic, ok} = mria:transaction(?COMMON_SHARD, fun ?MODULE:announce_fun/2, [Node, Data])
catch
error:undef ->
{atomic, ok} = mria:transaction(
?COMMON_SHARD,
fun() ->
MS = ets:fun2ms(fun(#?TAB{key = {N, API}}) when N =:= Node ->
{N, API}
end),
OldKeys = mnesia:select(?TAB, MS, write),
_ = [
mnesia:delete({?TAB, Key})
|| Key <- OldKeys
],
%% Insert new records:
_ = [
mnesia:write(#?TAB{key = {Node, API}, version = Version})
|| {API, Version} <- Data
],
%% Update maximum supported version:
_ = [update_minimum(API) || {API, _} <- Data],
ok
end
)
end,
ok.
-spec versions_file(atom()) -> file:filename_all().