我尝试以分布式方式运行一个简单的应用程序来测试故障转移接管功能但是失败了.
我想要的是:
应用程序myapp_api
使用rest api,它将myapp
应用程序作为依赖项.我想从myapp_api
3个节点开始,我希望整个应用程序(myapp_api
+ myapp
)只能同时在一个节点上工作.
怎么了:
主app(myapp_api
)按预期工作:仅在具有故障转移和接管的一个节点上.但由于某些原因,依赖myapp
总是从每个节点开始.我希望它只能同时在一个节点上工作.
我所做的:
我以第一个节点的配置为例.
[
{kernel,
[{distributed, [{myapp_api,
1000,
['n1@myhost', {'n2@myhost', 'n3@myhost'}]}]},
{sync_nodes_optional, ['n2@myhost', 'n3@myhost']},
{sync_nodes_timeout, 5000}
]}
].
Run Code Online (Sandbox Code Playgroud)
我erl -sname nI -config nI.config -pa apps/*/ebin deps/*/ebin -s myapp_api
在每个节点打电话
.
我在go-swagger包中找到了这种验证.
// Required validates an interface for requiredness
func Required(path, in string, data interface{}) *errors.Validation {
val := reflect.ValueOf(data)
if reflect.DeepEqual(reflect.Zero(val.Type()), val) {
return errors.Required(path, in)
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
我试图使用它,这迫使我做了一些想法.
为什么以下不是真实的陈述?
exper := int32(0)
reflect.DeepEqual(
reflect.Zero(reflect.ValueOf(exper).Type()),
reflect.ValueOf(exper)
)
Run Code Online (Sandbox Code Playgroud) 我有两个gen_server模块.
第一个serv.erl
-module(serv).
-behaviour(gen_server).
-export([init/1,
handle_call/3,
handle_cast/2,
handle_info/2,
code_change/3,
terminate/2,
start_link/0
]).
start_link() ->
gen_server:start_link(?MODULE, [], []).
init([]) ->
process_flag(trap_exit, true),
spawn_link(user, start_link,[]),
{ok, []}.
handle_call(_E, _From, State) ->
{noreply, State}.
handle_cast(_Message, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
handle_info(Message, State) ->
{noreply, State}.
code_change(_OldVersion, State, _Extra) ->
{ok, State}.
Run Code Online (Sandbox Code Playgroud)
和user.erl(除了init/1完全相同):
init([]) ->
{ok, []}.
Run Code Online (Sandbox Code Playgroud)
我以为服务器会永远存在.如果第一台服务器死了,另一台服务器会收到{'EXIT',Pid,Reason}消息.
但是如果你通过serv:start_link()启动模块,用户模块将在启动后立即退出,并显示消息{'EXIT',Pid,normal}.为什么用户会死?