|
@@ -117,7 +117,7 @@
|
|
|
id := subscription_id(),
|
|
id := subscription_id(),
|
|
|
start_time := emqx_ds:time(),
|
|
start_time := emqx_ds:time(),
|
|
|
props := map(),
|
|
props := map(),
|
|
|
- extra := map()
|
|
|
|
|
|
|
+ deleted := boolean()
|
|
|
}.
|
|
}.
|
|
|
|
|
|
|
|
-define(TIMER_PULL, timer_pull).
|
|
-define(TIMER_PULL, timer_pull).
|
|
@@ -209,7 +209,7 @@ info(created_at, #{s := S}) ->
|
|
|
info(is_persistent, #{}) ->
|
|
info(is_persistent, #{}) ->
|
|
|
true;
|
|
true;
|
|
|
info(subscriptions, #{s := S}) ->
|
|
info(subscriptions, #{s := S}) ->
|
|
|
- subs_to_map(S);
|
|
|
|
|
|
|
+ emqx_persistent_session_ds_subs:to_map(S);
|
|
|
info(subscriptions_cnt, #{s := S}) ->
|
|
info(subscriptions_cnt, #{s := S}) ->
|
|
|
emqx_topic_gbt:size(emqx_persistent_session_ds_state:get_subscriptions(S));
|
|
emqx_topic_gbt:size(emqx_persistent_session_ds_state:get_subscriptions(S));
|
|
|
info(subscriptions_max, #{props := Conf}) ->
|
|
info(subscriptions_max, #{props := Conf}) ->
|
|
@@ -280,7 +280,7 @@ subscribe(
|
|
|
SubOpts,
|
|
SubOpts,
|
|
|
Session = #{id := ID, s := S0}
|
|
Session = #{id := ID, s := S0}
|
|
|
) ->
|
|
) ->
|
|
|
- case subs_lookup(TopicFilter, S0) of
|
|
|
|
|
|
|
+ case emqx_persistent_session_ds_subs:lookup(TopicFilter, S0) of
|
|
|
undefined ->
|
|
undefined ->
|
|
|
%% TODO: max subscriptions
|
|
%% TODO: max subscriptions
|
|
|
|
|
|
|
@@ -313,7 +313,8 @@ subscribe(
|
|
|
Subscription = #{
|
|
Subscription = #{
|
|
|
start_time => now_ms(),
|
|
start_time => now_ms(),
|
|
|
props => SubOpts,
|
|
props => SubOpts,
|
|
|
- id => SubId
|
|
|
|
|
|
|
+ id => SubId,
|
|
|
|
|
+ deleted => false
|
|
|
},
|
|
},
|
|
|
IsNew = true;
|
|
IsNew = true;
|
|
|
Subscription0 = #{} ->
|
|
Subscription0 = #{} ->
|
|
@@ -321,7 +322,7 @@ subscribe(
|
|
|
IsNew = false,
|
|
IsNew = false,
|
|
|
S1 = S0
|
|
S1 = S0
|
|
|
end,
|
|
end,
|
|
|
- S = emqx_persistent_session_ds_state:put_subscription(TopicFilter, [], Subscription, S1),
|
|
|
|
|
|
|
+ S = emqx_persistent_session_ds_subs:on_subscribe(TopicFilter, Subscription, S1),
|
|
|
?tp(persistent_session_ds_subscription_added, #{
|
|
?tp(persistent_session_ds_subscription_added, #{
|
|
|
topic_filter => TopicFilter, sub => Subscription, is_new => IsNew
|
|
topic_filter => TopicFilter, sub => Subscription, is_new => IsNew
|
|
|
}),
|
|
}),
|
|
@@ -333,7 +334,7 @@ unsubscribe(
|
|
|
TopicFilter,
|
|
TopicFilter,
|
|
|
Session = #{id := ID, s := S0}
|
|
Session = #{id := ID, s := S0}
|
|
|
) ->
|
|
) ->
|
|
|
- case subs_lookup(TopicFilter, S0) of
|
|
|
|
|
|
|
+ case emqx_persistent_session_ds_subs:lookup(TopicFilter, S0) of
|
|
|
undefined ->
|
|
undefined ->
|
|
|
{error, ?RC_NO_SUBSCRIPTION_EXISTED};
|
|
{error, ?RC_NO_SUBSCRIPTION_EXISTED};
|
|
|
Subscription = #{props := SubOpts} ->
|
|
Subscription = #{props := SubOpts} ->
|
|
@@ -343,12 +344,12 @@ unsubscribe(
|
|
|
|
|
|
|
|
-spec do_unsubscribe(id(), topic_filter(), subscription(), emqx_persistent_session_ds_state:t()) ->
|
|
-spec do_unsubscribe(id(), topic_filter(), subscription(), emqx_persistent_session_ds_state:t()) ->
|
|
|
emqx_persistent_session_ds_state:t().
|
|
emqx_persistent_session_ds_state:t().
|
|
|
-do_unsubscribe(SessionId, TopicFilter, #{id := SubId}, S0) ->
|
|
|
|
|
- S1 = emqx_persistent_session_ds_state:del_subscription(TopicFilter, [], S0),
|
|
|
|
|
|
|
+do_unsubscribe(SessionId, TopicFilter, Subscription = #{id := SubId}, S0) ->
|
|
|
|
|
+ S1 = emqx_persistent_session_ds_subs:on_unsubscribe(TopicFilter, Subscription, S0),
|
|
|
?tp(persistent_session_ds_subscription_delete, #{
|
|
?tp(persistent_session_ds_subscription_delete, #{
|
|
|
session_id => SessionId, topic_filter => TopicFilter
|
|
session_id => SessionId, topic_filter => TopicFilter
|
|
|
}),
|
|
}),
|
|
|
- S = emqx_persistent_session_ds_stream_scheduler:del_subscription(SubId, S1),
|
|
|
|
|
|
|
+ S = emqx_persistent_session_ds_stream_scheduler:on_unsubscribe(SubId, S1),
|
|
|
?tp_span(
|
|
?tp_span(
|
|
|
persistent_session_ds_subscription_route_delete,
|
|
persistent_session_ds_subscription_route_delete,
|
|
|
#{session_id => SessionId, topic_filter => TopicFilter},
|
|
#{session_id => SessionId, topic_filter => TopicFilter},
|
|
@@ -359,7 +360,7 @@ do_unsubscribe(SessionId, TopicFilter, #{id := SubId}, S0) ->
|
|
|
-spec get_subscription(topic_filter(), session()) ->
|
|
-spec get_subscription(topic_filter(), session()) ->
|
|
|
emqx_types:subopts() | undefined.
|
|
emqx_types:subopts() | undefined.
|
|
|
get_subscription(TopicFilter, #{s := S}) ->
|
|
get_subscription(TopicFilter, #{s := S}) ->
|
|
|
- case subs_lookup(TopicFilter, S) of
|
|
|
|
|
|
|
+ case emqx_persistent_session_ds_subs:lookup(TopicFilter, S) of
|
|
|
_Subscription = #{props := SubOpts} ->
|
|
_Subscription = #{props := SubOpts} ->
|
|
|
SubOpts;
|
|
SubOpts;
|
|
|
undefined ->
|
|
undefined ->
|
|
@@ -459,7 +460,8 @@ handle_timeout(
|
|
|
Session = emqx_session:ensure_timer(?TIMER_PULL, Timeout, Session1),
|
|
Session = emqx_session:ensure_timer(?TIMER_PULL, Timeout, Session1),
|
|
|
{ok, Publishes, Session};
|
|
{ok, Publishes, Session};
|
|
|
handle_timeout(_ClientInfo, ?TIMER_GET_STREAMS, Session0 = #{s := S0}) ->
|
|
handle_timeout(_ClientInfo, ?TIMER_GET_STREAMS, Session0 = #{s := S0}) ->
|
|
|
- S = emqx_persistent_session_ds_stream_scheduler:renew_streams(S0),
|
|
|
|
|
|
|
+ S1 = emqx_persistent_session_ds_subs:gc(S0),
|
|
|
|
|
+ S = emqx_persistent_session_ds_stream_scheduler:renew_streams(S1),
|
|
|
Interval = emqx_config:get([session_persistence, renew_streams_interval]),
|
|
Interval = emqx_config:get([session_persistence, renew_streams_interval]),
|
|
|
Session = emqx_session:ensure_timer(
|
|
Session = emqx_session:ensure_timer(
|
|
|
?TIMER_GET_STREAMS,
|
|
?TIMER_GET_STREAMS,
|
|
@@ -679,7 +681,7 @@ session_drop(ID, Reason) ->
|
|
|
case emqx_persistent_session_ds_state:open(ID) of
|
|
case emqx_persistent_session_ds_state:open(ID) of
|
|
|
{ok, S0} ->
|
|
{ok, S0} ->
|
|
|
?tp(debug, drop_persistent_session, #{client_id => ID, reason => Reason}),
|
|
?tp(debug, drop_persistent_session, #{client_id => ID, reason => Reason}),
|
|
|
- _S = subs_fold(
|
|
|
|
|
|
|
+ _S = emqx_persistent_session_ds_subs:fold(
|
|
|
fun(TopicFilter, Subscription, S) ->
|
|
fun(TopicFilter, Subscription, S) ->
|
|
|
do_unsubscribe(ID, TopicFilter, Subscription, S)
|
|
do_unsubscribe(ID, TopicFilter, Subscription, S)
|
|
|
end,
|
|
end,
|
|
@@ -897,27 +899,6 @@ do_drain_buffer(Inflight0, S0, Acc) ->
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-subs_lookup(TopicFilter, S) ->
|
|
|
|
|
- Subs = emqx_persistent_session_ds_state:get_subscriptions(S),
|
|
|
|
|
- emqx_topic_gbt:lookup(TopicFilter, [], Subs, undefined).
|
|
|
|
|
-
|
|
|
|
|
-subs_to_map(S) ->
|
|
|
|
|
- subs_fold(
|
|
|
|
|
- fun(TopicFilter, #{props := Props}, Acc) -> Acc#{TopicFilter => Props} end,
|
|
|
|
|
- #{},
|
|
|
|
|
- S
|
|
|
|
|
- ).
|
|
|
|
|
-
|
|
|
|
|
-subs_fold(Fun, AccIn, S) ->
|
|
|
|
|
- Subs = emqx_persistent_session_ds_state:get_subscriptions(S),
|
|
|
|
|
- emqx_topic_gbt:fold(
|
|
|
|
|
- fun(Key, Sub, Acc) -> Fun(emqx_topic_gbt:get_topic(Key), Sub, Acc) end,
|
|
|
|
|
- AccIn,
|
|
|
|
|
- Subs
|
|
|
|
|
- ).
|
|
|
|
|
-
|
|
|
|
|
-%%--------------------------------------------------------------------------------
|
|
|
|
|
-
|
|
|
|
|
%% TODO: find a more reliable way to perform actions that have side
|
|
%% TODO: find a more reliable way to perform actions that have side
|
|
|
%% effects. Add `CBM:init' callback to the session behavior?
|
|
%% effects. Add `CBM:init' callback to the session behavior?
|
|
|
-spec ensure_timers(session()) -> session().
|
|
-spec ensure_timers(session()) -> session().
|