我正在尝试构建一个具有以下结构的主管树:
1 个根主管 -> 3 个“级别”主管 -> 每个级别主管都有一个初始化主管 -> X 个工人(现在只有 1 个)
但是由于某种原因,启动第二级主管会使整个树终止,如果我只启动 1 个根 -> 1 个级别 -> 1 个初始化 -> 1 个工作人员(或更多工作人员),那很好,但是一旦我尝试添加更多监督树终止。
-module(otp_supervisor).
-behavior(supervisor).
-export([start_cell/1]).
-export([init/1]).
start_cell(root) ->
supervisor:start_link({local, root}, ?MODULE, [root]);
start_cell({Type, Role}) ->
supervisor:start_link({local, Type}, ?MODULE, [{Type, Role}]).
init([root]) ->
init_root(one_for_one, 3, 60);
init([{level, Param}]) ->
init_level(one_for_one, 3, 60, {member, Param});
init([{member, Param}]) ->
init_member(one_for_one, 3, 60, Param).
init_root(RestartStrategy, MaxRestart, MaxTime) ->
io:format("~p ~s: Spawning...~n", [self(), root_supervisor]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{olevel,
{otp_supervisor, start_cell, [{level, overseer}]},
permanent, 1000, supervisor, [otp_supervisor]
},
{slevel,
{otp_supervisor, start_cell, [{level, supervisor}]},
permanent, 1000, supervisor, [otp_supervisor]
},
{wlevel,
{otp_supervisor, start_cell, [{level, worker}]},
permanent, 1000, supervisor, [otp_supervisor]
}
]
}
}.
init_level(RestartStrategy, MaxRestart, MaxTime, {member, overseer}) ->
io:format("~p ~s: Spawning...~n", [self(), overseer_level_supervisor]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{oinit,
{otp_supervisor, start_cell, [{member, overseer}]},
permanent, 1000, supervisor, [otp_supervisor]}
]
}
};
init_level(RestartStrategy, MaxRestart, MaxTime, {member, supervisor}) ->
io:format("~p ~s: Spawning...~n", [self(), supervisor_level_supervisor]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{sinit,
{otp_supervisor, start_cell, [{member, supervisor}]},
permanent, 1000, supervisor, [otp_supervisor]}
]
}
};
init_level(RestartStrategy, MaxRestart, MaxTime, {member, worker}) ->
io:format("~p ~s: Spawning...~n", [self(), worker_level_supervisor]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{winit,
{otp_supervisor, start_cell, [{member, worker}]},
permanent, 1000, supervisor, [otp_supervisor]}
]
}
}.
init_member(RestartStrategy, MaxRestart, MaxTime, overseer) ->
io:format("~p ~s: Spawning...~n", [self(), init_overseer]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{ol_core,
{aux_datasocket, start, [ol_overseer1]},
permanent, 1000, worker, [aux_datasocket]
}
]
}
};
init_member(RestartStrategy, MaxRestart, MaxTime, supervisor) ->
io:format("~p ~s: Spawning...~n", [self(), init_supervisor]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{sl_core,
{aux_datasocket, start, [sl_overseer1]},
permanent, 1000, worker, [aux_datasocket]
}
]
}
};
init_member(RestartStrategy, MaxRestart, MaxTime, worker) ->
io:format("~p ~s: Spawning...~n", [self(), init_worker]),
{ok, {
{RestartStrategy, MaxRestart, MaxTime},
[
{wl_core,
{aux_datasocket, start, [wl_overseer1]},
permanent, 1000, worker, [aux_datasocket]
}
]
}
}.
aux_datasocket 模块是一个非常简单的 gen_server ,它本身工作得很好(因为它现在除了启动 gen_server 什么都不做)所以我很肯定错误不在于该模块。