fix: e4.4.0 failed to join e4.3.0 cluster
This commit is contained in:
parent
fdacb9040d
commit
41a547d36d
|
@ -44,32 +44,16 @@
|
|||
, code_change/3
|
||||
]).
|
||||
|
||||
-ifdef(TEST).
|
||||
-export([create_table/0]).
|
||||
-endif.
|
||||
|
||||
-define(TAB, ?MODULE).
|
||||
|
||||
-record(state, {max_predef_topic_id = 0}).
|
||||
|
||||
-record(emqx_sn_registry, {key, value}).
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
-copy_mnesia({mnesia, [copy]}).
|
||||
|
||||
|
||||
%% @doc Create or replicate tables.
|
||||
-spec(mnesia(boot | copy) -> ok).
|
||||
mnesia(boot) ->
|
||||
%% Optimize storage
|
||||
StoreProps = [{ets, [{read_concurrency, true}]}],
|
||||
ok = ekka_mnesia:create_table(?MODULE, [
|
||||
{attributes, record_info(fields, emqx_sn_registry)},
|
||||
{ram_copies, [node()]},
|
||||
{storage_properties, StoreProps}]);
|
||||
|
||||
mnesia(copy) ->
|
||||
ok = ekka_mnesia:copy_table(?MODULE, ram_copies).
|
||||
|
||||
%%-----------------------------------------------------------------------------
|
||||
|
||||
-spec(start_link(list()) -> {ok, pid()} | ignore | {error, Reason :: term()}).
|
||||
|
@ -123,6 +107,7 @@ unregister_topic(ClientId) ->
|
|||
%%-----------------------------------------------------------------------------
|
||||
|
||||
init([PredefTopics]) ->
|
||||
create_table(),
|
||||
%% {predef, TopicId} -> TopicName
|
||||
%% {predef, TopicName} -> TopicId
|
||||
%% {ClientId, TopicId} -> TopicName
|
||||
|
@ -137,6 +122,15 @@ init([PredefTopics]) ->
|
|||
end, 0, PredefTopics),
|
||||
{ok, #state{max_predef_topic_id = MaxPredefId}}.
|
||||
|
||||
create_table() ->
|
||||
%% Optimize storage
|
||||
StoreProps = [{ets, [{read_concurrency, true}]}],
|
||||
ok = ekka_mnesia:create_table(?MODULE, [
|
||||
{attributes, record_info(fields, emqx_sn_registry)},
|
||||
{ram_copies, [node()]},
|
||||
{storage_properties, StoreProps}]),
|
||||
ok = ekka_mnesia:copy_table(?MODULE, ram_copies).
|
||||
|
||||
handle_call({register, ClientId, TopicName}, _From,
|
||||
State = #state{max_predef_topic_id = PredefId}) ->
|
||||
case lookup_topic_id(ClientId, TopicName) of
|
||||
|
|
|
@ -42,7 +42,7 @@ end_per_suite(_Config) ->
|
|||
|
||||
init_per_testcase(_TestCase, Config) ->
|
||||
ekka_mnesia:start(),
|
||||
emqx_sn_registry:mnesia(boot),
|
||||
emqx_sn_registry:create_table(),
|
||||
mnesia:clear_table(emqx_sn_registry),
|
||||
PredefTopics = application:get_env(emqx_sn, predefined, []),
|
||||
{ok, _Pid} = ?REGISTRY:start_link(PredefTopics),
|
||||
|
@ -118,4 +118,3 @@ register_a_lot(N, Max) when N < Max ->
|
|||
Topic = iolist_to_binary(["Topic", integer_to_list(N)]),
|
||||
?assertEqual(N, ?REGISTRY:register_topic(<<"ClientId">>, Topic)),
|
||||
register_a_lot(N+1, Max).
|
||||
|
||||
|
|
Loading…
Reference in New Issue