From 439abe430b157e996b7a10f67dc3e11c990fd154 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Tue, 23 Jul 2024 10:50:09 +0800 Subject: [PATCH] refactor: remove relup revert callback functions --- apps/emqx/src/emqx_post_upgrade.erl | 28 ++++++++------- rebar.config.erl | 2 +- .../examples/5.6.1-to-5.6.1+patch.A.relup | 36 +++++++++++-------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/apps/emqx/src/emqx_post_upgrade.erl b/apps/emqx/src/emqx_post_upgrade.erl index 6b09f2a30..900278799 100644 --- a/apps/emqx/src/emqx_post_upgrade.erl +++ b/apps/emqx/src/emqx_post_upgrade.erl @@ -16,23 +16,25 @@ -module(emqx_post_upgrade). +%% Example of a hot upgrade callback function. %% PR#12765 % -export([ % pr12765_update_stats_timer/1, -% pr12765_revert_stats_timer/1 +% pr20000_ensure_sup_started/3 % ]). --include("logger.hrl"). - -%%------------------------------------------------------------------------------ -%% Hot Upgrade Callback Functions. -%%------------------------------------------------------------------------------ +%% Please ensure that every callback function is reentrant. +%% This way, users can attempt upgrade multiple times if an issue arises. +%% % pr12765_update_stats_timer(_FromVsn) -> % emqx_stats:update_interval(broker_stats, fun emqx_broker_helper:stats_fun/0). - -% pr12765_revert_stats_timer(_ToVsn) -> -% emqx_stats:update_interval(broker_stats, fun emqx_broker:stats_fun/0). - -%%------------------------------------------------------------------------------ -%% Helper functions -%%------------------------------------------------------------------------------ +% +% pr20000_ensure_sup_started(_FromVsn, "5.6.1" ++ _, ChildSpec) -> +% ChildId = maps:get(id, ChildSpec), +% case supervisor:terminate_child(emqx_sup, ChildId) of +% ok -> supervisor:delete_child(emqx_sup, ChildId); +% Error -> Error +% end, +% supervisor:start_child(emqx_sup, ChildSpec); +% pr20000_ensure_sup_started(_FromVsn, _TargetVsn, _) -> +% ok. diff --git a/rebar.config.erl b/rebar.config.erl index fcfd2595f..522770f68 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -184,7 +184,7 @@ project_app_excluded("apps/" ++ AppStr, ExcludedApps) -> plugins() -> [ - {emqx_relup, {git, "https://github.com/emqx/emqx-relup.git", {tag, "0.1.0"}}}, + {emqx_relup, {git, "https://github.com/emqx/emqx-relup.git", {tag, "0.1.1"}}}, %% emqx main project does not require port-compiler %% pin at root level for deterministic {pc, "v1.14.0"} diff --git a/rel/relup/examples/5.6.1-to-5.6.1+patch.A.relup b/rel/relup/examples/5.6.1-to-5.6.1+patch.A.relup index 1c833c579..8e2170dda 100644 --- a/rel/relup/examples/5.6.1-to-5.6.1+patch.A.relup +++ b/rel/relup/examples/5.6.1-to-5.6.1+patch.A.relup @@ -8,31 +8,37 @@ %% Note that we do not support the 'apply' command in the 'code_changes' section. %% If any complex operations are needed during the upgrade process, please add %% them in the 'post_upgrade_callbacks' section, and implement them in the -%% 'emqx_post_upgrade' module. +%% 'emqx_post_upgrade' module. We consolidate the hot upgrade callback code into +%% a single module ('emqx_post_upgrade') is to avoid mixing the hot upgrade-related +%% code with the main logic code. + +ChildSpec = fun(Mod) -> + #{ + id => Mod, + start => {Mod, start_link, []}, + restart => permanent, + shutdown => 5000, + type => worker, + modules => [Mod] + } + end. #{ target_version => "5.6.1+patch.A", from_version => "5.6.1", code_changes => + %% the 'emqx_release' and 'emqx_post_upgrade' will be automatically added, + %% no need to include them here [ {load_module, emqx_broker} , {load_module, emqx_metrics} - , {load_module, emqx_persistent_message} - , {load_module, emqx_dashboard_monitor} - , {load_module, emqx_dashboard_monitor_api} - , {load_module, emqx_ds_builtin_metrics} - , {load_module, emqx_ds_storage_bitfield_lts} - , {load_module, emqx_prometheus} - , {load_module, emqx_ds_builtin_db_sup} - , {load_module, emqx_ds_builtin_sup} - , {load_module, emqx_ds_replication_layer} - , {load_module, emqx_ds_storage_layer} - , {load_module, emqx_broker_helper} - , {load_module, emqx_shared_sub} , {load_module, emqx_ds_replication_shard_allocator} - , {load_module, emqx_mgmt_api_metrics} , {update, emqx_ds_replication_layer_egress, {advanced, #{}}} ], post_upgrade_callbacks => - [ {pr12765_update_stats_timer, pr12765_revert_stats_timer} + [ + %% emqx_post_upgrade:pr12765_update_stats_timer/1 + pr12765_update_stats_timer, + %% emqx_post_upgrade:pr20000_ensure_sup_started/3 + {pr20000_ensure_sup_started, ["5.6.1+patch.A", ChildSpec(some_mod)]} ] }.