我在这里有一个奇怪的问题(我想)
我在应用程序中使用哨兵以及更改主实例时最主要的事情-我正在打开与实际实例的新连接(一切正常)。
还有我无法获得关闭连接到从属实例的连接的良方法的问题
实际上,当我收到诸如 <<“ READONLY您不能针对只读slave进行写操作”之类的消息时,我可以关闭连接。>>
但是如果我有1500个连接池,它可能会关闭几分钟(p:s我每5秒检查一次健康情况)
还有其他(更快)的解决方案吗?
这是我的代码的一部分:
sentinel_controller.erl
handle_info(check_master_instance, #state{
interval = Interval,
name = CtrlName,
connected_sentinels = Conns,
master_instance_name = MasterName} = State) ->
_ = utils:c_tref(State#state.tref_check_master),
Masters = get_masters(Conns, MasterName, CtrlName),
NewState =
case get_actually_master(Masters) of
{ok, MasterInstancePeer} ->
check_pools(MasterInstancePeer, State);
Error ->
?LOG_WARNING("{Sentinel Controller} Error got MasterPeer with reason: ~p~n", [Error]),
TimerCheckMaster = erlang:send_after(Interval, self(), check_master_instance),
State#state{tref_check_master = TimerCheckMaster}
end,
{noreply, NewState};
check_pools(MasterInstance, #state{
interval = Interval,
pool_conf = PoolConf,
name = ProcsTab,
pool_started = false} = State) ->
try
ok = redis_pool_sup:start_pool(ProcsTab, PoolConf),
TimerCheckMaster = erlang:send_after(Interval, self(), check_master_instance),
State#state{tref_check_master = TimerCheckMaster, pool_started = true, master_instance_peer = MasterInstance}
catch _:_ ->
?LOG_WARNING("error started pool Reason: ~p; Master instance: ~p~n", [erlang:get_stacktrace(), MasterInstance]),
State
end;
check_pools(NewMasterInstance, #state{
pool_started = true,
interval = Interval} = State) ->
TimerCheckMaster = erlang:send_after(Interval, self(), check_master_instance),
State#state{tref_check_master = TimerCheckMaster, pool_started = true, master_instance_peer = NewMasterInstance}.
如果您需要其他片段,请告诉我
提前thnx