From f2a8041cd5690d3416c1705b25f3b9b4635d1b55 Mon Sep 17 00:00:00 2001 From: Valentino Geron Date: Thu, 1 Apr 2021 12:13:55 +0300 Subject: [PATCH] Fix XAUTOCLAIM response to return the next available id as the cursor (#8725) This command used to return the last scanned entry id as the cursor, instead of the next one to be scanned. so in the next call, the user could / should have sent `(cursor` and not just `cursor` if he wanted to avoid scanning the same record twice. Scanning the record twice would look odd if someone is checking what exactly was scanned, but it also has a side effect of incrementing the delivery count twice. --- src/t_stream.c | 3 +++ tests/unit/type/stream-cgroups.tcl | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/t_stream.c b/src/t_stream.c index 1407ee98b..f175eed9a 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -3151,6 +3151,9 @@ void xautoclaimCommand(client *c) { server.dirty++; } + /* We need to return the next entry as a cursor for the next XAUTOCLAIM call */ + raxNext(&ri); + streamID endid; if (raxEOF(&ri)) { endid.ms = endid.seq = 0; diff --git a/tests/unit/type/stream-cgroups.tcl b/tests/unit/type/stream-cgroups.tcl index f8de0741d..53eb46ca3 100644 --- a/tests/unit/type/stream-cgroups.tcl +++ b/tests/unit/type/stream-cgroups.tcl @@ -373,7 +373,7 @@ start_server { after 200 set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 1] assert_equal [llength $reply] 2 - assert_equal [lindex $reply 0] $id1 + assert_equal [lindex $reply 0] "0-0" assert_equal [llength [lindex $reply 1]] 1 assert_equal [llength [lindex $reply 1 0]] 2 assert_equal [llength [lindex $reply 1 0 1]] 2 @@ -392,7 +392,7 @@ start_server { set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 2] # id1 is self-claimed here but not id2 ('count' was set to 2) assert_equal [llength $reply] 2 - assert_equal [lindex $reply 0] $id2 + assert_equal [lindex $reply 0] $id3 assert_equal [llength [lindex $reply 1]] 2 assert_equal [llength [lindex $reply 1 0]] 2 assert_equal [llength [lindex $reply 1 0 1]] 2 @@ -438,22 +438,22 @@ start_server { set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 2] assert_equal [llength $reply] 2 set cursor [lindex $reply 0] - assert_equal $cursor $id2 + assert_equal $cursor $id3 assert_equal [llength [lindex $reply 1]] 2 assert_equal [llength [lindex $reply 1 0 1]] 2 assert_equal [lindex $reply 1 0 1] {a 1} # Claim 2 more entries - set reply [r XAUTOCLAIM mystream mygroup consumer2 10 ($cursor COUNT 2] + set reply [r XAUTOCLAIM mystream mygroup consumer2 10 $cursor COUNT 2] assert_equal [llength $reply] 2 set cursor [lindex $reply 0] - assert_equal $cursor $id4 + assert_equal $cursor $id5 assert_equal [llength [lindex $reply 1]] 2 assert_equal [llength [lindex $reply 1 0 1]] 2 assert_equal [lindex $reply 1 0 1] {c 3} # Claim last entry - set reply [r XAUTOCLAIM mystream mygroup consumer2 10 ($cursor COUNT 2] + set reply [r XAUTOCLAIM mystream mygroup consumer2 10 $cursor COUNT 1] assert_equal [llength $reply] 2 set cursor [lindex $reply 0] assert_equal $cursor {0-0}