diff --git a/src/t_stream.c b/src/t_stream.c index 85ae4354b..91ffdbbd4 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -2778,6 +2778,11 @@ void xsetidCommand(client *c) { if (o == NULL || checkType(c,o,OBJ_STREAM)) return; stream *s = o->ptr; + if (streamCompareID(&id,&s->max_deleted_entry_id) < 0) { + addReplyError(c,"The ID specified in XSETID is smaller than current max_deleted_entry_id"); + return; + } + /* If the stream has at least one item, we want to check that the user * is setting a last ID that is equal or greater than the current top * item, otherwise the fundamental ID monotonicity assumption is violated. */ diff --git a/tests/unit/type/stream.tcl b/tests/unit/type/stream.tcl index 8f196883a..3081c40d1 100644 --- a/tests/unit/type/stream.tcl +++ b/tests/unit/type/stream.tcl @@ -823,6 +823,19 @@ start_server {tags {"stream"}} { r XADD mystream MAXLEN 0 * a b set err } {ERR *smaller*} + + test {XSETID cannot set smaller ID than current MAXDELETEDID} { + r DEL x + r XADD x 1-1 a 1 + r XADD x 1-2 b 2 + r XADD x 1-3 c 3 + r XDEL x 1-2 + r XDEL x 1-3 + set reply [r XINFO stream x] + assert_equal [dict get $reply max-deleted-entry-id] "1-3" + catch {r XSETID x "1-2" } err + set err + } {ERR *smaller*} } start_server {tags {"stream"}} {