In XADD take deleted items into consideration when switch to new node (#8390)

If we set stream-node-max-bytes = 0, then we insert entry then delete,
do this many times, the last stream node will be very big.
This commit is contained in:
Huang Zw 2021-02-22 21:08:16 +08:00 committed by GitHub
parent 75ca6c2ef6
commit c5c4c3018a

View File

@ -512,7 +512,9 @@ int streamAppendItem(stream *s, robj **argv, int64_t numfields, streamID *added_
{ {
lp = NULL; lp = NULL;
} else if (server.stream_node_max_entries) { } else if (server.stream_node_max_entries) {
int64_t count = lpGetInteger(lpFirst(lp)); unsigned char *lp_ele = lpFirst(lp);
/* Count both live entries and deleted ones. */
int64_t count = lpGetInteger(lp_ele) + lpGetInteger(lpNext(lp,lp_ele));
if (count >= server.stream_node_max_entries) { if (count >= server.stream_node_max_entries) {
/* Shrink extra pre-allocated memory */ /* Shrink extra pre-allocated memory */
lp = lpShrinkToFit(lp); lp = lpShrinkToFit(lp);