summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2019-12-04 17:29:29 +0200
committerOran Agra <oran@redislabs.com>2020-03-25 21:47:57 +0200
commit3b29556a0cd9db0daa7828fe81df41fbe95e04dc (patch)
tree3d47437e445643120c64b65ee77e695ce1eb0db0
parentc1295bb9f1234f2a3dd3c1bf76eb5afcf8cf711a (diff)
downloadredis-3b29556a0cd9db0daa7828fe81df41fbe95e04dc.tar.gz
AOFRW on an empty stream created with MKSTREAM loads badkly
the AOF will be loaded successfully, but the stream will be missing, i.e inconsistencies with the original db. this was because XADD with id of 0-0 would error. add a test to reproduce.
-rw-r--r--src/aof.c3
-rw-r--r--tests/unit/type/stream-cgroups.tcl13
2 files changed, 15 insertions, 1 deletions
diff --git a/src/aof.c b/src/aof.c
index 8ab9349f0..6bb239252 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -1212,12 +1212,13 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
/* Use the XADD MAXLEN 0 trick to generate an empty stream if
* the key we are serializing is an empty string, which is possible
* for the Stream type. */
+ id.ms = 0; id.seq = 1;
if (rioWriteBulkCount(r,'*',7) == 0) return 0;
if (rioWriteBulkString(r,"XADD",4) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
if (rioWriteBulkString(r,"MAXLEN",6) == 0) return 0;
if (rioWriteBulkString(r,"0",1) == 0) return 0;
- if (rioWriteBulkStreamID(r,&s->last_id) == 0) return 0;
+ if (rioWriteBulkStreamID(r,&id) == 0) return 0;
if (rioWriteBulkString(r,"x",1) == 0) return 0;
if (rioWriteBulkString(r,"y",1) == 0) return 0;
}
diff --git a/tests/unit/type/stream-cgroups.tcl b/tests/unit/type/stream-cgroups.tcl
index 072ed14d6..6b9a4a9cd 100644
--- a/tests/unit/type/stream-cgroups.tcl
+++ b/tests/unit/type/stream-cgroups.tcl
@@ -311,4 +311,17 @@ start_server {
}
}
}
+
+ start_server {tags {"stream"} overrides {appendonly yes aof-use-rdb-preamble no}} {
+ test {Empty stream with no lastid can be rewrite into AOF correctly} {
+ r XGROUP CREATE mystream group-name $ MKSTREAM
+ assert {[dict get [r xinfo stream mystream] length] == 0}
+ set grpinfo [r xinfo groups mystream]
+ r bgrewriteaof
+ waitForBgrewriteaof r
+ r debug loadaof
+ assert {[dict get [r xinfo stream mystream] length] == 0}
+ assert {[r xinfo groups mystream] == $grpinfo}
+ }
+ }
}