diff options
author | Madelyn Olson <34459052+madolson@users.noreply.github.com> | 2021-02-09 11:52:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 11:52:28 -0800 |
commit | 899c85ae67631f4f9f866a254ac5e149b86e5529 (patch) | |
tree | c5986f36c294b3ed45103c03489728cea7b734ef /src | |
parent | 4554a49d32c5c0921f251262f2fbe02d7ac64b59 (diff) | |
download | redis-899c85ae67631f4f9f866a254ac5e149b86e5529.tar.gz |
Moved most static strings into the shared structure (#8411)
Moved most static strings into the shared structure
Diffstat (limited to 'src')
-rw-r--r-- | src/acl.c | 6 | ||||
-rw-r--r-- | src/aof.c | 3 | ||||
-rw-r--r-- | src/object.c | 17 | ||||
-rw-r--r-- | src/replication.c | 3 | ||||
-rw-r--r-- | src/scripting.c | 7 | ||||
-rw-r--r-- | src/server.c | 40 | ||||
-rw-r--r-- | src/server.h | 7 | ||||
-rw-r--r-- | src/t_hash.c | 6 | ||||
-rw-r--r-- | src/t_set.c | 9 | ||||
-rw-r--r-- | src/t_stream.c | 37 | ||||
-rw-r--r-- | src/t_string.c | 6 |
11 files changed, 61 insertions, 80 deletions
@@ -2253,7 +2253,7 @@ void authCommand(client *c) { return; } - username = createStringObject("default",7); + username = shared.default_username; password = c->argv[1]; } else { username = c->argv[1]; @@ -2265,9 +2265,5 @@ void authCommand(client *c) { } else { addReplyError(c,"-WRONGPASS invalid username-password pair or user is disabled."); } - - /* Free the "default" string object we created for the two - * arguments form. */ - if (c->argc == 2) decrRefCount(username); } @@ -588,11 +588,10 @@ sds catAppendOnlyExpireAtCommand(sds buf, struct redisCommand *cmd, robj *key, r } decrRefCount(seconds); - argv[0] = createStringObject("PEXPIREAT",9); + argv[0] = shared.pexpireat; argv[1] = key; argv[2] = createStringObjectFromLongLong(when); buf = catAppendOnlyGenericCommand(buf, 3, argv); - decrRefCount(argv[0]); decrRefCount(argv[2]); return buf; } diff --git a/src/object.c b/src/object.c index 8573ef0b5..ce2f3dc14 100644 --- a/src/object.c +++ b/src/object.c @@ -384,23 +384,6 @@ void decrRefCountVoid(void *o) { decrRefCount(o); } -/* This function set the ref count to zero without freeing the object. - * It is useful in order to pass a new object to functions incrementing - * the ref count of the received object. Example: - * - * functionThatWillIncrementRefCount(resetRefCount(CreateObject(...))); - * - * Otherwise you need to resort to the less elegant pattern: - * - * *obj = createObject(...); - * functionThatWillIncrementRefCount(obj); - * decrRefCount(obj); - */ -robj *resetRefCount(robj *obj) { - obj->refcount = 0; - return obj; -} - int checkType(client *c, robj *o, int type) { /* A NULL is considered an empty key */ if (o && o->type != type) { diff --git a/src/replication.c b/src/replication.c index f23fcb6de..90fa6c782 100644 --- a/src/replication.c +++ b/src/replication.c @@ -3333,10 +3333,9 @@ void replicationCron(void) { checkClientPauseTimeoutAndReturnIfPaused(); if (!manual_failover_in_progress) { - ping_argv[0] = createStringObject("PING",4); + ping_argv[0] = shared.ping; replicationFeedSlaves(server.slaves, server.slaveseldb, ping_argv, 1); - decrRefCount(ping_argv[0]); } } diff --git a/src/scripting.c b/src/scripting.c index 41469ee2e..e23d49e8b 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -1668,12 +1668,11 @@ void evalGenericCommand(client *c, int evalsha) { * or just running a CPU costly read-only script on the slaves. */ if (server.dirty == initial_server_dirty) { rewriteClientCommandVector(c,3, - resetRefCount(createStringObject("SCRIPT",6)), - resetRefCount(createStringObject("LOAD",4)), + shared.script, + shared.load, script); } else { - rewriteClientCommandArgument(c,0, - resetRefCount(createStringObject("EVAL",4))); + rewriteClientCommandArgument(c,0,shared.eval); rewriteClientCommandArgument(c,1,script); } forceCommandPropagation(c,PROPAGATE_REPL|PROPAGATE_AOF); diff --git a/src/server.c b/src/server.c index faaca7215..bc0eb8255 100644 --- a/src/server.c +++ b/src/server.c @@ -2418,13 +2418,10 @@ void beforeSleep(struct aeEventLoop *eventLoop) { if (server.get_ack_from_slaves && !checkClientPauseTimeoutAndReturnIfPaused()) { robj *argv[3]; - argv[0] = createStringObject("REPLCONF",8); - argv[1] = createStringObject("GETACK",6); - argv[2] = createStringObject("*",1); /* Not used argument. */ + argv[0] = shared.replconf; + argv[1] = shared.getack; + argv[2] = shared.special_asterick; /* Not used argument. */ replicationFeedSlaves(server.slaves, server.slaveseldb, argv, 3); - decrRefCount(argv[0]); - decrRefCount(argv[1]); - decrRefCount(argv[2]); server.get_ack_from_slaves = 0; } @@ -2565,6 +2562,8 @@ void createSharedObjects(void) { 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 command names */ shared.del = createStringObject("DEL",3); shared.unlink = createStringObject("UNLINK",6); shared.rpop = createStringObject("RPOP",4); @@ -2577,15 +2576,38 @@ void createSharedObjects(void) { shared.zpopmax = createStringObject("ZPOPMAX",7); shared.multi = createStringObject("MULTI",5); shared.exec = createStringObject("EXEC",4); - /* Used in the LMOVE/BLMOVE commands */ - shared.left = createStringObject("left",4); - shared.right = createStringObject("right",5); + shared.hset = createStringObject("HSET",4); + shared.srem = createStringObject("SREM",4); + shared.xgroup = createStringObject("XGROUP",6); + shared.xclaim = createStringObject("XCLAIM",6); + shared.script = createStringObject("SCRIPT",6); + shared.replconf = createStringObject("REPLCONF",8); shared.pexpireat = createStringObject("PEXPIREAT",9); shared.pexpire = createStringObject("PEXPIRE",7); shared.persist = createStringObject("PERSIST",7); shared.set = createStringObject("SET",3); + shared.eval = createStringObject("EVAL",4); + + /* Shared command argument */ + shared.left = createStringObject("left",4); + shared.right = createStringObject("right",5); shared.pxat = createStringObject("PXAT", 4); shared.px = createStringObject("PX",2); + shared.time = createStringObject("TIME",4); + shared.retrycount = createStringObject("RETRYCOUNT",10); + shared.force = createStringObject("FORCE",5); + shared.justid = createStringObject("JUSTID",6); + shared.lastid = createStringObject("LASTID",6); + shared.default_username = createStringObject("default",7); + shared.ping = createStringObject("ping",7); + shared.setid = createStringObject("SETID",5); + shared.keepttl = createStringObject("KEEPTTL",7); + shared.load = createStringObject("LOAD",4); + shared.createconsumer = createStringObject("CREATECONSUMER",14); + shared.getack = createStringObject("GETACK",6); + shared.special_asterick = createStringObject("*",1); + shared.special_equals = createStringObject("=",1); + for (j = 0; j < OBJ_SHARED_INTEGERS; j++) { shared.integers[j] = makeObjectShared(createObject(OBJ_STRING,(void*)(long)j)); diff --git a/src/server.h b/src/server.h index b293afcee..7140c4571 100644 --- a/src/server.h +++ b/src/server.h @@ -976,8 +976,11 @@ struct sharedObjectsStruct { *busykeyerr, *oomerr, *plus, *messagebulk, *pmessagebulk, *subscribebulk, *unsubscribebulk, *psubscribebulk, *punsubscribebulk, *del, *unlink, *rpop, *lpop, *lpush, *rpoplpush, *lmove, *blmove, *zpopmin, *zpopmax, - *emptyscan, *multi, *exec, *left, *right, *persist, *set, *pexpireat, - *pexpire, *pxat, *px, + *emptyscan, *multi, *exec, *left, *right, *hset, *srem, *xgroup, *xclaim, + *script, *replconf, *eval, *persist, *set, *pexpireat, *pexpire, + *time, *pxat, *px, *retrycount, *force, *justid, + *lastid, *ping, *setid, *keepttl, *load, *createconsumer, + *getack, *special_asterick, *special_equals, *default_username, *select[PROTO_SHARED_SELECT_CMDS], *integers[OBJ_SHARED_INTEGERS], *mbulkhdr[OBJ_SHARED_BULKHDR_LEN], /* "*<value>\r\n" */ diff --git a/src/t_hash.c b/src/t_hash.c index 082e0f129..cae350566 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -759,11 +759,9 @@ void hincrbyfloatCommand(client *c) { /* Always replicate HINCRBYFLOAT as an HSET command with the final value * in order to make sure that differences in float precision or formatting * will not create differences in replicas or after an AOF restart. */ - robj *aux, *newobj; - aux = createStringObject("HSET",4); + robj *newobj; newobj = createRawStringObject(buf,len); - rewriteClientCommandArgument(c,0,aux); - decrRefCount(aux); + rewriteClientCommandArgument(c,0,shared.hset); rewriteClientCommandArgument(c,3,newobj); decrRefCount(newobj); } diff --git a/src/t_set.c b/src/t_set.c index de0a9f954..f7a05206d 100644 --- a/src/t_set.c +++ b/src/t_set.c @@ -499,7 +499,7 @@ void spopWithCountCommand(client *c) { * Prepare our replication argument vector. Also send the array length * which is common to both the code paths. */ robj *propargv[3]; - propargv[0] = createStringObject("SREM",4); + propargv[0] = shared.srem; propargv[1] = c->argv[1]; addReplySetLen(c,count); @@ -590,13 +590,12 @@ void spopWithCountCommand(client *c) { * dirty counter. We don't want to propagate an SPOP command since * we propagated the command as a set of SREMs operations using * the alsoPropagate() API. */ - decrRefCount(propargv[0]); preventCommandPropagation(c); signalModifiedKey(c,c->db,c->argv[1]); } void spopCommand(client *c) { - robj *set, *ele, *aux; + robj *set, *ele; sds sdsele; int64_t llele; int encoding; @@ -629,9 +628,7 @@ void spopCommand(client *c) { notifyKeyspaceEvent(NOTIFY_SET,"spop",c->argv[1],c->db->id); /* Replicate/AOF this command as an SREM operation */ - aux = createStringObject("SREM",4); - rewriteClientCommandVector(c,3,aux,c->argv[1],ele); - decrRefCount(aux); + rewriteClientCommandVector(c,3,shared.srem,c->argv[1],ele); /* Add the element to the reply */ addReplyBulk(c,ele); diff --git a/src/t_stream.c b/src/t_stream.c index 32bfa1f7d..7b4ffe3c4 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -1328,19 +1328,19 @@ void streamPropagateXCLAIM(client *c, robj *key, streamCG *group, robj *groupnam * Note that JUSTID is useful in order to avoid that XCLAIM will do * useless work in the slave side, trying to fetch the stream item. */ robj *argv[14]; - argv[0] = createStringObject("XCLAIM",6); + argv[0] = shared.xclaim; argv[1] = key; argv[2] = groupname; argv[3] = createStringObject(nack->consumer->name,sdslen(nack->consumer->name)); - argv[4] = createStringObjectFromLongLong(0); + argv[4] = shared.integers[0]; argv[5] = id; - argv[6] = createStringObject("TIME",4); + argv[6] = shared.time; argv[7] = createStringObjectFromLongLong(nack->delivery_time); - argv[8] = createStringObject("RETRYCOUNT",10); + argv[8] = shared.retrycount; argv[9] = createStringObjectFromLongLong(nack->delivery_count); - argv[10] = createStringObject("FORCE",5); - argv[11] = createStringObject("JUSTID",6); - argv[12] = createStringObject("LASTID",6); + argv[10] = shared.force; + argv[11] = shared.justid; + argv[12] = shared.lastid; argv[13] = createObjectFromStreamID(&group->last_id); /* We use progagate() because this code path is not always called from @@ -1348,16 +1348,9 @@ void streamPropagateXCLAIM(client *c, robj *key, streamCG *group, robj *groupnam * consumer group state, and we don't need MULTI/EXEC wrapping because * there is no message state cross-message atomicity required. */ propagate(server.xclaimCommand,c->db->id,argv,14,PROPAGATE_AOF|PROPAGATE_REPL); - decrRefCount(argv[0]); decrRefCount(argv[3]); - decrRefCount(argv[4]); - decrRefCount(argv[6]); decrRefCount(argv[7]); - decrRefCount(argv[8]); decrRefCount(argv[9]); - decrRefCount(argv[10]); - decrRefCount(argv[11]); - decrRefCount(argv[12]); decrRefCount(argv[13]); } @@ -1369,8 +1362,8 @@ void streamPropagateXCLAIM(client *c, robj *key, streamCG *group, robj *groupnam */ void streamPropagateGroupID(client *c, robj *key, streamCG *group, robj *groupname) { robj *argv[5]; - argv[0] = createStringObject("XGROUP",6); - argv[1] = createStringObject("SETID",5); + argv[0] = shared.xgroup; + argv[1] = shared.setid; argv[2] = key; argv[3] = groupname; argv[4] = createObjectFromStreamID(&group->last_id); @@ -1380,8 +1373,6 @@ void streamPropagateGroupID(client *c, robj *key, streamCG *group, robj *groupna * consumer group state, and we don't need MULTI/EXEC wrapping because * there is no message state cross-message atomicity required. */ propagate(server.xgroupCommand,c->db->id,argv,5,PROPAGATE_AOF|PROPAGATE_REPL); - decrRefCount(argv[0]); - decrRefCount(argv[1]); decrRefCount(argv[4]); } @@ -1393,8 +1384,8 @@ void streamPropagateGroupID(client *c, robj *key, streamCG *group, robj *groupna */ void streamPropagateConsumerCreation(client *c, robj *key, robj *groupname, sds consumername) { robj *argv[5]; - argv[0] = createStringObject("XGROUP",6); - argv[1] = createStringObject("CREATECONSUMER",14); + argv[0] = shared.xgroup; + argv[1] = shared.createconsumer; argv[2] = key; argv[3] = groupname; argv[4] = createObject(OBJ_STRING,sdsdup(consumername)); @@ -1404,8 +1395,6 @@ void streamPropagateConsumerCreation(client *c, robj *key, robj *groupname, sds * consumer group state, and we don't need MULTI/EXEC wrapping because * there is no message state cross-message atomicity required. */ propagate(server.xgroupCommand,c->db->id,argv,5,PROPAGATE_AOF|PROPAGATE_REPL); - decrRefCount(argv[0]); - decrRefCount(argv[1]); decrRefCount(argv[4]); } @@ -1725,9 +1714,7 @@ int streamParseIntervalIDOrReply(client *c, robj *o, streamID *id, int *exclude, } void streamRewriteApproxSpecifier(client *c, int idx) { - robj *equal_obj = createStringObject("=",1); - rewriteClientCommandArgument(c,idx,equal_obj); - decrRefCount(equal_obj); + rewriteClientCommandArgument(c,idx,shared.special_equals); } /* We propagate MAXLEN/MINID ~ <count> as MAXLEN/MINID = <resulting-len-of-stream> diff --git a/src/t_string.c b/src/t_string.c index d05366b7c..6a3b256b8 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -631,7 +631,7 @@ void decrbyCommand(client *c) { void incrbyfloatCommand(client *c) { long double incr, value; - robj *o, *new, *aux; + robj *o, *new; o = lookupKeyWrite(c->db,c->argv[1]); if (checkType(c,o,OBJ_STRING)) return; @@ -659,9 +659,7 @@ void incrbyfloatCommand(client *c) { * will not create differences in replicas or after an AOF restart. */ rewriteClientCommandArgument(c,0,shared.set); rewriteClientCommandArgument(c,2,new); - aux = createStringObject("KEEPTTL",7); - rewriteClientCommandArgument(c,3,aux); - decrRefCount(aux); + rewriteClientCommandArgument(c,3,shared.keepttl); } void appendCommand(client *c) { |