Merge branch 'unstable' of https://github.com/antirez/redis into Multithread
This commit is contained in:
commit
8b72fe935e
39
src/acl.c
39
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. */
|
* When C_ERR is returned a log is produced with hints about the issue. */
|
||||||
int ACLSaveToFile(const char *filename) {
|
int ACLSaveToFile(const char *filename) {
|
||||||
sds acl = sdsempty();
|
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
|
/* Let's generate an SDS string containing the new version of the
|
||||||
* ACL file. */
|
* ACL file. */
|
||||||
@ -1291,41 +1293,38 @@ int ACLSaveToFile(const char *filename) {
|
|||||||
raxStop(&ri);
|
raxStop(&ri);
|
||||||
|
|
||||||
/* Create a temp file with the new content. */
|
/* Create a temp file with the new content. */
|
||||||
sds tmpfilename = sdsnew(filename);
|
tmpfilename = sdsnew(filename);
|
||||||
tmpfilename = sdscatfmt(tmpfilename,".tmp-%i-%I",
|
tmpfilename = sdscatfmt(tmpfilename,".tmp-%i-%I",
|
||||||
(int)getpid(),(int)mstime());
|
(int)getpid(),(int)mstime());
|
||||||
if ((fd = open(tmpfilename,O_WRONLY|O_CREAT,0644)) == -1) {
|
if ((fd = open(tmpfilename,O_WRONLY|O_CREAT,0644)) == -1) {
|
||||||
serverLog(LL_WARNING,"Opening temp ACL file for ACL SAVE: %s",
|
serverLog(LL_WARNING,"Opening temp ACL file for ACL SAVE: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
sdsfree(tmpfilename);
|
goto cleanup;
|
||||||
sdsfree(acl);
|
|
||||||
return C_ERR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write it. */
|
/* Write it. */
|
||||||
if (write(fd,acl,sdslen(acl)) != (ssize_t)sdslen(acl)) {
|
if (write(fd,acl,sdslen(acl)) != (ssize_t)sdslen(acl)) {
|
||||||
serverLog(LL_WARNING,"Writing ACL file for ACL SAVE: %s",
|
serverLog(LL_WARNING,"Writing ACL file for ACL SAVE: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
close(fd);
|
goto cleanup;
|
||||||
unlink(tmpfilename);
|
|
||||||
sdsfree(tmpfilename);
|
|
||||||
sdsfree(acl);
|
|
||||||
return C_ERR;
|
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd); fd = -1;
|
||||||
sdsfree(acl);
|
|
||||||
|
|
||||||
/* Let's replace the new file with the old one. */
|
/* Let's replace the new file with the old one. */
|
||||||
if (rename(tmpfilename,filename) == -1) {
|
if (rename(tmpfilename,filename) == -1) {
|
||||||
serverLog(LL_WARNING,"Renaming ACL file for ACL SAVE: %s",
|
serverLog(LL_WARNING,"Renaming ACL file for ACL SAVE: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
unlink(tmpfilename);
|
goto cleanup;
|
||||||
sdsfree(tmpfilename);
|
|
||||||
return C_ERR;
|
|
||||||
}
|
}
|
||||||
|
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(tmpfilename);
|
||||||
return C_OK;
|
sdsfree(acl);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is called once the server is already running, modules are
|
/* This function is called once the server is already running, modules are
|
||||||
@ -1372,7 +1371,7 @@ void ACLLoadUsersAtStartup(void) {
|
|||||||
* ACL USERS
|
* ACL USERS
|
||||||
* ACL CAT [<category>]
|
* ACL CAT [<category>]
|
||||||
* ACL SETUSER <username> ... acl rules ...
|
* ACL SETUSER <username> ... acl rules ...
|
||||||
* ACL DELUSER <username>
|
* ACL DELUSER <username> [...]
|
||||||
* ACL GETUSER <username>
|
* ACL GETUSER <username>
|
||||||
*/
|
*/
|
||||||
void aclCommand(client *c) {
|
void aclCommand(client *c) {
|
||||||
@ -1400,6 +1399,10 @@ void aclCommand(client *c) {
|
|||||||
addReplyError(c,"The 'default' user cannot be removed");
|
addReplyError(c,"The 'default' user cannot be removed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 2; j < c->argc; j++) {
|
||||||
|
sds username = c->argv[j]->ptr;
|
||||||
user *u;
|
user *u;
|
||||||
if (raxRemove(Users,(unsigned char*)username,
|
if (raxRemove(Users,(unsigned char*)username,
|
||||||
sdslen(username),
|
sdslen(username),
|
||||||
@ -1546,7 +1549,7 @@ void aclCommand(client *c) {
|
|||||||
"USERS -- List all the registered usernames.",
|
"USERS -- List all the registered usernames.",
|
||||||
"SETUSER <username> [attribs ...] -- Create or modify a user.",
|
"SETUSER <username> [attribs ...] -- Create or modify a user.",
|
||||||
"GETUSER <username> -- Get the user details.",
|
"GETUSER <username> -- Get the user details.",
|
||||||
"DELUSER <username> -- Delete a user.",
|
"DELUSER <username> [...] -- Delete a list of users.",
|
||||||
"CAT -- List available categories.",
|
"CAT -- List available categories.",
|
||||||
"CAT <category> -- List commands inside category.",
|
"CAT <category> -- List commands inside category.",
|
||||||
"WHOAMI -- Return the current connection username.",
|
"WHOAMI -- Return the current connection username.",
|
||||||
|
@ -862,23 +862,7 @@ void addReplyNullArray(client *c) {
|
|||||||
|
|
||||||
/* Create the length prefix of a bulk reply, example: $2234 */
|
/* Create the length prefix of a bulk reply, example: $2234 */
|
||||||
void addReplyBulkLenCore(client *c, robj *obj, bool fAsync) {
|
void addReplyBulkLenCore(client *c, robj *obj, bool fAsync) {
|
||||||
size_t len;
|
size_t len = stringObjectLen(obj);
|
||||||
|
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len < OBJ_SHARED_BULKHDR_LEN)
|
if (len < OBJ_SHARED_BULKHDR_LEN)
|
||||||
addReplyCore(c,shared.bulkhdr[len], fAsync);
|
addReplyCore(c,shared.bulkhdr[len], fAsync);
|
||||||
|
@ -4930,6 +4930,12 @@ static int clusterManagerCommandCreate(int argc, char **argv) {
|
|||||||
cursor += slots_per_node;
|
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;
|
int assign_unused = 0, available_count = interleaved_len;
|
||||||
assign_replicas:
|
assign_replicas:
|
||||||
for (i = 0; i < masters_count; i++) {
|
for (i = 0; i < masters_count; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user