Merge pull request #4711 from qzhuyan/dev/william/fix-issue-2671-c2

Dev/william/fix issue 2671 c2
This commit is contained in:
William Yang 2021-04-29 11:20:36 +02:00 committed by GitHub
commit 3c103ae546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View File

@ -2268,8 +2268,8 @@ broker.shared_dispatch_ack_enabled = false
## Value: Flag ## Value: Flag
broker.route_batch_clean = off broker.route_batch_clean = off
## Performance toggle for subscribe/unsubscribe wildcard topic ## Performance toggle for subscribe/unsubscribe wildcard topic.
## change this toggle only when there are many wildcard topics. ## Change this toggle only when there are many wildcard topics.
## Value: Enum ## Value: Enum
## - key: mnesia translational updates with per-key locks. recommended for single node setup. ## - key: mnesia translational updates with per-key locks. recommended for single node setup.
## - tab: mnesia translational updates with table lock. recommended for multi-nodes setup. ## - tab: mnesia translational updates with table lock. recommended for multi-nodes setup.

View File

@ -2254,11 +2254,13 @@ end}.
{datatype, flag} {datatype, flag}
]}. ]}.
%% @doc performance toggle for subscribe/unsubscribe wildcard topic %% @doc Performance toggle for subscribe/unsubscribe wildcard topic.
%% change this toggle only when there are many wildcard topics. %% Change this toggle only when there are many wildcard topics.
%% key: mnesia translational updates with per-key locks. recommended for single node setup. %% key: mnesia translational updates with per-key locks. recommended for single node setup.
%% tab: mnesia translational updates with table lock. recommended for multi-nodes setup. %% tab: mnesia translational updates with table lock. recommended for multi-nodes setup.
%% global: global lock protected updates. recommended for larger cluster. %% global: global lock protected updates. recommended for larger cluster.
%% NOTE: when changing from/to 'global' lock, it requires all nodes in the cluster
%%
{mapping, "broker.perf.route_lock_type", "emqx.route_lock_type", [ {mapping, "broker.perf.route_lock_type", "emqx.route_lock_type", [
{default, key}, {default, key},
{datatype, {enum, [key, tab, global]}} {datatype, {enum, [key, tab, global]}}

View File

@ -268,9 +268,26 @@ maybe_trans(Fun, Args) ->
-spec(trans(function(), list(any())) -> ok | {error, term()}). -spec(trans(function(), list(any())) -> ok | {error, term()}).
trans(Fun, Args) -> trans(Fun, Args) ->
case mnesia:transaction(Fun, Args) of %% trigger selective receive optimization of compiler,
{atomic, Ok} -> Ok; %% ideal for handling bursty traffic.
{aborted, Reason} -> {error, Reason} Ref = erlang:make_ref(),
Owner = self(),
{WPid, RefMon} = spawn_monitor(
fun() ->
Res = case mnesia:transaction(Fun, Args) of
{atomic, Ok} -> Ok;
{aborted, Reason} -> {error, Reason}
end,
Owner ! {Ref, Res}
end),
receive
{Ref, TransRes} ->
receive
{'DOWN', RefMon, process, WPid, normal} -> ok
end,
TransRes;
{'DOWN', RefMon, process, WPid, Info} ->
{error, {trans_crash, Info}}
end. end.
lock_router() -> lock_router() ->