From 0f28754021a66f2fe77dee1dd712220a741dc203 Mon Sep 17 00:00:00 2001 From: artix Date: Wed, 20 Feb 2019 15:36:12 +0100 Subject: [PATCH 1/5] Cluster Manager: fix replica assigment anti-affinity (create) Fix issue #5849 --- src/redis-cli.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/redis-cli.c b/src/redis-cli.c index 93290e5ed..1203c2eff 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -4918,6 +4918,12 @@ static int clusterManagerCommandCreate(int argc, char **argv) { cursor += slots_per_node; } + /* Rotating the list sometimes helps to get better initial + * anti-affinity before the optimizer runs. */ + clusterManagerNode *first_node = interleaved[0]; + for (i = 0; i < (interleaved_len - 1); i++) + interleaved[i] = interleaved[i + 1]; + interleaved[interleaved_len - 1] = first_node; int assign_unused = 0, available_count = interleaved_len; assign_replicas: for (i = 0; i < masters_count; i++) { From fdc4003d23dfc287380174f219548c12bee07475 Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Thu, 21 Feb 2019 00:34:54 +0000 Subject: [PATCH 2/5] Making deleting users better defined and update documentation --- src/acl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/acl.c b/src/acl.c index 407d86736..d6c54e00f 100644 --- a/src/acl.c +++ b/src/acl.c @@ -1304,7 +1304,7 @@ void ACLLoadUsersAtStartup(void) { * ACL USERS * ACL CAT [] * ACL SETUSER ... acl rules ... - * ACL DELUSER + * ACL DELUSER [...] * ACL GETUSER */ void aclCommand(client *c) { @@ -1332,6 +1332,10 @@ void aclCommand(client *c) { addReplyError(c,"The 'default' user cannot be removed"); return; } + } + + for (int j = 2; j < c->argc; j++) { + sds username = c->argv[j]->ptr; user *u; if (raxRemove(Users,(unsigned char*)username, sdslen(username), @@ -1469,7 +1473,7 @@ void aclCommand(client *c) { "USERS -- List all the registered usernames.", "SETUSER [attribs ...] -- Create or modify a user.", "GETUSER -- Get the user details.", -"DELUSER -- Delete a user.", +"DELUSER [...] -- Delete a list of users.", "CAT -- List available categories.", "CAT -- List commands inside category.", "WHOAMI -- Return the current connection username.", From 9131fc56d69cb4bb2bf2e5d29636f22c3036f4e9 Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Wed, 20 Feb 2019 03:52:57 +0000 Subject: [PATCH 3/5] Refactored manual computation of object length --- src/networking.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/networking.c b/src/networking.c index 23bc97eec..599d69bef 100644 --- a/src/networking.c +++ b/src/networking.c @@ -636,23 +636,7 @@ void addReplyNullArray(client *c) { /* Create the length prefix of a bulk reply, example: $2234 */ void addReplyBulkLen(client *c, robj *obj) { - size_t len; - - if (sdsEncodedObject(obj)) { - len = sdslen(obj->ptr); - } else { - long n = (long)obj->ptr; - - /* Compute how many bytes will take this integer as a radix 10 string */ - len = 1; - if (n < 0) { - len++; - n = -n; - } - while((n = n/10) != 0) { - len++; - } - } + size_t len = stringObjectLen(obj); if (len < OBJ_SHARED_BULKHDR_LEN) addReply(c,shared.bulkhdr[len]); From 2bea3929d0ba3ba066185102c14370e4269213e6 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 22 Feb 2019 12:41:57 +0100 Subject: [PATCH 4/5] ACL: less error prone error handling in ACLSaveToFile(). --- src/acl.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/acl.c b/src/acl.c index cdf1b907b..f74567f2e 100644 --- a/src/acl.c +++ b/src/acl.c @@ -1268,7 +1268,9 @@ sds ACLLoadFromFile(const char *filename) { * When C_ERR is returned a log is produced with hints about the issue. */ int ACLSaveToFile(const char *filename) { sds acl = sdsempty(); - int fd; + int fd = -1; + sds tmpfilename = NULL; + int retval = C_ERR; /* Let's generate an SDS string containing the new version of the * ACL file. */ @@ -1291,40 +1293,37 @@ int ACLSaveToFile(const char *filename) { raxStop(&ri); /* Create a temp file with the new content. */ - sds tmpfilename = sdsnew(filename); + tmpfilename = sdsnew(filename); tmpfilename = sdscatfmt(tmpfilename,".tmp-%i-%I", (int)getpid(),(int)mstime()); if ((fd = open(tmpfilename,O_WRONLY|O_CREAT,0644)) == -1) { serverLog(LL_WARNING,"Opening temp ACL file for ACL SAVE: %s", strerror(errno)); - sdsfree(tmpfilename); - sdsfree(acl); - return C_ERR; + goto cleanup; } /* Write it. */ if (write(fd,acl,sdslen(acl)) != (ssize_t)sdslen(acl)) { serverLog(LL_WARNING,"Writing ACL file for ACL SAVE: %s", strerror(errno)); - close(fd); - unlink(tmpfilename); - sdsfree(tmpfilename); - sdsfree(acl); - return C_ERR; + goto cleanup; } - close(fd); - sdsfree(acl); + close(fd); fd = -1; /* Let's replace the new file with the old one. */ if (rename(tmpfilename,filename) == -1) { serverLog(LL_WARNING,"Renaming ACL file for ACL SAVE: %s", strerror(errno)); - unlink(tmpfilename); - sdsfree(tmpfilename); - return C_ERR; + goto cleanup; } + sdsfree(tmpfilename); tmpfilename = NULL; + retval = C_OK; /* If we reached this point, everything is fine. */ +cleanup: + if (fd != -1) close(fd); + if (tmpfilename) unlink(tmpfilename); sdsfree(tmpfilename); + sdsfree(acl); return C_OK; } From 07473feaebd9af228baddd6c28ded0da42dab255 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 22 Feb 2019 12:45:13 +0100 Subject: [PATCH 5/5] ACL: fix ACLSaveToFile() return value. --- src/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/acl.c b/src/acl.c index f74567f2e..43db19898 100644 --- a/src/acl.c +++ b/src/acl.c @@ -1324,7 +1324,7 @@ cleanup: if (tmpfilename) unlink(tmpfilename); sdsfree(tmpfilename); sdsfree(acl); - return C_OK; + return retval; } /* This function is called once the server is already running, modules are