Avoid last handled stanzas cache to grow indefinitely

This commit is contained in:
Evgeny Khramtsov 2019-07-01 20:43:57 +03:00
parent 052894d608
commit f68da70f3e
3 changed files with 15 additions and 4 deletions

View File

@ -20,7 +20,7 @@
{deps, [{lager, ".*", {git, "https://github.com/erlang-lager/lager", "3.6.10"}},
{p1_utils, ".*", {git, "https://github.com/processone/p1_utils", "2887223"}},
{cache_tab, ".*", {git, "https://github.com/processone/cache_tab", "f3d8376"}},
{cache_tab, ".*", {git, "https://github.com/processone/cache_tab", "01e0f33"}},
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.1.1"}}},
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.16"}}},
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", "7fd02f3a2f"}},

View File

@ -752,7 +752,8 @@ init_cache(Opts) ->
cache_opts(Opts) ->
[{max_size, mod_stream_mgmt_opt:cache_size(Opts)},
{life_time, infinity}].
{life_time, mod_stream_mgmt_opt:cache_life_time(Opts)},
{type, ordered_set}].
-spec store_stanzas_in(ljid(), erlang:timestamp(), non_neg_integer()) -> boolean().
store_stanzas_in(LJID, Time, Num) ->
@ -763,8 +764,8 @@ store_stanzas_in(LJID, Time, Num) ->
pop_stanzas_in(LJID, Time) ->
case ets_cache:lookup(?STREAM_MGMT_CACHE, {LJID, Time}) of
{ok, Val} ->
ets_cache:delete(?STREAM_MGMT_CACHE, {LJID, Time},
ejabberd_cluster:get_nodes()),
ets_cache:match_delete(?STREAM_MGMT_CACHE, {LJID, '_'},
ejabberd_cluster:get_nodes()),
{ok, Val};
error ->
error
@ -809,6 +810,8 @@ mod_opt_type(resend_on_timeout) ->
econf:bool());
mod_opt_type(cache_size) ->
econf:pos_int(infinity);
mod_opt_type(cache_life_time) ->
econf:timeout(second, infinity);
mod_opt_type(queue_type) ->
econf:queue_type().
@ -818,5 +821,6 @@ mod_options(Host) ->
{max_resume_timeout, undefined},
{ack_timeout, timer:seconds(60)},
{cache_size, ejabberd_option:cache_size(Host)},
{cache_life_time, timer:hours(48)},
{resend_on_timeout, false},
{queue_type, ejabberd_option:queue_type(Host)}].

View File

@ -4,6 +4,7 @@
-module(mod_stream_mgmt_opt).
-export([ack_timeout/1]).
-export([cache_life_time/1]).
-export([cache_size/1]).
-export([max_ack_queue/1]).
-export([max_resume_timeout/1]).
@ -17,6 +18,12 @@ ack_timeout(Opts) when is_map(Opts) ->
ack_timeout(Host) ->
gen_mod:get_module_opt(Host, mod_stream_mgmt, ack_timeout).
-spec cache_life_time(gen_mod:opts() | global | binary()) -> 'infinity' | pos_integer().
cache_life_time(Opts) when is_map(Opts) ->
gen_mod:get_opt(cache_life_time, Opts);
cache_life_time(Host) ->
gen_mod:get_module_opt(Host, mod_stream_mgmt, cache_life_time).
-spec cache_size(gen_mod:opts() | global | binary()) -> 'infinity' | pos_integer().
cache_size(Opts) when is_map(Opts) ->
gen_mod:get_opt(cache_size, Opts);