Hacky implementation of takeover/abdicate.

Will do this a bit differently when a local realm_man dummy is written.
This commit is contained in:
Craig Everett 2018-06-05 23:10:08 +09:00
parent 44d3bb37fc
commit b54ce9fcbd
2 changed files with 24 additions and 17 deletions

View File

@ -172,7 +172,6 @@
{meta = none :: none | zx:package_meta(),
home = none :: none | file:filename(),
argv = none :: none | [string()],
sys_conf = zx_sys_conf:load() :: zx_sys_conf:data(),
id = 0 :: id(),
actions = [] :: [request()],
requests = maps:new() :: requests(),
@ -189,6 +188,7 @@
-record(rmeta,
{serial = 0 :: non_neg_integer(),
retries = 0 :: non_neg_integer(),
prime = {"zomp.tsuriai.jp", 11311} :: zx:host(),
private = [] :: [zx:host()],
mirrors = queue:new() :: queue:queue(zx:host()),
@ -607,6 +607,7 @@ start_link() ->
%% TODO: Implement lockfile checking and master lock acquisition.
init(none) ->
put(zx_sys_conf, zx_sys_conf:load()),
{ok, #s{}}.
@ -884,10 +885,15 @@ dequeue(Pending) ->
%% return a populated MX and CX to the caller. Should only ever be called by init/1.
%% Returns an `ok' tuple to disambiguate it from pure functions *and* to leave an
%% obvious place to populate error returns in the future if desired.
%%
%%TODO: This is a hack to make things feel managedish. They aren't.
%% A local manager process needs to exist if an actual Zomp node doesn't.
init_connections(State = #s{mx = MX, cx = CX}) ->
Realms = cx_realms(CX),
{ok, NewMX, NewCX} = init_connections(Realms, MX, CX),
Managed = zx_sys_conf:managed(get(zx_sys_conf)),
Unmanaged = lists:subtract(Realms, Managed),
{ok, NewMX, NewCX} = init_connections(Unmanaged, MX, CX),
State#s{mx = NewMX, cx = NewCX}.
@ -1532,8 +1538,10 @@ cx_populate(Realm, CX) ->
cx_load_realm_meta(Meta) ->
Realm = maps:get(realm, Meta),
Retries = zx_sys_conf:retries(get(zx_sys_conf)),
Basic =
#rmeta{prime = maps:get(prime, Meta),
#rmeta{retries = Retries,
prime = maps:get(prime, Meta),
sysop = maps:get(sysop, Meta),
key = maps:get(key, Meta)},
cx_load_cache(Realm, Basic).

View File

@ -11,6 +11,8 @@
%%% an answer and updates the state accordingly.
%%%
%%% Bad configuration data causes a reset to defaults so that the system can function.
%%%
%%% TODO: Change this to a gen_server that just babysits the config data.
%%% @end
-module(zx_sys_conf).
@ -36,7 +38,7 @@
-record(d,
{timeout = 5 :: pos_integer(),
retries = {3, 3} :: non_neg_integer(),
retries = 3 :: non_neg_integer(),
maxconn = 5 :: pos_integer(),
managed = sets:new() :: sets:set(zx:realm()),
mirrors = [] :: [zx:host()]}).
@ -75,8 +77,8 @@ populate_data(List) ->
end,
Retries =
case proplists:get_value(retries, List, 3) of
RT when is_integer(RT) and RT > 0 -> {RT, RT};
_ -> {3, 3}
RT when is_integer(RT) and RT > 0 -> RT;
_ -> 3
end,
MaxConn =
case proplists:get_value(maxconn, List, 5) of
@ -105,7 +107,7 @@ populate_data(List) ->
%% Save the current etc/sys.conf to disk.
save(#d{timeout = Timeout,
retries = {_, Retries},
retries = Retries,
maxconn = MaxConn,
managed = Managed,
mirrors = Mirrors}) ->
@ -134,8 +136,7 @@ timeout(#d{timeout = Timeout}) ->
%% @doc
%% Set the timeout attribute to a new value.
timeout(Value, Data)
when is_integer(Value) and Value > 0 ->
timeout(Value, Data) when is_integer(Value) and Value > 0 ->
Data#d{timeout = Value}.
@ -143,7 +144,7 @@ timeout(Value, Data)
%% @doc
%% Return the retries value.
retries(#d{retries = {_, Retries}}) ->
retries(#d{retries = Retries}) ->
Retries.
@ -154,9 +155,8 @@ retries(#d{retries = {_, Retries}}) ->
%% @doc
%% Set the retries attribute to a new value.
retries(Value, Data = #d{retries = {Remaining, _}})
when is_integer(Value) and Value >= 0 ->
Data#d{retries = {Remaining, Value}}.
retries(Value, Data) when Value > 0 ->
Data#d{retries = Value}.
-spec retry(Data) -> Result
@ -199,8 +199,7 @@ maxconn(#d{maxconn = MaxConn}) ->
%% @doc
%% Set the value of maxconn.
maxconn(Value, Data)
when is_integer(Value) and Value > 0 ->
maxconn(Value, Data) when is_integer(Value) and Value > 0 ->
Data#d{maxconn = Value}.