aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Khramtsov <ekhramtsov@process-one.net>2019-07-01 20:43:57 +0300
committerEvgeny Khramtsov <ekhramtsov@process-one.net>2019-07-01 20:43:57 +0300
commitf68da70f3ed77700558d39050c2353f46937630a (patch)
tree633839d3bae2aad61bb560aee3280b739ca10348 /src
parentUpdate Spanish and Catalan translations (diff)
Avoid last handled stanzas cache to grow indefinitely
Diffstat (limited to 'src')
-rw-r--r--src/mod_stream_mgmt.erl10
-rw-r--r--src/mod_stream_mgmt_opt.erl7
2 files changed, 14 insertions, 3 deletions
diff --git a/src/mod_stream_mgmt.erl b/src/mod_stream_mgmt.erl
index c151807ff..1ebff130c 100644
--- a/src/mod_stream_mgmt.erl
+++ b/src/mod_stream_mgmt.erl
@@ -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)}].
diff --git a/src/mod_stream_mgmt_opt.erl b/src/mod_stream_mgmt_opt.erl
index 102906fdc..58d4fe1e7 100644
--- a/src/mod_stream_mgmt_opt.erl
+++ b/src/mod_stream_mgmt_opt.erl
@@ -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);