diff options
author | Huang Zhw <huang_zhw@126.com> | 2021-06-07 19:43:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 14:43:36 +0300 |
commit | eaa7a7bb93c1ac6dbf347e1c29ac719a12a75158 (patch) | |
tree | 9a20e74434721bc3848a99df2696678131100bc8 /src/t_stream.c | |
parent | b438bc5a0bd0ec98681151a32a05845ffc917871 (diff) | |
download | redis-eaa7a7bb93c1ac6dbf347e1c29ac719a12a75158.tar.gz |
Fix XTRIM or XADD with LIMIT may delete more entries than Count. (#9048)
The decision to stop trimming due to LIMIT in XADD and XTRIM was after the limit was reached.
i.e. the code was deleting **at least** that count of records (from the LIMIT argument's perspective, not the MAXLEN),
instead of **up to** that count of records.
see #9046
Diffstat (limited to 'src/t_stream.c')
-rw-r--r-- | src/t_stream.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/t_stream.c b/src/t_stream.c index 7c8a288c8..678fceeee 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -702,16 +702,16 @@ int64_t streamTrim(stream *s, streamAddTrimArgs *args) { int64_t deleted = 0; while (raxNext(&ri)) { - /* Check if we exceeded the amount of work we could do */ - if (limit && deleted >= limit) - break; - if (trim_strategy == TRIM_STRATEGY_MAXLEN && s->length <= maxlen) break; unsigned char *lp = ri.data, *p = lpFirst(lp); int64_t entries = lpGetInteger(p); + /* Check if we exceeded the amount of work we could do */ + if (limit && (deleted + entries) > limit) + break; + /* Check if we can remove the whole node. */ int remove_node; streamID master_id = {0}; /* For MINID */ |