Skip to content

Commit

Permalink
Merge branch 'unstable' of https://github.com/adetunjii/valkey into f…
Browse files Browse the repository at this point in the history
…ix/format-yaml
  • Loading branch information
adetunjii committed Jun 13, 2024
2 parents 8bc3c5a + d211078 commit 8eb17f1
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 188 deletions.
4 changes: 4 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# License 1

BSD 3-Clause License

Copyright (c) 2024-present, Valkey contributors
All rights reserved.

Expand All @@ -13,6 +15,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

# License 2

BSD 3-Clause License

Copyright (c) 2006-2020, Salvatore Sanfilippo
All rights reserved.

Expand Down
5 changes: 5 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ DEBUG=-g -ggdb
# Linux ARM32 needs -latomic at linking time
ifneq (,$(findstring armv,$(uname_M)))
FINAL_LIBS+=-latomic
else
# Linux POWER needs -latomic at linking time
ifneq (,$(findstring ppc,$(uname_M)))
FINAL_LIBS+=-latomic
endif
endif

ifeq ($(uname_S),SunOS)
Expand Down
40 changes: 15 additions & 25 deletions src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void ACLFreeUserAndKillClients(user *u) {
* more defensive to set the default user and put
* it in non authenticated mode. */
c->user = DefaultUser;
c->authenticated = 0;
c->flags &= ~CLIENT_AUTHENTICATED;
/* We will write replies to this client later, so we can't
* close it directly even if async. */
if (c == server.current_client) {
Expand Down Expand Up @@ -1494,7 +1494,7 @@ void addAuthErrReply(client *c, robj *err) {
* The return value is AUTH_OK on success (valid username / password pair) & AUTH_ERR otherwise. */
int checkPasswordBasedAuth(client *c, robj *username, robj *password) {
if (ACLCheckUserCredentials(username, password) == C_OK) {
c->authenticated = 1;
c->flags |= CLIENT_AUTHENTICATED;
c->user = ACLGetUserByName(username->ptr, sdslen(username->ptr));
moduleNotifyUserChanged(c);
return AUTH_OK;
Expand Down Expand Up @@ -1587,12 +1587,10 @@ 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 All @@ -1618,12 +1616,10 @@ 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 @@ -2669,15 +2665,13 @@ void addACLLogEntry(client *c, int reason, int context, int argpos, sds username
if (object) {
le->object = object;
} else {
/* clang-format off */
switch(reason) {
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();
}
/* clang-format on */
}

/* if we have a real client from the network, use it (could be missing on module timers) */
Expand Down Expand Up @@ -3058,28 +3052,24 @@ 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";
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";
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
42 changes: 19 additions & 23 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1994,21 +1994,19 @@ int rioWriteStreamPendingEntry(rio *r,
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;
if (rioWriteBulkString(r,groupname,groupname_len) == 0) return 0;
if (rioWriteBulkString(r,consumer->name,sdslen(consumer->name)) == 0) return 0;
if (rioWriteBulkString(r,"0",1) == 0) return 0;
if (rioWriteBulkStreamID(r,&id) == 0) return 0;
if (rioWriteBulkString(r,"TIME",4) == 0) return 0;
if (rioWriteBulkLongLong(r,nack->delivery_time) == 0) return 0;
if (rioWriteBulkString(r,"RETRYCOUNT",10) == 0) return 0;
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 */
if (rioWriteBulkCount(r, '*', 12) == 0) return 0;
if (rioWriteBulkString(r, "XCLAIM", 6) == 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;
if (rioWriteBulkString(r, "0", 1) == 0) return 0;
if (rioWriteBulkStreamID(r, &id) == 0) return 0;
if (rioWriteBulkString(r, "TIME", 4) == 0) return 0;
if (rioWriteBulkLongLong(r, nack->delivery_time) == 0) return 0;
if (rioWriteBulkString(r, "RETRYCOUNT", 10) == 0) return 0;
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;
return 1;
}

Expand All @@ -2021,14 +2019,12 @@ int rioWriteStreamEmptyConsumer(rio *r,
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 */
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;
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -4888,7 +4888,7 @@ void bitmapClearBit(unsigned char *bitmap, int pos) {
* MIGRATE_TO flag the when a primary gets the first slot. */
int clusterPrimariesHaveReplicas(void) {
dictIterator di;
dictInitSafeIterator(&di, server.cluster->nodes);
dictInitIterator(&di, server.cluster->nodes);
dictEntry *de;
int replicas = 0;
while ((de = dictNext(&di)) != NULL) {
Expand Down Expand Up @@ -6509,7 +6509,7 @@ void clusterPromoteSelfToPrimary(void) {

int detectAndUpdateCachedNodeHealth(void) {
dictIterator di;
dictInitSafeIterator(&di, server.cluster->nodes);
dictInitIterator(&di, server.cluster->nodes);
dictEntry *de;
clusterNode *node;
int overall_health_changed = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -966,13 +966,13 @@ struct COMMAND_STRUCT CLUSTER_Subcommands[] = {
{MAKE_CMD("forget","Removes a node from the nodes table.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_FORGET_History,0,CLUSTER_FORGET_Tips,0,clusterCommand,3,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_FORGET_Keyspecs,0,NULL,1),.args=CLUSTER_FORGET_Args},
{MAKE_CMD("getkeysinslot","Returns the key names in a hash slot.","O(N) where N is the number of requested keys","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_GETKEYSINSLOT_History,0,CLUSTER_GETKEYSINSLOT_Tips,1,clusterCommand,4,CMD_STALE,0,CLUSTER_GETKEYSINSLOT_Keyspecs,0,NULL,2),.args=CLUSTER_GETKEYSINSLOT_Args},
{MAKE_CMD("help","Returns helpful text about the different subcommands.","O(1)","5.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_HELP_History,0,CLUSTER_HELP_Tips,0,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_HELP_Keyspecs,0,NULL,0)},
{MAKE_CMD("info","Returns information about the state of a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_INFO_History,0,CLUSTER_INFO_Tips,1,clusterCommand,2,CMD_STALE,0,CLUSTER_INFO_Keyspecs,0,NULL,0)},
{MAKE_CMD("info","Returns information about the state of a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_INFO_History,0,CLUSTER_INFO_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_INFO_Keyspecs,0,NULL,0)},
{MAKE_CMD("keyslot","Returns the hash slot for a key.","O(N) where N is the number of bytes in the key","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_KEYSLOT_History,0,CLUSTER_KEYSLOT_Tips,0,clusterCommand,3,CMD_STALE,0,CLUSTER_KEYSLOT_Keyspecs,0,NULL,1),.args=CLUSTER_KEYSLOT_Args},
{MAKE_CMD("links","Returns a list of all TCP links to and from peer nodes.","O(N) where N is the total number of Cluster nodes","7.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_LINKS_History,0,CLUSTER_LINKS_Tips,1,clusterCommand,2,CMD_STALE,0,CLUSTER_LINKS_Keyspecs,0,NULL,0)},
{MAKE_CMD("meet","Forces a node to handshake with another node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_MEET_History,1,CLUSTER_MEET_Tips,0,clusterCommand,-4,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_MEET_Keyspecs,0,NULL,3),.args=CLUSTER_MEET_Args},
{MAKE_CMD("myid","Returns the ID of a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_MYID_History,0,CLUSTER_MYID_Tips,0,clusterCommand,2,CMD_STALE,0,CLUSTER_MYID_Keyspecs,0,NULL,0)},
{MAKE_CMD("myshardid","Returns the shard ID of a node.","O(1)","7.2.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_MYSHARDID_History,0,CLUSTER_MYSHARDID_Tips,1,clusterCommand,2,CMD_STALE,0,CLUSTER_MYSHARDID_Keyspecs,0,NULL,0)},
{MAKE_CMD("nodes","Returns the cluster configuration for a node.","O(N) where N is the total number of Cluster nodes","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_NODES_History,0,CLUSTER_NODES_Tips,1,clusterCommand,2,CMD_STALE,0,CLUSTER_NODES_Keyspecs,0,NULL,0)},
{MAKE_CMD("myid","Returns the ID of a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_MYID_History,0,CLUSTER_MYID_Tips,0,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_MYID_Keyspecs,0,NULL,0)},
{MAKE_CMD("myshardid","Returns the shard ID of a node.","O(1)","7.2.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_MYSHARDID_History,0,CLUSTER_MYSHARDID_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_MYSHARDID_Keyspecs,0,NULL,0)},
{MAKE_CMD("nodes","Returns the cluster configuration for a node.","O(N) where N is the total number of Cluster nodes","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_NODES_History,0,CLUSTER_NODES_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_NODES_Keyspecs,0,NULL,0)},
{MAKE_CMD("replicas","Lists the replica nodes of a master node.","O(N) where N is the number of replicas.","5.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_REPLICAS_History,0,CLUSTER_REPLICAS_Tips,1,clusterCommand,3,CMD_ADMIN|CMD_STALE,0,CLUSTER_REPLICAS_Keyspecs,0,NULL,1),.args=CLUSTER_REPLICAS_Args},
{MAKE_CMD("replicate","Configure a node as replica of a master node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_REPLICATE_History,0,CLUSTER_REPLICATE_Tips,0,clusterCommand,3,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_REPLICATE_Keyspecs,0,NULL,1),.args=CLUSTER_REPLICATE_Args},
{MAKE_CMD("reset","Resets a node.","O(N) where N is the number of known nodes. The command may execute a FLUSHALL as a side effect.","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_RESET_History,0,CLUSTER_RESET_Tips,0,clusterCommand,-2,CMD_ADMIN|CMD_STALE|CMD_NOSCRIPT,0,CLUSTER_RESET_Keyspecs,0,NULL,1),.args=CLUSTER_RESET_Args},
Expand Down
1 change: 1 addition & 0 deletions src/commands/cluster-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"container": "CLUSTER",
"function": "clusterCommand",
"command_flags": [
"LOADING",
"STALE"
],
"command_tips": [
Expand Down
1 change: 1 addition & 0 deletions src/commands/cluster-myid.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"container": "CLUSTER",
"function": "clusterCommand",
"command_flags": [
"LOADING",
"STALE"
],
"reply_schema": {
Expand Down
1 change: 1 addition & 0 deletions src/commands/cluster-myshardid.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"container": "CLUSTER",
"function": "clusterCommand",
"command_flags": [
"LOADING",
"STALE"
],
"command_tips": [
Expand Down
1 change: 1 addition & 0 deletions src/commands/cluster-nodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"container": "CLUSTER",
"function": "clusterCommand",
"command_flags": [
"LOADING",
"STALE"
],
"command_tips": [
Expand Down
6 changes: 3 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,11 @@ void rewriteConfigSaveOption(standardConfig *config, const char *name, struct re
if (!server.saveparamslen) {
rewriteConfigRewriteLine(state, name, sdsnew("save \"\""), 1);
} else {
line = sdsnew(name);
for (j = 0; j < server.saveparamslen; j++) {
line = sdscatprintf(sdsempty(), "save %ld %d", (long)server.saveparams[j].seconds,
server.saveparams[j].changes);
rewriteConfigRewriteLine(state, name, line, 1);
line = sdscatprintf(line, " %ld %d", (long)server.saveparams[j].seconds, server.saveparams[j].changes);
}
rewriteConfigRewriteLine(state, name, line, 1);
}

/* Mark "save" as processed in case server.saveparamslen is zero. */
Expand Down
9 changes: 7 additions & 2 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@ unsigned long long dictFingerprint(dict *d) {
return hash;
}

/* Initiaize a normal iterator. This function should be called when initializing
* an iterator on the stack. */
void dictInitIterator(dictIterator *iter, dict *d) {
iter->d = d;
iter->table = 0;
Expand All @@ -952,16 +954,19 @@ void dictInitIterator(dictIterator *iter, dict *d) {
iter->nextEntry = NULL;
}

/* Initialize a safe iterator, which is allowed to modify the dictionary while iterating.
* You must call dictResetIterator when you are done with a safe iterator. */
void dictInitSafeIterator(dictIterator *iter, dict *d) {
dictInitIterator(iter, d);
iter->safe = 1;
}

void dictResetIterator(dictIterator *iter) {
if (!(iter->index == -1 && iter->table == 0)) {
if (iter->safe)
if (iter->safe) {
dictResumeRehashing(iter->d);
else
assert(iter->d->pauserehash >= 0);
} else
assert(iter->fingerprint == dictFingerprint(iter->d));
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,20 +1221,18 @@ char *ldbRespToHuman_Double(sds *o, char *reply);
* char*) so that we can return a modified pointer, as for SDS semantics. */
char *ldbRespToHuman(sds *o, char *reply) {
char *p = reply;
/* clang-format off */
switch(*p) {
case ':': p = ldbRespToHuman_Int(o,reply); break;
case '$': p = ldbRespToHuman_Bulk(o,reply); break;
case '+': p = ldbRespToHuman_Status(o,reply); break;
case '-': p = ldbRespToHuman_Status(o,reply); break;
case '*': p = ldbRespToHuman_MultiBulk(o,reply); break;
case '~': p = ldbRespToHuman_Set(o,reply); break;
case '%': p = ldbRespToHuman_Map(o,reply); break;
case '_': p = ldbRespToHuman_Null(o,reply); break;
case '#': p = ldbRespToHuman_Bool(o,reply); break;
case ',': p = ldbRespToHuman_Double(o,reply); break;
switch (*p) {
case ':': p = ldbRespToHuman_Int(o, reply); break;
case '$': p = ldbRespToHuman_Bulk(o, reply); break;
case '+': p = ldbRespToHuman_Status(o, reply); break;
case '-': p = ldbRespToHuman_Status(o, reply); break;
case '*': p = ldbRespToHuman_MultiBulk(o, reply); break;
case '~': p = ldbRespToHuman_Set(o, reply); break;
case '%': p = ldbRespToHuman_Map(o, reply); break;
case '_': p = ldbRespToHuman_Null(o, reply); break;
case '#': p = ldbRespToHuman_Bool(o, reply); break;
case ',': p = ldbRespToHuman_Double(o, reply); break;
}
/* clang-format on */
return p;
}

Expand Down
11 changes: 3 additions & 8 deletions src/kvstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

#define UNUSED(V) ((void)V)

static dict *kvstoreIteratorNextDict(kvstoreIterator *kvs_it);

struct _kvstore {
int flags;
dictType dtype;
Expand Down Expand Up @@ -572,7 +574,7 @@ void kvstoreIteratorRelease(kvstoreIterator *kvs_it) {
}

/* Returns next dictionary from the iterator, or NULL if iteration is complete. */
dict *kvstoreIteratorNextDict(kvstoreIterator *kvs_it) {
static dict *kvstoreIteratorNextDict(kvstoreIterator *kvs_it) {
if (kvs_it->next_didx == -1) return NULL;

/* The dict may be deleted during the iteration process, so here need to check for NULL. */
Expand Down Expand Up @@ -600,13 +602,6 @@ dictEntry *kvstoreIteratorNext(kvstoreIterator *kvs_it) {
if (!de) { /* No current dict or reached the end of the dictionary. */
dict *d = kvstoreIteratorNextDict(kvs_it);
if (!d) return NULL;
if (kvs_it->di.d) {
/* Before we move to the next dict, reset the iter of the previous dict. */
dictIterator *iter = &kvs_it->di;
dictResetIterator(iter);
/* In the safe iterator context, we may delete entries. */
freeDictIfNeeded(kvs_it->kvs, kvs_it->didx);
}
dictInitSafeIterator(&kvs_it->di, d);
de = dictNext(&kvs_it->di);
}
Expand Down
1 change: 0 additions & 1 deletion src/kvstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ uint64_t kvstoreGetHash(kvstore *kvs, const void *key);
/* kvstore iterator specific functions */
kvstoreIterator *kvstoreIteratorInit(kvstore *kvs);
void kvstoreIteratorRelease(kvstoreIterator *kvs_it);
dict *kvstoreIteratorNextDict(kvstoreIterator *kvs_it);
int kvstoreIteratorGetCurrentDictIndex(kvstoreIterator *kvs_it);
dictEntry *kvstoreIteratorNext(kvstoreIterator *kvs_it);

Expand Down
Loading

0 comments on commit 8eb17f1

Please sign in to comment.