From aae0fdc11434fa76a1847eca9292c277b559730a Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 16 Jul 2019 18:32:01 -0400 Subject: [PATCH 1/2] Shared objects should be marked as such --- src/server.cpp | 144 ++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 8ccbab059..e1d0aa5da 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2184,99 +2184,99 @@ void afterSleep(struct aeEventLoop *eventLoop) { void createSharedObjects(void) { int j; - shared.crlf = createObject(OBJ_STRING,sdsnew("\r\n")); - shared.ok = createObject(OBJ_STRING,sdsnew("+OK\r\n")); - shared.err = createObject(OBJ_STRING,sdsnew("-ERR\r\n")); - shared.emptybulk = createObject(OBJ_STRING,sdsnew("$0\r\n\r\n")); - shared.emptymultibulk = createObject(OBJ_STRING,sdsnew("*0\r\n")); - shared.nullbulk = createObject(OBJ_STRING,sdsnew("$0\r\n\r\n")); - shared.czero = createObject(OBJ_STRING,sdsnew(":0\r\n")); - shared.cone = createObject(OBJ_STRING,sdsnew(":1\r\n")); - shared.emptyarray = createObject(OBJ_STRING,sdsnew("*0\r\n")); - shared.pong = createObject(OBJ_STRING,sdsnew("+PONG\r\n")); - shared.queued = createObject(OBJ_STRING,sdsnew("+QUEUED\r\n")); - shared.emptyscan = createObject(OBJ_STRING,sdsnew("*2\r\n$1\r\n0\r\n*0\r\n")); - shared.wrongtypeerr = createObject(OBJ_STRING,sdsnew( - "-WRONGTYPE Operation against a key holding the wrong kind of value\r\n")); - shared.nokeyerr = createObject(OBJ_STRING,sdsnew( - "-ERR no such key\r\n")); - shared.syntaxerr = createObject(OBJ_STRING,sdsnew( - "-ERR syntax error\r\n")); - shared.sameobjecterr = createObject(OBJ_STRING,sdsnew( - "-ERR source and destination objects are the same\r\n")); - shared.outofrangeerr = createObject(OBJ_STRING,sdsnew( - "-ERR index out of range\r\n")); - shared.noscripterr = createObject(OBJ_STRING,sdsnew( - "-NOSCRIPT No matching script. Please use EVAL.\r\n")); - shared.loadingerr = createObject(OBJ_STRING,sdsnew( - "-LOADING Redis is loading the dataset in memory\r\n")); - shared.slowscripterr = createObject(OBJ_STRING,sdsnew( - "-BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n")); - shared.masterdownerr = createObject(OBJ_STRING,sdsnew( - "-MASTERDOWN Link with MASTER is down and replica-serve-stale-data is set to 'no'.\r\n")); - shared.bgsaveerr = createObject(OBJ_STRING,sdsnew( - "-MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.\r\n")); - shared.roslaveerr = createObject(OBJ_STRING,sdsnew( - "-READONLY You can't write against a read only replica.\r\n")); - shared.noautherr = createObject(OBJ_STRING,sdsnew( - "-NOAUTH Authentication required.\r\n")); - shared.oomerr = createObject(OBJ_STRING,sdsnew( - "-OOM command not allowed when used memory > 'maxmemory'.\r\n")); - shared.execaborterr = createObject(OBJ_STRING,sdsnew( - "-EXECABORT Transaction discarded because of previous errors.\r\n")); - shared.noreplicaserr = createObject(OBJ_STRING,sdsnew( - "-NOREPLICAS Not enough good replicas to write.\r\n")); - shared.busykeyerr = createObject(OBJ_STRING,sdsnew( - "-BUSYKEY Target key name already exists.\r\n")); - shared.space = createObject(OBJ_STRING,sdsnew(" ")); - shared.colon = createObject(OBJ_STRING,sdsnew(":")); - shared.plus = createObject(OBJ_STRING,sdsnew("+")); + shared.crlf = makeObjectShared(createObject(OBJ_STRING,sdsnew("\r\n"))); + shared.ok = makeObjectShared(createObject(OBJ_STRING,sdsnew("+OK\r\n"))); + shared.err = makeObjectShared(createObject(OBJ_STRING,sdsnew("-ERR\r\n"))); + shared.emptybulk = makeObjectShared(createObject(OBJ_STRING,sdsnew("$0\r\n\r\n"))); + shared.emptymultibulk = makeObjectShared(createObject(OBJ_STRING,sdsnew("*0\r\n"))); + shared.nullbulk = makeObjectShared(createObject(OBJ_STRING,sdsnew("$0\r\n\r\n"))); + shared.czero = makeObjectShared(createObject(OBJ_STRING,sdsnew(":0\r\n"))); + shared.cone = makeObjectShared(createObject(OBJ_STRING,sdsnew(":1\r\n"))); + shared.emptyarray = makeObjectShared(createObject(OBJ_STRING,sdsnew("*0\r\n"))); + shared.pong = makeObjectShared(createObject(OBJ_STRING,sdsnew("+PONG\r\n"))); + shared.queued = makeObjectShared(createObject(OBJ_STRING,sdsnew("+QUEUED\r\n"))); + shared.emptyscan = makeObjectShared(createObject(OBJ_STRING,sdsnew("*2\r\n$1\r\n0\r\n*0\r\n"))); + shared.wrongtypeerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-WRONGTYPE Operation against a key holding the wrong kind of value\r\n"))); + shared.nokeyerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-ERR no such key\r\n"))); + shared.syntaxerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-ERR syntax error\r\n"))); + shared.sameobjecterr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-ERR source and destination objects are the same\r\n"))); + shared.outofrangeerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-ERR index out of range\r\n"))); + shared.noscripterr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-NOSCRIPT No matching script. Please use EVAL.\r\n"))); + shared.loadingerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-LOADING Redis is loading the dataset in memory\r\n"))); + shared.slowscripterr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n"))); + shared.masterdownerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-MASTERDOWN Link with MASTER is down and replica-serve-stale-data is set to 'no'.\r\n"))); + shared.bgsaveerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.\r\n"))); + shared.roslaveerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-READONLY You can't write against a read only replica.\r\n"))); + shared.noautherr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-NOAUTH Authentication required.\r\n"))); + shared.oomerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-OOM command not allowed when used memory > 'maxmemory'.\r\n"))); + shared.execaborterr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-EXECABORT Transaction discarded because of previous errors.\r\n"))); + shared.noreplicaserr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-NOREPLICAS Not enough good replicas to write.\r\n"))); + shared.busykeyerr = makeObjectShared(createObject(OBJ_STRING,sdsnew( + "-BUSYKEY Target key name already exists.\r\n"))); + shared.space = makeObjectShared(createObject(OBJ_STRING,sdsnew(" "))); + shared.colon = makeObjectShared(createObject(OBJ_STRING,sdsnew(":"))); + shared.plus = makeObjectShared(createObject(OBJ_STRING,sdsnew("+"))); /* The shared NULL depends on the protocol version. */ shared.null[0] = NULL; shared.null[1] = NULL; - shared.null[2] = createObject(OBJ_STRING,sdsnew("$-1\r\n")); - shared.null[3] = createObject(OBJ_STRING,sdsnew("_\r\n")); + shared.null[2] = makeObjectShared(createObject(OBJ_STRING,sdsnew("$-1\r\n"))); + shared.null[3] = makeObjectShared(createObject(OBJ_STRING,sdsnew("_\r\n"))); shared.nullarray[0] = NULL; shared.nullarray[1] = NULL; - shared.nullarray[2] = createObject(OBJ_STRING,sdsnew("*-1\r\n")); - shared.nullarray[3] = createObject(OBJ_STRING,sdsnew("_\r\n")); + shared.nullarray[2] = makeObjectShared(createObject(OBJ_STRING,sdsnew("*-1\r\n"))); + shared.nullarray[3] = makeObjectShared(createObject(OBJ_STRING,sdsnew("_\r\n"))); for (j = 0; j < PROTO_SHARED_SELECT_CMDS; j++) { char dictid_str[64]; int dictid_len; dictid_len = ll2string(dictid_str,sizeof(dictid_str),j); - shared.select[j] = createObject(OBJ_STRING, + shared.select[j] = makeObjectShared(createObject(OBJ_STRING, sdscatprintf(sdsempty(), "*2\r\n$6\r\nSELECT\r\n$%d\r\n%s\r\n", - dictid_len, dictid_str)); - } - shared.messagebulk = createStringObject("$7\r\nmessage\r\n",13); - shared.pmessagebulk = createStringObject("$8\r\npmessage\r\n",14); - shared.subscribebulk = createStringObject("$9\r\nsubscribe\r\n",15); - shared.unsubscribebulk = createStringObject("$11\r\nunsubscribe\r\n",18); - shared.psubscribebulk = createStringObject("$10\r\npsubscribe\r\n",17); - shared.punsubscribebulk = createStringObject("$12\r\npunsubscribe\r\n",19); - shared.del = createStringObject("DEL",3); - shared.unlink = createStringObject("UNLINK",6); - shared.rpop = createStringObject("RPOP",4); - shared.lpop = createStringObject("LPOP",4); - shared.lpush = createStringObject("LPUSH",5); - shared.rpoplpush = createStringObject("RPOPLPUSH",9); - shared.zpopmin = createStringObject("ZPOPMIN",7); - shared.zpopmax = createStringObject("ZPOPMAX",7); + dictid_len, dictid_str))); + } + shared.messagebulk = makeObjectShared(createStringObject("$7\r\nmessage\r\n",13)); + shared.pmessagebulk = makeObjectShared(createStringObject("$8\r\npmessage\r\n",14)); + shared.subscribebulk = makeObjectShared(createStringObject("$9\r\nsubscribe\r\n",15)); + shared.unsubscribebulk = makeObjectShared(createStringObject("$11\r\nunsubscribe\r\n",18)); + shared.psubscribebulk = makeObjectShared(createStringObject("$10\r\npsubscribe\r\n",17)); + shared.punsubscribebulk = makeObjectShared(createStringObject("$12\r\npunsubscribe\r\n",19)); + shared.del = makeObjectShared(createStringObject("DEL",3)); + shared.unlink = makeObjectShared(createStringObject("UNLINK",6)); + shared.rpop = makeObjectShared(createStringObject("RPOP",4)); + shared.lpop = makeObjectShared(createStringObject("LPOP",4)); + shared.lpush = makeObjectShared(createStringObject("LPUSH",5)); + shared.rpoplpush = makeObjectShared(createStringObject("RPOPLPUSH",9)); + shared.zpopmin = makeObjectShared(createStringObject("ZPOPMIN",7)); + shared.zpopmax = makeObjectShared(createStringObject("ZPOPMAX",7)); for (j = 0; j < OBJ_SHARED_INTEGERS; j++) { shared.integers[j] = makeObjectShared(createObject(OBJ_STRING,(void*)(long)j)); shared.integers[j]->encoding = OBJ_ENCODING_INT; } for (j = 0; j < OBJ_SHARED_BULKHDR_LEN; j++) { - shared.mbulkhdr[j] = createObject(OBJ_STRING, - sdscatprintf(sdsempty(),"*%d\r\n",j)); - shared.bulkhdr[j] = createObject(OBJ_STRING, - sdscatprintf(sdsempty(),"$%d\r\n",j)); + shared.mbulkhdr[j] = makeObjectShared(createObject(OBJ_STRING, + sdscatprintf(sdsempty(),"*%d\r\n",j))); + shared.bulkhdr[j] = makeObjectShared(createObject(OBJ_STRING, + sdscatprintf(sdsempty(),"$%d\r\n",j))); } /* The following two shared objects, minstring and maxstrings, are not * actually used for their value but as a special object meaning From c8516f3dc484920de4fc52acd72f5104d643ca87 Mon Sep 17 00:00:00 2001 From: John Sully Date: Wed, 17 Jul 2019 02:34:02 -0400 Subject: [PATCH 2/2] Fix Issue #58 --- src/server.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/server.cpp b/src/server.cpp index e1d0aa5da..c425933a4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2934,6 +2934,18 @@ void initServer(void) { g_pserver->db[j].defrag_later = listCreate(); } + /* Fixup Master Client Database */ + listIter li; + listNode *ln; + listRewind(g_pserver->masters, &li); + while ((ln = listNext(&li))) + { + redisMaster *mi = (redisMaster*)listNodeValue(ln); + serverAssert(mi->master == nullptr); + if (mi->cached_master != nullptr) + selectDb(mi->cached_master, 0); + } + if (g_pserver->syslog_enabled) { openlog(g_pserver->syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT, g_pserver->syslog_facility);