Merge branch 'unstable' of https://github.com/antirez/redis into Multithread

This commit is contained in:
John Sully 2019-02-22 21:16:10 -05:00
commit 8b72fe935e
3 changed files with 28 additions and 35 deletions

View File

@ -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,41 +1293,38 @@ 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);
return C_OK;
sdsfree(acl);
return retval;
}
/* This function is called once the server is already running, modules are
@ -1372,7 +1371,7 @@ void ACLLoadUsersAtStartup(void) {
* ACL USERS
* ACL CAT [<category>]
* ACL SETUSER <username> ... acl rules ...
* ACL DELUSER <username>
* ACL DELUSER <username> [...]
* ACL GETUSER <username>
*/
void aclCommand(client *c) {
@ -1400,6 +1399,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),
@ -1546,7 +1549,7 @@ void aclCommand(client *c) {
"USERS -- List all the registered usernames.",
"SETUSER <username> [attribs ...] -- Create or modify a user.",
"GETUSER <username> -- Get the user details.",
"DELUSER <username> -- Delete a user.",
"DELUSER <username> [...] -- Delete a list of users.",
"CAT -- List available categories.",
"CAT <category> -- List commands inside category.",
"WHOAMI -- Return the current connection username.",

View File

@ -862,23 +862,7 @@ void addReplyNullArray(client *c) {
/* Create the length prefix of a bulk reply, example: $2234 */
void addReplyBulkLenCore(client *c, robj *obj, bool fAsync) {
size_t len;
if (sdsEncodedObject(obj)) {
len = sdslen((sds)ptrFromObj(obj));
} else {
long n = (long)ptrFromObj(obj);
/* 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)
addReplyCore(c,shared.bulkhdr[len], fAsync);

View File

@ -4930,6 +4930,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++) {