From 1ed0f049fed99e67e6216b5eb8798c423e33f673 Mon Sep 17 00:00:00 2001 From: DarrenJiang13 Date: Sat, 7 Aug 2021 10:27:24 +0800 Subject: [PATCH] [BUGFIX] Add some missed error statistics (#9328) add error counting for some missed behaviors. (cherry picked from commit 43eb0ce3bf76a5d287b93a767bead9ad6230a1ad) --- src/db.c | 2 +- src/multi.c | 10 +++++++--- src/object.c | 3 +-- src/server.h | 1 + tests/unit/info.tcl | 7 ++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/db.c b/src/db.c index 05c795114..6f6d696e1 100644 --- a/src/db.c +++ b/src/db.c @@ -165,7 +165,7 @@ robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags) { robj *lookupKeyWrite(redisDb *db, robj *key) { return lookupKeyWriteWithFlags(db, key, LOOKUP_NONE); } -static void SentReplyOnKeyMiss(client *c, robj *reply){ +void SentReplyOnKeyMiss(client *c, robj *reply){ serverAssert(sdsEncodedObject(reply)); sds rep = reply->ptr; if (sdslen(rep) > 1 && rep[0] == '-'){ diff --git a/src/multi.c b/src/multi.c index 3a157bee6..ebbdabbf0 100644 --- a/src/multi.c +++ b/src/multi.c @@ -179,9 +179,13 @@ void execCommand(client *c) { * A failed EXEC in the first case returns a multi bulk nil object * (technically it is not an error but a special behavior), while * in the second an EXECABORT error is returned. */ - if (c->flags & (CLIENT_DIRTY_CAS|CLIENT_DIRTY_EXEC)) { - addReply(c, c->flags & CLIENT_DIRTY_EXEC ? shared.execaborterr : - shared.nullarray[c->resp]); + if (c->flags & (CLIENT_DIRTY_CAS | CLIENT_DIRTY_EXEC)) { + if (c->flags & CLIENT_DIRTY_EXEC) { + addReplyErrorObject(c, shared.execaborterr); + } else { + addReply(c, shared.nullarray[c->resp]); + } + discardTransaction(c); return; } diff --git a/src/object.c b/src/object.c index 23920fb2c..8a5e80a6f 100644 --- a/src/object.c +++ b/src/object.c @@ -1246,8 +1246,7 @@ robj *objectCommandLookup(client *c, robj *key) { robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply) { robj *o = objectCommandLookup(c,key); - - if (!o) addReply(c, reply); + if (!o) SentReplyOnKeyMiss(c, reply); return o; } diff --git a/src/server.h b/src/server.h index 74bd5447a..4edb7d3a0 100644 --- a/src/server.h +++ b/src/server.h @@ -2339,6 +2339,7 @@ robj *lookupKeyReadWithFlags(redisDb *db, robj *key, int flags); robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags); robj *objectCommandLookup(client *c, robj *key); robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply); +void SentReplyOnKeyMiss(client *c, robj *reply); int objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle, long long lru_clock, int lru_multiplier); #define LOOKUP_NONE 0 diff --git a/tests/unit/info.tcl b/tests/unit/info.tcl index 0602e7147..61be4a0d1 100644 --- a/tests/unit/info.tcl +++ b/tests/unit/info.tcl @@ -110,11 +110,12 @@ start_server {tags {"info"}} { catch {r exec} e assert_match {EXECABORT*} $e assert_match {*count=1*} [errorstat ERR] - assert_equal [s total_error_replies] 1 + assert_match {*count=1*} [errorstat EXECABORT] + assert_equal [s total_error_replies] 2 assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set] assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat multi] - assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat exec] - assert_equal [s total_error_replies] 1 + assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat exec] + assert_equal [s total_error_replies] 2 r config resetstat assert_match {} [errorstat ERR] }