New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EMQX-9101 mnesia unregister hook #133
EMQX-9101 mnesia unregister hook #133
Conversation
These OTP versions implement mnesia_hook:unregister_hook/1
Closes: EMQX-9101
be97073
to
bb65dc0
Compare
@@ -38,6 +38,7 @@ start(_Type, _Args) -> | |||
mria_sup:start_link(). | |||
|
|||
stop(_State) -> | |||
mria_rlog:cleanup(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Is this stop function called before or after application controller shuts down the supervisor?
I think we need to unregister hook while the rlog_server
processes are still running to avoid error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called after supervision tree is shutdown.
Initially I've added it to prep_stop/1
callback, but than thought that it might be too early to un-register it before all the app processes are shutdown..
A naive test shows that un-registering the hook in application stop/1
callback is enough to fix the crashes upon restarting mria:
$ . ~/kerl/25.1.2-3-emqx/activate
$ make clean
$ PROFILE=emqx-enterprise make emqx-enterprise
$ _build/emqx-enterprise/rel/emqx/bin/emqx console_clean
(search)`ensure': application:ensure_all_started(mria).
{ok,[inets,crypto,asn1,public_key,ssl,gen_rpc,replayq,
snabbkaffe,optvar,mria]}
(emqx@127.0.0.1)2>
(emqx@127.0.0.1)2>
(search)`mria:st': mria:stop(),application:ensure_all_started(mria).
2023-03-22T12:48:39.983144+02:00 [warning] msg: Stopping mria, mfa: mria:stop/1, line: 130, reason: stop
{ok,[mria]}
(emqx@127.0.0.1)3> mria:stop(),application:ensure_all_started(mria).
2023-03-22T12:48:42.148922+02:00 [warning] msg: Stopping mria, mfa: mria:stop/1, line: 130, reason: stop
{ok,[mria]}
(emqx@127.0.0.1)4> mria:stop(),application:ensure_all_started(mria).
2023-03-22T12:48:42.892593+02:00 [warning] msg: Stopping mria, mfa: mria:stop/1, line: 130, reason: stop
{ok,[mria]}
(emqx@127.0.0.1)5> mria:stop(),application:ensure_all_started(mria).
2023-03-22T12:48:43.474105+02:00 [warning] msg: Stopping mria, mfa: mria:stop/1, line: 130, reason: stop
{ok,[mria]}
The same test with the previous OTP (without un-registering):
$ kerl_deactivate
$ . ~/kerl/25.1.2-2-emqx/activate
$ make clean
$ PROFILE=emqx-enterprise make emqx-enterprise
$ _build/emqx-enterprise/rel/emqx/bin/emqx console_clean
(search)`mria': application:ensure_all_started(mria).
{ok,[inets,crypto,asn1,public_key,ssl,gen_rpc,replayq,
snabbkaffe,optvar,mria]}
(emqx@127.0.0.1)2>
(emqx@127.0.0.1)2>
(emqx@127.0.0.1)2>
(emqx@127.0.0.1)2>
(search)`mria:st': mria:stop(),application:ensure_all_started(mria).
2023-03-22T12:52:29.959562+02:00 [warning] msg: Stopping mria, mfa: mria:stop/1, line: 130, reason: stop
2023-03-22T12:52:30.015153+02:00 [error] Mnesia('emqx@127.0.0.1'): ** ERROR ** Mnesia post_commit hook failed: error:badarg, Stacktrace:[{erlang,send,['$mria_meta_shard',{trans,{tid,13,<0.2267.0>},#{disc_copies => [],disc_only_copies => [],ext => [],node => 'emqx@127.0.0.1',ram_copies => [{{mria_schema,mria_schema},{mria_schema,mria_schema,'$mria_meta_shard',ram_copies,[{type,ordered_set},{record_name,mria_schema},{attributes,[mnesia_table,shard,storage,config]}]},write}],schema_ops => []}}],[{error_info,#{module => erl_erts_errors}}]},{mria_rlog_server,dispatch,3,[{file,"mria_rlog_server.erl"},{line,105}]},{mnesia_hook,do_post_commit,2,[{file,"mnesia_hook.erl"},{line,69}]},{mnesia_tm,do_commit,3,[{file,"mnesia_tm.erl"},{line,1788}]},{mnesia_tm,multi_commit,5,[{file,"mnesia_tm.erl"},{line,1422}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,843}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,818}]},{mria_schema,boostrap,0,[{file,"mria_schema.erl"},{line,335}]}]
{ok,[mria]}
(emqx@127.0.0.1)3>
(emqx@127.0.0.1)3> mria:stop(),application:ensure_all_started(mria).
2023-03-22T12:52:31.244164+02:00 [warning] msg: Stopping mria, mfa: mria:stop/1, line: 130, reason: stop
2023-03-22T12:52:31.303299+02:00 [error] Mnesia('emqx@127.0.0.1'): ** ERROR ** Mnesia post_commit hook failed: error:badarg, Stacktrace:[{erlang,send,['$mria_meta_shard',{trans,{tid,14,<0.2328.0>},#{disc_copies => [],disc_only_copies => [],ext => [],node => 'emqx@127.0.0.1',ram_copies => [{{mria_schema,mria_schema},{mria_schema,mria_schema,'$mria_meta_shard',ram_copies,[{type,ordered_set},{record_name,mria_schema},{attributes,[mnesia_table,shard,storage,config]}]},write}],schema_ops => []}}],[{error_info,#{module => erl_erts_errors}}]},{mria_rlog_server,dispatch,3,[{file,"mria_rlog_server.erl"},{line,105}]},{mnesia_hook,do_post_commit,2,[{file,"mnesia_hook.erl"},{line,69}]},{mnesia_tm,do_commit,3,[{file,"mnesia_tm.erl"},{line,1788}]},{mnesia_tm,multi_commit,5,[{file,"mnesia_tm.erl"},{line,1422}]},{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,843}]},{mnesia_tm,execute_transaction,5,[{file,"mnesia_tm.erl"},{line,818}]},{mria_schema,boostrap,0,[{file,"mria_schema.erl"},{line,335}]}]
{ok,[mria]}
No description provided.