Skip to content

Commit

Permalink
Merge branch 'valkey-io:unstable' into unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
PingXie authored May 13, 2024
2 parents 303346b + c7ad9fe commit 3a4de02
Show file tree
Hide file tree
Showing 76 changed files with 1,258 additions and 873 deletions.
12 changes: 12 additions & 0 deletions src/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Don't format files copied from other sources.
lzf*
crccombine.*
crcspeed.*
mt19937-64.*
pqsort.*
setcpuaffinity.c
setproctitle.c
sha1.*
sha256.*
siphash.c
strl.c
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ $(ENGINE_LIB_NAME): $(ENGINE_SERVER_OBJ)

# valkey-unit-tests
$(ENGINE_UNIT_TESTS): $(ENGINE_TEST_OBJ) $(ENGINE_LIB_NAME)
$(SERVER_LD) $(ALLOW_DUPLICATE_FLAG) -o $@ $^ ../deps/fpconv/libfpconv.a $(FINAL_LIBS)
$(SERVER_LD) $(ALLOW_DUPLICATE_FLAG) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS)

# valkey-sentinel
$(ENGINE_SENTINEL_NAME): $(SERVER_NAME)
Expand Down
24 changes: 18 additions & 6 deletions src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ user *DefaultUser; /* Global reference to the default user.
different user. */

list *UsersToLoad; /* This is a list of users found in the configuration file
that we'll need to load in the final stage of Redis
that we'll need to load in the final stage of the server
initialization, after all the modules are already
loaded. Every list element is a NULL terminated
array of SDS pointers: the first is the user name,
Expand Down Expand Up @@ -1601,10 +1601,12 @@ static int ACLSelectorCheckKey(aclSelector *selector, const char *key, int keyle
listRewind(selector->patterns,&li);

int key_flags = 0;
/* clang-format off */
if (keyspec_flags & CMD_KEY_ACCESS) key_flags |= ACL_READ_PERMISSION;
if (keyspec_flags & CMD_KEY_INSERT) key_flags |= ACL_WRITE_PERMISSION;
if (keyspec_flags & CMD_KEY_DELETE) key_flags |= ACL_WRITE_PERMISSION;
if (keyspec_flags & CMD_KEY_UPDATE) key_flags |= ACL_WRITE_PERMISSION;
/* clang-format on */

/* Test this key against every pattern. */
while((ln = listNext(&li))) {
Expand Down Expand Up @@ -1632,10 +1634,12 @@ static int ACLSelectorHasUnrestrictedKeyAccess(aclSelector *selector, int flags)
listRewind(selector->patterns,&li);

int access_flags = 0;
/* clang-format off */
if (flags & CMD_KEY_ACCESS) access_flags |= ACL_READ_PERMISSION;
if (flags & CMD_KEY_INSERT) access_flags |= ACL_WRITE_PERMISSION;
if (flags & CMD_KEY_DELETE) access_flags |= ACL_WRITE_PERMISSION;
if (flags & CMD_KEY_UPDATE) access_flags |= ACL_WRITE_PERMISSION;
/* clang-format on */

/* Test this key against every pattern. */
while((ln = listNext(&li))) {
Expand Down Expand Up @@ -2700,13 +2704,15 @@ void addACLLogEntry(client *c, int reason, int context, int argpos, sds username
if (object) {
le->object = object;
} else {
/* clang-format off */
switch(reason) {
case ACL_DENIED_CMD: le->object = sdsdup(c->cmd->fullname); break;
case ACL_DENIED_KEY: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_CHANNEL: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_AUTH: le->object = sdsdup(c->argv[0]->ptr); break;
default: le->object = sdsempty();
case ACL_DENIED_CMD: le->object = sdsdup(c->cmd->fullname); break;
case ACL_DENIED_KEY: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_CHANNEL: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_AUTH: le->object = sdsdup(c->argv[0]->ptr); break;
default: le->object = sdsempty();
}
/* clang-format on */
}

/* if we have a real client from the network, use it (could be missing on module timers) */
Expand Down Expand Up @@ -3090,24 +3096,28 @@ void aclCommand(client *c) {

addReplyBulkCString(c,"reason");
char *reasonstr;
/* clang-format off */
switch(le->reason) {
case ACL_DENIED_CMD: reasonstr="command"; break;
case ACL_DENIED_KEY: reasonstr="key"; break;
case ACL_DENIED_CHANNEL: reasonstr="channel"; break;
case ACL_DENIED_AUTH: reasonstr="auth"; break;
default: reasonstr="unknown";
}
/* clang-format on */
addReplyBulkCString(c,reasonstr);

addReplyBulkCString(c,"context");
char *ctxstr;
/* clang-format off */
switch(le->context) {
case ACL_LOG_CTX_TOPLEVEL: ctxstr="toplevel"; break;
case ACL_LOG_CTX_MULTI: ctxstr="multi"; break;
case ACL_LOG_CTX_LUA: ctxstr="lua"; break;
case ACL_LOG_CTX_MODULE: ctxstr="module"; break;
default: ctxstr="unknown";
}
/* clang-format on */
addReplyBulkCString(c,ctxstr);

addReplyBulkCString(c,"object");
Expand Down Expand Up @@ -3156,6 +3166,7 @@ void aclCommand(client *c) {

addReply(c,shared.ok);
} else if (c->argc == 2 && !strcasecmp(sub,"help")) {
/* clang-format off */
const char *help[] = {
"CAT [<category>]",
" List all commands that belong to <category>, or all command categories",
Expand Down Expand Up @@ -3185,6 +3196,7 @@ void aclCommand(client *c) {
" Return the current connection username.",
NULL
};
/* clang-format on */
addReplyHelp(c,help);
} else {
addReplySubcommandSyntaxError(c);
Expand Down
2 changes: 1 addition & 1 deletion src/anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ int anetFdToString(int fd, char *ip, size_t ip_len, int *port, int remote) {
* and one of the use cases is O_CLOEXEC|O_NONBLOCK. */
int anetPipe(int fds[2], int read_flags, int write_flags) {
int pipe_flags = 0;
#if defined(__linux__) || defined(__FreeBSD__)
#ifdef HAVE_PIPE2
/* When possible, try to leverage pipe2() to apply flags that are common to both ends.
* There is no harm to set O_CLOEXEC to prevent fd leaks. */
pipe_flags = O_CLOEXEC | (read_flags & write_flags);
Expand Down
6 changes: 4 additions & 2 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <sys/wait.h>
#include <sys/param.h>

void freeClientArgv(client *c);
off_t getAppendOnlyFileSize(sds filename, int *status);
off_t getBaseAndIncrAppendOnlyFilesSize(aofManifest *am, int *status);
int getBaseAndIncrAppendOnlyFilesNum(aofManifest *am);
Expand Down Expand Up @@ -701,7 +700,6 @@ void aofDelTempIncrAofFile(void) {
bg_unlink(aof_filepath);
sdsfree(aof_filepath);
sdsfree(aof_filename);
return;
}

/* Called after `loadDataFromDisk` when the server starts. If `server.aof_state` is
Expand Down Expand Up @@ -2035,6 +2033,7 @@ int rioWriteStreamPendingEntry(rio *r, robj *key, const char *groupname, size_t
RETRYCOUNT <count> JUSTID FORCE. */
streamID id;
streamDecodeID(rawid,&id);
/* clang-format off */
if (rioWriteBulkCount(r,'*',12) == 0) return 0;
if (rioWriteBulkString(r,"XCLAIM",6) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
Expand All @@ -2048,6 +2047,7 @@ int rioWriteStreamPendingEntry(rio *r, robj *key, const char *groupname, size_t
if (rioWriteBulkLongLong(r,nack->delivery_count) == 0) return 0;
if (rioWriteBulkString(r,"JUSTID",6) == 0) return 0;
if (rioWriteBulkString(r,"FORCE",5) == 0) return 0;
/* clang-format on */
return 1;
}

Expand All @@ -2056,12 +2056,14 @@ int rioWriteStreamPendingEntry(rio *r, robj *key, const char *groupname, size_t
* All this in the context of the specified key and group. */
int rioWriteStreamEmptyConsumer(rio *r, robj *key, const char *groupname, size_t groupname_len, streamConsumer *consumer) {
/* XGROUP CREATECONSUMER <key> <group> <consumer> */
/* clang-format off */
if (rioWriteBulkCount(r,'*',5) == 0) return 0;
if (rioWriteBulkString(r,"XGROUP",6) == 0) return 0;
if (rioWriteBulkString(r,"CREATECONSUMER",14) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
if (rioWriteBulkString(r,groupname,groupname_len) == 0) return 0;
if (rioWriteBulkString(r,consumer->name,sdslen(consumer->name)) == 0) return 0;
/* clang-format on */
return 1;
}

Expand Down
3 changes: 3 additions & 0 deletions src/asciilogo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2024, Valkey contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -27,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

/* clang-format off */
const char *ascii_logo =
" .+^+. \n"
" .+#########+. \n"
Expand All @@ -47,3 +49,4 @@ const char *ascii_logo =
" '| |####+########+' \n"
" +#########+' \n"
" '+v+' \n\n";
/* clang-format off */
4 changes: 2 additions & 2 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6320,7 +6320,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out,
return 1;
}

void clusterSetSlotCommand(client *c) {
void clusterCommandSetSlot(client *c) {
int slot;
int timeout_ms;
clusterNode *n;
Expand Down Expand Up @@ -6575,7 +6575,7 @@ int clusterCommandSpecial(client *c) {
/* SETSLOT 10 IMPORTING <node ID> */
/* SETSLOT 10 STABLE */
/* SETSLOT 10 NODE <node ID> */
clusterSetSlotCommand(c);
clusterCommandSetSlot(c);
} else if (!strcasecmp(c->argv[1]->ptr,"bumpepoch") && c->argc == 2) {
/* CLUSTER BUMPEPOCH */
int retval = clusterBumpConfigEpochWithoutConsensus();
Expand Down
16 changes: 15 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,21 @@
#define HAVE_ACCEPT4 1
#endif

#if (defined(__APPLE__) && defined(MAC_OS_10_6_DETECTED)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__)
/* Detect for pipe2() */
#if defined(__linux__) || \
defined(__FreeBSD__) || \
defined(OpenBSD5_7) || \
(defined(__DragonFly__) && __DragonFly_version >= 400106) || \
(defined(__NetBSD__) && (defined(NetBSD6_0) || __NetBSD_Version__ >= 600000000))
#define HAVE_PIPE2 1
#endif

/* Detect for kqueue */
#if (defined(__APPLE__) && defined(MAC_OS_10_6_DETECTED)) || \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined (__NetBSD__)
#define HAVE_KQUEUE 1
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/crccombine.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void gf2_matrix_square(uint64_t *square, uint64_t *mat, uint8_t dim) {
square[n] = CRC_MULTIPLY(mat, mat[n]);
}

/* Turns out our Redis / Jones CRC cycles at this point, so we can support
/* Turns out our Jones CRC cycles at this point, so we can support
* more than 64 bits of extension if we want. Trivially. */
static uint64_t combine_cache[64][64];

Expand Down Expand Up @@ -204,7 +204,7 @@ void init_combine_cache(uint64_t poly, uint8_t dim) {
gf2_matrix_square(combine_cache[1], combine_cache[0], dim);

/* do/while to overwrite the first two layers, they are not used, but are
* re-generated in the last two layers for the Redis polynomial */
* re-generated in the last two layers for the crc polynomial */
do {
gf2_matrix_square(combine_cache[cache_num], combine_cache[cache_num + prev], dim);
prev = -1;
Expand Down
8 changes: 6 additions & 2 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,9 @@ int getKeysUsingKeySpecs(struct serverCommand *cmd, robj **argv, int argc, int s
if (cmd->flags & CMD_MODULE || cmd->arity < 0) {
continue;
} else {
serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
serverPanic("%s built-in command declared keys positions"
" not matching the arity requirements.",
server.extended_redis_compat ? "Redis" : "Valkey");
}
}
keys[result->numkeys].pos = i;
Expand Down Expand Up @@ -2276,7 +2278,9 @@ int getKeysUsingLegacyRangeSpec(struct serverCommand *cmd, robj **argv, int argc
result->numkeys = 0;
return 0;
} else {
serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
serverPanic("%s built-in command declared keys positions"
" not matching the arity requirements.",
server.extended_redis_compat ? "Redis" : "Valkey");
}
}
keys[i].pos = j;
Expand Down
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ void logServerInfo(void) {
robj *argv[1];
argv[0] = createStringObject("all", strlen("all"));
dict *section_dict = genInfoSectionDict(argv, 1, NULL, &all, &everything);
infostring = genRedisInfoString(section_dict, all, everything);
infostring = genValkeyInfoString(section_dict, all, everything);
if (server.cluster_enabled){
infostring = genClusterDebugString(infostring);
}
Expand Down
27 changes: 0 additions & 27 deletions src/endianconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,3 @@ uint64_t intrev64(uint64_t v) {
memrev64(&v);
return v;
}

#ifdef SERVER_TEST
#include <stdio.h>

#define UNUSED(x) (void)(x)
int endianconvTest(int argc, char *argv[], int flags) {
char buf[32];

UNUSED(argc);
UNUSED(argv);
UNUSED(flags);

snprintf(buf,sizeof(buf),"ciaoroma");
memrev16(buf);
printf("%s\n", buf);

snprintf(buf,sizeof(buf),"ciaoroma");
memrev32(buf);
printf("%s\n", buf);

snprintf(buf,sizeof(buf),"ciaoroma");
memrev64(buf);
printf("%s\n", buf);

return 0;
}
#endif
5 changes: 0 additions & 5 deletions src/endianconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,4 @@ uint64_t intrev64(uint64_t v);
#define htonu64(v) intrev64(v)
#define ntohu64(v) intrev64(v)
#endif

#ifdef SERVER_TEST
int endianconvTest(int argc, char *argv[], int flags);
#endif

#endif
8 changes: 6 additions & 2 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,16 @@ void evalShaRoCommand(client *c) {

void scriptCommand(client *c) {
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) {
/* clang-format off */
const char *help[] = {
"DEBUG (YES|SYNC|NO)",
" Set the debug mode for subsequent scripts executed.",
"EXISTS <sha1> [<sha1> ...]",
" Return information about the existence of the scripts in the script cache.",
"FLUSH [ASYNC|SYNC]",
" Flush the Lua scripts cache. Very dangerous on replicas.",
" When called without the optional mode argument, the behavior is determined by the",
" lazyfree-lazy-user-flush configuration directive. Valid modes are:",
" When called without the optional mode argument, the behavior is determined",
" by the lazyfree-lazy-user-flush configuration directive. Valid modes are:",
" * ASYNC: Asynchronously flush the scripts cache.",
" * SYNC: Synchronously flush the scripts cache.",
"KILL",
Expand All @@ -692,6 +693,7 @@ void scriptCommand(client *c) {
" Load a script into the scripts cache without executing it.",
NULL
};
/* clang-format on */
addReplyHelp(c, help);
} else if (c->argc >= 2 && !strcasecmp(c->argv[1]->ptr,"flush")) {
int async = 0;
Expand Down Expand Up @@ -1251,6 +1253,7 @@ char *ldbRedisProtocolToHuman_Double(sds *o, char *reply);
* char*) so that we can return a modified pointer, as for SDS semantics. */
char *ldbRedisProtocolToHuman(sds *o, char *reply) {
char *p = reply;
/* clang-format off */
switch(*p) {
case ':': p = ldbRedisProtocolToHuman_Int(o,reply); break;
case '$': p = ldbRedisProtocolToHuman_Bulk(o,reply); break;
Expand All @@ -1263,6 +1266,7 @@ char *ldbRedisProtocolToHuman(sds *o, char *reply) {
case '#': p = ldbRedisProtocolToHuman_Bool(o,reply); break;
case ',': p = ldbRedisProtocolToHuman_Double(o,reply); break;
}
/* clang-format on */
return p;
}

Expand Down
2 changes: 2 additions & 0 deletions src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ void functionFlushCommand(client *c) {

/* FUNCTION HELP */
void functionHelpCommand(client *c) {
/* clang-format off */
const char *help[] = {
"LOAD [REPLACE] <FUNCTION CODE>",
" Create a new library with the given library name and code.",
Expand Down Expand Up @@ -864,6 +865,7 @@ void functionHelpCommand(client *c) {
" libraries with the new libraries (notice that even on this option there is a chance of failure",
" in case of functions name collision with another library).",
NULL };
/* clang-format on */
addReplyHelp(c, help);
}

Expand Down
4 changes: 0 additions & 4 deletions src/intset.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ uint32_t intsetLen(const intset *is);
size_t intsetBlobLen(intset *is);
int intsetValidateIntegrity(const unsigned char *is, size_t size, int deep);

#ifdef SERVER_TEST
int intsetTest(int argc, char *argv[], int flags);
#endif

#endif // __INTSET_H
Loading

0 comments on commit 3a4de02

Please sign in to comment.