From 297950e8b817dbf3f2dbbbff497fdf3a047cc8f2 Mon Sep 17 00:00:00 2001 From: hujiecs <2844633656@qq.com> Date: Tue, 16 Oct 2018 15:48:03 +0800 Subject: [PATCH 1/4] several typos fixed, optimize MSETNX to avoid unnecessary loop --- src/atomicvar.h | 2 +- src/intset.c | 2 +- src/object.c | 2 +- src/quicklist.h | 2 +- src/t_string.c | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/atomicvar.h b/src/atomicvar.h index 173b045f..160056cd 100644 --- a/src/atomicvar.h +++ b/src/atomicvar.h @@ -1,7 +1,7 @@ /* This file implements atomic counters using __atomic or __sync macros if * available, otherwise synchronizing different threads using a mutex. * - * The exported interaface is composed of three macros: + * The exported interface is composed of three macros: * * atomicIncr(var,count) -- Increment the atomic counter * atomicGetIncr(var,oldvalue_var,count) -- Get and increment the atomic counter diff --git a/src/intset.c b/src/intset.c index 198c90aa..4445a5ca 100644 --- a/src/intset.c +++ b/src/intset.c @@ -123,7 +123,7 @@ static uint8_t intsetSearch(intset *is, int64_t value, uint32_t *pos) { } else { /* Check for the case where we know we cannot find the value, * but do know the insert position. */ - if (value > _intsetGet(is,intrev32ifbe(is->length)-1)) { + if (value > _intsetGet(is,max)) { if (pos) *pos = intrev32ifbe(is->length); return 0; } else if (value < _intsetGet(is,0)) { diff --git a/src/object.c b/src/object.c index 6987e1e6..7c98a6ef 100644 --- a/src/object.c +++ b/src/object.c @@ -185,7 +185,7 @@ robj *createStringObjectFromLongDouble(long double value, int humanfriendly) { /* Duplicate a string object, with the guarantee that the returned object * has the same encoding as the original one. * - * This function also guarantees that duplicating a small integere object + * This function also guarantees that duplicating a small integer object * (or a string object that contains a representation of a small integer) * will always result in a fresh object that is unshared (refcount == 1). * diff --git a/src/quicklist.h b/src/quicklist.h index 955a22cf..a7e27a2d 100644 --- a/src/quicklist.h +++ b/src/quicklist.h @@ -40,7 +40,7 @@ * container: 2 bits, NONE=1, ZIPLIST=2. * recompress: 1 bit, bool, true if node is temporarry decompressed for usage. * attempted_compress: 1 bit, boolean, used for verifying during testing. - * extra: 12 bits, free for future use; pads out the remainder of 32 bits */ + * extra: 10 bits, free for future use; pads out the remainder of 32 bits */ typedef struct quicklistNode { struct quicklistNode *prev; struct quicklistNode *next; diff --git a/src/t_string.c b/src/t_string.c index e121df73..2afedc30 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -313,6 +313,7 @@ void msetGenericCommand(client *c, int nx) { for (j = 1; j < c->argc; j += 2) { if (lookupKeyWrite(c->db,c->argv[j]) != NULL) { busykeys++; + break; } } if (busykeys) { From a6499ecac21e685c9d95dc749cd928412d4f689b Mon Sep 17 00:00:00 2001 From: youjiali1995 Date: Thu, 18 Oct 2018 18:57:51 +0800 Subject: [PATCH 2/4] migrate: fix mismatch of RESTORE reply when some keys have expired. --- src/cluster.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index e82f256c..7620b178 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -5164,10 +5164,10 @@ try_again: serverAssertWithInfo(c,NULL,rioWriteBulkLongLong(&cmd,dbid)); } - int expired = 0; /* Number of keys that we'll find already expired. - Note that serializing large keys may take some time - so certain keys that were found non expired by the - lookupKey() function, may be expired later. */ + int non_expired = 0; /* Number of keys that we'll find non expired. + Note that serializing large keys may take some time + so certain keys that were found non expired by the + lookupKey() function, may be expired later. */ /* Create RESTORE payload and generate the protocol to call the command. */ for (j = 0; j < num_keys; j++) { @@ -5177,11 +5177,12 @@ try_again: if (expireat != -1) { ttl = expireat-mstime(); if (ttl < 0) { - expired++; continue; } if (ttl < 1) ttl = 1; } + kv[non_expired++] = kv[j]; + serverAssertWithInfo(c,NULL, rioWriteBulkCount(&cmd,'*',replace ? 5 : 4)); @@ -5208,6 +5209,7 @@ try_again: if (replace) serverAssertWithInfo(c,NULL,rioWriteBulkString(&cmd,"REPLACE",7)); } + num_keys = non_expired; /* Transfer the query to the other node in 64K chunks. */ errno = 0; @@ -5250,7 +5252,7 @@ try_again: * command name itself. */ if (!copy) newargv = zmalloc(sizeof(robj*)*(num_keys+1)); - for (j = 0; j < num_keys-expired; j++) { + for (j = 0; j < num_keys; j++) { if (syncReadLine(cs->fd, buf2, sizeof(buf2), timeout) <= 0) { socket_error = 1; break; From 63e41ee19236d88799935e38e517b2a918cacbb3 Mon Sep 17 00:00:00 2001 From: hujie <2844633656@qq.com> Date: Sat, 20 Oct 2018 12:18:56 +0800 Subject: [PATCH 3/4] fix typo --- src/db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index ec92a2b4..536f8af6 100644 --- a/src/db.c +++ b/src/db.c @@ -206,7 +206,7 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) { * 2) clients WATCHing for the destination key notified. * 3) The expire time of the key is reset (the key is made persistent). * - * All the new keys in the database should be craeted via this interface. */ + * All the new keys in the database should be creted via this interface. */ void setKey(redisDb *db, robj *key, robj *val) { if (lookupKeyWrite(db,key) == NULL) { dbAdd(db,key,val); From e610dbce14af98cbac60ee53248788e80f1ec6a0 Mon Sep 17 00:00:00 2001 From: hujie <2844633656@qq.com> Date: Sun, 21 Oct 2018 10:37:36 +0800 Subject: [PATCH 4/4] fix typo in config.c --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 86548bc8..d1bfaa3f 100644 --- a/src/config.c +++ b/src/config.c @@ -120,7 +120,7 @@ const char *configEnumGetName(configEnum *ce, int val) { return NULL; } -/* Wrapper for configEnumGetName() returning "unknown" insetad of NULL if +/* Wrapper for configEnumGetName() returning "unknown" instead of NULL if * there is no match. */ const char *configEnumGetNameOrUnknown(configEnum *ce, int val) { const char *name = configEnumGetName(ce,val);