diff --git a/src/ejabberd_cluster.erl b/src/ejabberd_cluster.erl index 3db8dd29d..190e35202 100644 --- a/src/ejabberd_cluster.erl +++ b/src/ejabberd_cluster.erl @@ -21,8 +21,8 @@ -define(HASHTBL, nodes_hash). -define(HASHTBL_NEW, nodes_hash_new). --define(POINTS, 16). --define(REHASH_TIMEOUT, 5000). +-define(POINTS, 64). +-define(REHASH_TIMEOUT, 30000). -record(state, {}). diff --git a/src/p1_fsm.erl b/src/p1_fsm.erl index 9ca924112..0d9d7f134 100644 --- a/src/p1_fsm.erl +++ b/src/p1_fsm.erl @@ -555,7 +555,15 @@ handle_msg(Msg, Parent, Name, StateName, StateData, Mod, _Time, loop(Parent, Name, NStateName, NStateData, Mod, Time1, [], Limits, Queue, QueueLen); {migrate, NStateData, {Node, M, F, A}, Time1} -> - Reason = case catch rpc:call(Node, M, F, A, 5000) of + RPCTimeout = if Time1 == 0 -> + %% We don't care about a delay, + %% so we set it one minute + 60000; + true -> + Time1 + end, + Now = now(), + Reason = case catch rpc:call(Node, M, F, A, RPCTimeout) of {badrpc, _} = Err -> {migration_error, Err}; {'EXIT', _} = Err -> @@ -565,7 +573,9 @@ handle_msg(Msg, Parent, Name, StateName, StateData, Mod, _Time, {ok, Clone} -> process_flag(trap_exit, true), MRef = erlang:monitor(process, Clone), - TRef = erlang:start_timer(Time1, self(), timeout), + NowDiff = timer:now_diff(now(), Now), + TimeLeft = lists:max([Time1 - NowDiff, 0]) div 1000, + TRef = erlang:start_timer(TimeLeft, self(), timeout), relay_messages(MRef, TRef, Clone, Queue); Reply -> {migration_error, {bad_reply, Reply}} @@ -608,7 +618,15 @@ handle_msg(Msg, Parent, Name, StateName, StateData, loop(Parent, Name, NStateName, NStateData, Mod, Time1, Debug1, Limits, Queue, QueueLen); {migrate, NStateData, {Node, M, F, A}, Time1} -> - Reason = case catch rpc:call(Node, M, F, A, Time1) of + RPCTimeout = if Time1 == 0 -> + %% We don't care about a delay, + %% so we set it one minute + 60000; + true -> + Time1 + end, + Now = now(), + Reason = case catch rpc:call(Node, M, F, A, RPCTimeout) of {badrpc, R} -> {migration_error, R}; {'EXIT', R} -> @@ -618,7 +636,9 @@ handle_msg(Msg, Parent, Name, StateName, StateData, {ok, Clone} -> process_flag(trap_exit, true), MRef = erlang:monitor(process, Clone), - TRef = erlang:start_timer(Time1, self(), timeout), + NowDiff = timer:now_diff(now(), Now), + TimeLeft = lists:max([Time1 - NowDiff, 0]) div 1000, + TRef = erlang:start_timer(TimeLeft, self(), timeout), relay_messages(MRef, TRef, Clone, Queue); Reply -> {migration_error, {bad_reply, Reply}}