Hacky implementation of takeover/abdicate.
Will do this a bit differently when a local realm_man dummy is written.
This commit is contained in:
parent
44d3bb37fc
commit
b54ce9fcbd
@ -172,7 +172,6 @@
|
|||||||
{meta = none :: none | zx:package_meta(),
|
{meta = none :: none | zx:package_meta(),
|
||||||
home = none :: none | file:filename(),
|
home = none :: none | file:filename(),
|
||||||
argv = none :: none | [string()],
|
argv = none :: none | [string()],
|
||||||
sys_conf = zx_sys_conf:load() :: zx_sys_conf:data(),
|
|
||||||
id = 0 :: id(),
|
id = 0 :: id(),
|
||||||
actions = [] :: [request()],
|
actions = [] :: [request()],
|
||||||
requests = maps:new() :: requests(),
|
requests = maps:new() :: requests(),
|
||||||
@ -189,6 +188,7 @@
|
|||||||
|
|
||||||
-record(rmeta,
|
-record(rmeta,
|
||||||
{serial = 0 :: non_neg_integer(),
|
{serial = 0 :: non_neg_integer(),
|
||||||
|
retries = 0 :: non_neg_integer(),
|
||||||
prime = {"zomp.tsuriai.jp", 11311} :: zx:host(),
|
prime = {"zomp.tsuriai.jp", 11311} :: zx:host(),
|
||||||
private = [] :: [zx:host()],
|
private = [] :: [zx:host()],
|
||||||
mirrors = queue:new() :: queue:queue(zx:host()),
|
mirrors = queue:new() :: queue:queue(zx:host()),
|
||||||
@ -607,6 +607,7 @@ start_link() ->
|
|||||||
%% TODO: Implement lockfile checking and master lock acquisition.
|
%% TODO: Implement lockfile checking and master lock acquisition.
|
||||||
|
|
||||||
init(none) ->
|
init(none) ->
|
||||||
|
put(zx_sys_conf, zx_sys_conf:load()),
|
||||||
{ok, #s{}}.
|
{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.
|
%% 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
|
%% 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.
|
%% 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}) ->
|
init_connections(State = #s{mx = MX, cx = CX}) ->
|
||||||
Realms = cx_realms(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}.
|
State#s{mx = NewMX, cx = NewCX}.
|
||||||
|
|
||||||
|
|
||||||
@ -1532,8 +1538,10 @@ cx_populate(Realm, CX) ->
|
|||||||
|
|
||||||
cx_load_realm_meta(Meta) ->
|
cx_load_realm_meta(Meta) ->
|
||||||
Realm = maps:get(realm, Meta),
|
Realm = maps:get(realm, Meta),
|
||||||
|
Retries = zx_sys_conf:retries(get(zx_sys_conf)),
|
||||||
Basic =
|
Basic =
|
||||||
#rmeta{prime = maps:get(prime, Meta),
|
#rmeta{retries = Retries,
|
||||||
|
prime = maps:get(prime, Meta),
|
||||||
sysop = maps:get(sysop, Meta),
|
sysop = maps:get(sysop, Meta),
|
||||||
key = maps:get(key, Meta)},
|
key = maps:get(key, Meta)},
|
||||||
cx_load_cache(Realm, Basic).
|
cx_load_cache(Realm, Basic).
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
%%% an answer and updates the state accordingly.
|
%%% an answer and updates the state accordingly.
|
||||||
%%%
|
%%%
|
||||||
%%% Bad configuration data causes a reset to defaults so that the system can function.
|
%%% 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
|
%%% @end
|
||||||
|
|
||||||
-module(zx_sys_conf).
|
-module(zx_sys_conf).
|
||||||
@ -36,7 +38,7 @@
|
|||||||
|
|
||||||
-record(d,
|
-record(d,
|
||||||
{timeout = 5 :: pos_integer(),
|
{timeout = 5 :: pos_integer(),
|
||||||
retries = {3, 3} :: non_neg_integer(),
|
retries = 3 :: non_neg_integer(),
|
||||||
maxconn = 5 :: pos_integer(),
|
maxconn = 5 :: pos_integer(),
|
||||||
managed = sets:new() :: sets:set(zx:realm()),
|
managed = sets:new() :: sets:set(zx:realm()),
|
||||||
mirrors = [] :: [zx:host()]}).
|
mirrors = [] :: [zx:host()]}).
|
||||||
@ -75,8 +77,8 @@ populate_data(List) ->
|
|||||||
end,
|
end,
|
||||||
Retries =
|
Retries =
|
||||||
case proplists:get_value(retries, List, 3) of
|
case proplists:get_value(retries, List, 3) of
|
||||||
RT when is_integer(RT) and RT > 0 -> {RT, RT};
|
RT when is_integer(RT) and RT > 0 -> RT;
|
||||||
_ -> {3, 3}
|
_ -> 3
|
||||||
end,
|
end,
|
||||||
MaxConn =
|
MaxConn =
|
||||||
case proplists:get_value(maxconn, List, 5) of
|
case proplists:get_value(maxconn, List, 5) of
|
||||||
@ -105,7 +107,7 @@ populate_data(List) ->
|
|||||||
%% Save the current etc/sys.conf to disk.
|
%% Save the current etc/sys.conf to disk.
|
||||||
|
|
||||||
save(#d{timeout = Timeout,
|
save(#d{timeout = Timeout,
|
||||||
retries = {_, Retries},
|
retries = Retries,
|
||||||
maxconn = MaxConn,
|
maxconn = MaxConn,
|
||||||
managed = Managed,
|
managed = Managed,
|
||||||
mirrors = Mirrors}) ->
|
mirrors = Mirrors}) ->
|
||||||
@ -134,8 +136,7 @@ timeout(#d{timeout = Timeout}) ->
|
|||||||
%% @doc
|
%% @doc
|
||||||
%% Set the timeout attribute to a new value.
|
%% Set the timeout attribute to a new value.
|
||||||
|
|
||||||
timeout(Value, Data)
|
timeout(Value, Data) when is_integer(Value) and Value > 0 ->
|
||||||
when is_integer(Value) and Value > 0 ->
|
|
||||||
Data#d{timeout = Value}.
|
Data#d{timeout = Value}.
|
||||||
|
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ timeout(Value, Data)
|
|||||||
%% @doc
|
%% @doc
|
||||||
%% Return the retries value.
|
%% Return the retries value.
|
||||||
|
|
||||||
retries(#d{retries = {_, Retries}}) ->
|
retries(#d{retries = Retries}) ->
|
||||||
Retries.
|
Retries.
|
||||||
|
|
||||||
|
|
||||||
@ -154,9 +155,8 @@ retries(#d{retries = {_, Retries}}) ->
|
|||||||
%% @doc
|
%% @doc
|
||||||
%% Set the retries attribute to a new value.
|
%% Set the retries attribute to a new value.
|
||||||
|
|
||||||
retries(Value, Data = #d{retries = {Remaining, _}})
|
retries(Value, Data) when Value > 0 ->
|
||||||
when is_integer(Value) and Value >= 0 ->
|
Data#d{retries = Value}.
|
||||||
Data#d{retries = {Remaining, Value}}.
|
|
||||||
|
|
||||||
|
|
||||||
-spec retry(Data) -> Result
|
-spec retry(Data) -> Result
|
||||||
@ -199,8 +199,7 @@ maxconn(#d{maxconn = MaxConn}) ->
|
|||||||
%% @doc
|
%% @doc
|
||||||
%% Set the value of maxconn.
|
%% Set the value of maxconn.
|
||||||
|
|
||||||
maxconn(Value, Data)
|
maxconn(Value, Data) when is_integer(Value) and Value > 0 ->
|
||||||
when is_integer(Value) and Value > 0 ->
|
|
||||||
Data#d{maxconn = Value}.
|
Data#d{maxconn = Value}.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user