瀏覽代碼

refactor: remove relup revert callback functions

Shawn 1 年之前
父節點
當前提交
439abe430b
共有 3 個文件被更改,包括 37 次插入29 次删除
  1. 15 13
      apps/emqx/src/emqx_post_upgrade.erl
  2. 1 1
      rebar.config.erl
  3. 21 15
      rel/relup/examples/5.6.1-to-5.6.1+patch.A.relup

+ 15 - 13
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.

+ 1 - 1
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"}

+ 21 - 15
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)]}
         ]
 }.