mirror of
https://github.com/processone/ejabberd.git
synced 2024-07-06 23:22:36 +02:00
Add new options: migrate_timeout and rehash_timeout
This commit is contained in:
parent
290432c0ee
commit
e30e7686e3
|
@ -12,7 +12,7 @@
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0, get_node/1, get_node_new/1, announce/1, shutdown/0,
|
-export([start_link/0, get_node/1, get_node_new/1, announce/1, shutdown/0,
|
||||||
node_id/0, get_node_by_id/1, get_nodes/0, rehash_timeout/0, start/0,
|
node_id/0, get_node_by_id/1, get_nodes/0, rehash_timeout/0, start/0,
|
||||||
shutdown_migrate/1]).
|
shutdown_migrate/1, migrate_timeout/0]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
|
@ -25,8 +25,6 @@
|
||||||
-define(POINTS, 64).
|
-define(POINTS, 64).
|
||||||
-define(REHASH_TIMEOUT, timer:seconds(30)).
|
-define(REHASH_TIMEOUT, timer:seconds(30)).
|
||||||
-define(MIGRATE_TIMEOUT, timer:minutes(2)).
|
-define(MIGRATE_TIMEOUT, timer:minutes(2)).
|
||||||
%%-define(REHASH_TIMEOUT, timer:seconds(10)).
|
|
||||||
%%-define(MIGRATE_TIMEOUT, timer:seconds(5)).
|
|
||||||
-define(LOCK, {migrate, node()}).
|
-define(LOCK, {migrate, node()}).
|
||||||
|
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
@ -65,7 +63,20 @@ node_id() ->
|
||||||
integer_to_list(erlang:phash2(node())).
|
integer_to_list(erlang:phash2(node())).
|
||||||
|
|
||||||
rehash_timeout() ->
|
rehash_timeout() ->
|
||||||
?REHASH_TIMEOUT.
|
case ejabberd_config:get_local_option(rehash_timeout) of
|
||||||
|
N when is_integer(N), N > 0 ->
|
||||||
|
timer:seconds(N);
|
||||||
|
_ ->
|
||||||
|
?REHASH_TIMEOUT
|
||||||
|
end.
|
||||||
|
|
||||||
|
migrate_timeout() ->
|
||||||
|
case ejabberd_config:get_local_option(migrate_timeout) of
|
||||||
|
N when is_integer(N), N > 0 ->
|
||||||
|
timer:seconds(N);
|
||||||
|
_ ->
|
||||||
|
?MIGRATE_TIMEOUT
|
||||||
|
end.
|
||||||
|
|
||||||
get_node_by_id(NodeID) when is_list(NodeID) ->
|
get_node_by_id(NodeID) when is_list(NodeID) ->
|
||||||
case catch list_to_existing_atom(NodeID) of
|
case catch list_to_existing_atom(NodeID) of
|
||||||
|
@ -153,7 +164,7 @@ handle_call(announce, _From, State) ->
|
||||||
global:del_lock(?LOCK);
|
global:del_lock(?LOCK);
|
||||||
WorkingNodes ->
|
WorkingNodes ->
|
||||||
gen_server:abcast(WorkingNodes, ?MODULE, {node_ready, node()}),
|
gen_server:abcast(WorkingNodes, ?MODULE, {node_ready, node()}),
|
||||||
erlang:send_after(?MIGRATE_TIMEOUT, self(), del_lock)
|
erlang:send_after(migrate_timeout(), self(), del_lock)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
{reply, ok, State};
|
{reply, ok, State};
|
||||||
|
@ -169,7 +180,7 @@ handle_call(_Request, _From, State) ->
|
||||||
handle_cast({node_ready, Node}, State) ->
|
handle_cast({node_ready, Node}, State) ->
|
||||||
?INFO_MSG("adding node ~p to hash and starting migration", [Node]),
|
?INFO_MSG("adding node ~p to hash and starting migration", [Node]),
|
||||||
append_node(?HASHTBL, Node),
|
append_node(?HASHTBL, Node),
|
||||||
ejabberd_hooks:run(node_hash_update, [Node, up, ?MIGRATE_TIMEOUT]),
|
ejabberd_hooks:run(node_hash_update, [Node, up, migrate_timeout()]),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
|
@ -449,6 +449,10 @@ process_term(Term, State) ->
|
||||||
add_option(max_fsm_queue, N, State);
|
add_option(max_fsm_queue, N, State);
|
||||||
{hostname, Host} ->
|
{hostname, Host} ->
|
||||||
add_option(hostname, Host, State);
|
add_option(hostname, Host, State);
|
||||||
|
{rehash_timeout, Secs} ->
|
||||||
|
add_option(rehash_timeout, Secs, State);
|
||||||
|
{migrate_timeout, Secs} ->
|
||||||
|
add_option(migrate_timeout, Secs, State);
|
||||||
{_Opt, _Val} ->
|
{_Opt, _Val} ->
|
||||||
lists:foldl(fun(Host, S) -> process_host_term(Term, Host, S) end,
|
lists:foldl(fun(Host, S) -> process_host_term(Term, Host, S) end,
|
||||||
State, State#state.hosts)
|
State, State#state.hosts)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user