Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 100
PenaltyExcessCharacter: 100
MaxEmptyLinesToKeep: 2
BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BraceWrapping:
AfterControlStatement: MultiLine
AfterFunction: false
AfterStruct: false
AfterEnum: false
AfterUnion: false
BeforeElse: false
BeforeCatch: false
SplitEmptyFunction: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
Expand Down
9 changes: 6 additions & 3 deletions src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,8 @@ static int ACLCheckChannelAgainstList(list *reference, const char *channel, int
/* Channel patterns are matched literally against the channels in
* the list. Regular channels perform pattern matching. */
if ((is_pattern && !strcmp(pattern, channel)) ||
(!is_pattern && stringmatchlen(pattern, plen, channel, channellen, 0))) {
(!is_pattern && stringmatchlen(pattern, plen, channel, channellen, 0)))
{
return ACL_OK;
}
}
Expand Down Expand Up @@ -2662,7 +2663,8 @@ static sds ACLLoadFromFile(const char *filename) {
user *new_user = ACLGetUserByName(c->user->name, sdslen(c->user->name));
if (new_user && user_channels) {
if (!raxFind(user_channels, (unsigned char *)(new_user->name), sdslen(new_user->name),
(void **)&channels)) {
(void **)&channels))
{
channels = getUpcomingChannelList(new_user, original);
raxInsert(user_channels, (unsigned char *)(new_user->name), sdslen(new_user->name), channels, NULL);
}
Expand Down Expand Up @@ -2920,7 +2922,8 @@ void addACLLogEntry(client *c, int reason, int context, int argpos, sds username
le->cinfo = catClientInfoString(sdsempty(), realclient, 0);

if (context == ACL_LOG_CTX_SCRIPT &&
strcmp(scriptGetRunningEngineName(), "LUA") == 0) {
strcmp(scriptGetRunningEngineName(), "LUA") == 0)
{
/* For backward compatibility, we track that it's Lua using a special
* lua ACL log context. Any other scripting language is just "script" in
* the ACL log. */
Expand Down
3 changes: 2 additions & 1 deletion src/anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ int anetRetryAcceptOnError(int err) {
and ENETUNREACH. */
if (err == ENETDOWN || err == EPROTO || err == ENOPROTOOPT ||
err == EHOSTDOWN || err == ENONET || err == EHOSTUNREACH ||
err == EOPNOTSUPP || err == ENETUNREACH) {
err == EOPNOTSUPP || err == ENETUNREACH)
{
return 1;
}
#endif
Expand Down
45 changes: 30 additions & 15 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ void aofUpgradePrepare(aofManifest *am) {
*/
int aofDelHistoryFiles(void) {
if (server.aof_manifest == NULL || server.aof_disable_auto_gc == 1 ||
!listLength(server.aof_manifest->history_aof_list)) {
!listLength(server.aof_manifest->history_aof_list))
{
return C_OK;
}

Expand Down Expand Up @@ -1187,15 +1188,17 @@ void flushAppendOnlyFile(int force) {
* stop write commands before fsync called in one second,
* the data in page cache cannot be flushed in time. */
if (server.aof_fsync == AOF_FSYNC_EVERYSEC && server.aof_last_incr_fsync_offset != server.aof_last_incr_size &&
server.mstime - server.aof_last_fsync >= 1000 && !(sync_in_progress = aofFsyncInProgress())) {
server.mstime - server.aof_last_fsync >= 1000 && !(sync_in_progress = aofFsyncInProgress()))
{
goto try_fsync;

/* Check if we need to do fsync even the aof buffer is empty,
* the reason is described in the previous AOF_FSYNC_EVERYSEC block,
* and AOF_FSYNC_ALWAYS is also checked here to handle a case where
* aof_fsync is changed from everysec to always. */
} else if (server.aof_fsync == AOF_FSYNC_ALWAYS &&
server.aof_last_incr_fsync_offset != server.aof_last_incr_size) {
server.aof_last_incr_fsync_offset != server.aof_last_incr_size)
{
goto try_fsync;
} else {
/* All data is fsync'd already: Update fsynced_reploff_pending just in case.
Expand Down Expand Up @@ -1791,7 +1794,8 @@ int loadAppendOnlyFiles(aofManifest *am) {
if (fileExist(server.aof_filename)) {
if (!dirExists(server.aof_dirname) || (am->base_aof_info == NULL && listLength(am->incr_aof_list) == 0) ||
(am->base_aof_info != NULL && listLength(am->incr_aof_list) == 0 &&
!strcmp(am->base_aof_info->file_name, server.aof_filename) && !aofFileExist(server.aof_filename))) {
!strcmp(am->base_aof_info->file_name, server.aof_filename) && !aofFileExist(server.aof_filename)))
{
aofUpgradePrepare(am);
}
}
Expand Down Expand Up @@ -1923,7 +1927,8 @@ int rewriteListObject(rio *r, robj *key, robj *o) {
if (count == 0) {
int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? AOF_REWRITE_ITEMS_PER_CMD : items;
if (!rioWriteBulkCount(r, '*', 2 + cmd_items) || !rioWriteBulkString(r, "RPUSH", 5) ||
!rioWriteBulkObject(r, key)) {
!rioWriteBulkObject(r, key))
{
listTypeReleaseIterator(li);
return 0;
}
Expand Down Expand Up @@ -1963,7 +1968,8 @@ int rewriteSetObject(rio *r, robj *key, robj *o) {
if (count == 0) {
int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? AOF_REWRITE_ITEMS_PER_CMD : items;
if (!rioWriteBulkCount(r, '*', 2 + cmd_items) || !rioWriteBulkString(r, "SADD", 4) ||
!rioWriteBulkObject(r, key)) {
!rioWriteBulkObject(r, key))
{
setTypeReleaseIterator(si);
return 0;
}
Expand Down Expand Up @@ -2006,7 +2012,8 @@ int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? AOF_REWRITE_ITEMS_PER_CMD : items;

if (!rioWriteBulkCount(r, '*', 2 + cmd_items * 2) || !rioWriteBulkString(r, "ZADD", 4) ||
!rioWriteBulkObject(r, key)) {
!rioWriteBulkObject(r, key))
{
return 0;
}
}
Expand All @@ -2031,7 +2038,8 @@ int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? AOF_REWRITE_ITEMS_PER_CMD : items;

if (!rioWriteBulkCount(r, '*', 2 + cmd_items * 2) || !rioWriteBulkString(r, "ZADD", 4) ||
!rioWriteBulkObject(r, key)) {
!rioWriteBulkObject(r, key))
{
hashtableCleanupIterator(&iter);
return 0;
}
Expand Down Expand Up @@ -2114,7 +2122,8 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
int cmd_items = (non_volatile_items > AOF_REWRITE_ITEMS_PER_CMD) ? AOF_REWRITE_ITEMS_PER_CMD : non_volatile_items;

if (!rioWriteBulkCount(r, '*', 2 + cmd_items * 2) || !rioWriteBulkString(r, "HMSET", 5) ||
!rioWriteBulkObject(r, key)) {
!rioWriteBulkObject(r, key))
{
hashTypeResetIterator(&hi);
return 0;
}
Expand Down Expand Up @@ -2209,7 +2218,8 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {

/* Emit the XADD <key> <id> ...fields... command. */
if (!rioWriteBulkCount(r, '*', 3 + numfields * 2) || !rioWriteBulkString(r, "XADD", 4) ||
!rioWriteBulkObject(r, key) || !rioWriteBulkStreamID(r, &id)) {
!rioWriteBulkObject(r, key) || !rioWriteBulkStreamID(r, &id))
{
streamIteratorStop(&si);
return 0;
}
Expand All @@ -2218,7 +2228,8 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
int64_t field_len, value_len;
streamIteratorGetField(&si, &field, &value, &field_len, &value_len);
if (!rioWriteBulkString(r, (char *)field, field_len) ||
!rioWriteBulkString(r, (char *)value, value_len)) {
!rioWriteBulkString(r, (char *)value, value_len))
{
streamIteratorStop(&si);
return 0;
}
Expand All @@ -2232,7 +2243,8 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
id.seq = 1;
if (!rioWriteBulkCount(r, '*', 7) || !rioWriteBulkString(r, "XADD", 4) || !rioWriteBulkObject(r, key) ||
!rioWriteBulkString(r, "MAXLEN", 6) || !rioWriteBulkString(r, "0", 1) || !rioWriteBulkStreamID(r, &id) ||
!rioWriteBulkString(r, "x", 1) || !rioWriteBulkString(r, "y", 1)) {
!rioWriteBulkString(r, "x", 1) || !rioWriteBulkString(r, "y", 1))
{
streamIteratorStop(&si);
return 0;
}
Expand All @@ -2243,7 +2255,8 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
if (!rioWriteBulkCount(r, '*', 7) || !rioWriteBulkString(r, "XSETID", 6) || !rioWriteBulkObject(r, key) ||
!rioWriteBulkStreamID(r, &s->last_id) || !rioWriteBulkString(r, "ENTRIESADDED", 12) ||
!rioWriteBulkLongLong(r, s->entries_added) || !rioWriteBulkString(r, "MAXDELETEDID", 12) ||
!rioWriteBulkStreamID(r, &s->max_deleted_entry_id)) {
!rioWriteBulkStreamID(r, &s->max_deleted_entry_id))
{
streamIteratorStop(&si);
return 0;
}
Expand All @@ -2260,7 +2273,8 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
if (!rioWriteBulkCount(r, '*', 7) || !rioWriteBulkString(r, "XGROUP", 6) ||
!rioWriteBulkString(r, "CREATE", 6) || !rioWriteBulkObject(r, key) ||
!rioWriteBulkString(r, (char *)ri.key, ri.key_len) || !rioWriteBulkStreamID(r, &group->last_id) ||
!rioWriteBulkString(r, "ENTRIESREAD", 11) || !rioWriteBulkLongLong(r, group->entries_read)) {
!rioWriteBulkString(r, "ENTRIESREAD", 11) || !rioWriteBulkLongLong(r, group->entries_read))
{
raxStop(&ri);
streamIteratorStop(&si);
return 0;
Expand Down Expand Up @@ -2292,7 +2306,8 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
while (raxNext(&ri_pel)) {
streamNACK *nack = ri_pel.data;
if (rioWriteStreamPendingEntry(r, key, (char *)ri.key, ri.key_len, consumer, ri_pel.key, nack) ==
0) {
0)
{
raxStop(&ri_pel);
raxStop(&ri_cons);
raxStop(&ri);
Expand Down
3 changes: 2 additions & 1 deletion src/bitops.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ int getBitfieldTypeFromArgument(client *c, robj *o, int *sign, int *bits) {
}

if ((string2ll(p + 1, plen - 1, &llbits)) == 0 || llbits < 1 || (*sign == 1 && llbits > 64) ||
(*sign == 0 && llbits > 63)) {
(*sign == 0 && llbits > 63))
{
addReplyError(c, err);
return C_ERR;
}
Expand Down
9 changes: 6 additions & 3 deletions src/blocked.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ int blockedClientMayTimeout(client *c) {
if (c->bstate->btype == BLOCKED_LIST ||
c->bstate->btype == BLOCKED_ZSET ||
c->bstate->btype == BLOCKED_STREAM ||
c->bstate->btype == BLOCKED_WAIT) {
c->bstate->btype == BLOCKED_WAIT)
{
return 1;
}
return 0;
Expand Down Expand Up @@ -345,7 +346,8 @@ void disconnectOrRedirectAllBlockedClients(void) {
/* if the client is read-only and blocked by a read command, we do not unblock it */
if (c->flag.readonly && !(c->lastcmd->flags & CMD_WRITE)) continue;
if (clientSupportStandAloneRedirect(c) && (c->bstate->btype == BLOCKED_LIST || c->bstate->btype == BLOCKED_ZSET ||
c->bstate->btype == BLOCKED_STREAM || c->bstate->btype == BLOCKED_MODULE)) {
c->bstate->btype == BLOCKED_STREAM || c->bstate->btype == BLOCKED_MODULE))
{
if (c->bstate->btype == BLOCKED_MODULE && !moduleClientIsBlockedOnKeys(c)) continue;
/* Client has redirect capability and blocked on keys */
addReplyErrorSds(c, sdscatprintf(sdsempty(), "-REDIRECT %s:%d", server.primary_host, server.primary_port));
Expand Down Expand Up @@ -646,7 +648,8 @@ static void handleClientsBlockedOnKey(readyList *rl) {
* 3. In case of XREADGROUP call we will want to unblock on any change in object type
* or in case the key was deleted, since the group is no longer valid. */
if ((o != NULL && (receiver->bstate->btype == getBlockedTypeByType(o->type))) ||
(o != NULL && (receiver->bstate->btype == BLOCKED_MODULE)) || (receiver->bstate->unblock_on_nokey)) {
(o != NULL && (receiver->bstate->btype == BLOCKED_MODULE)) || (receiver->bstate->unblock_on_nokey))
{
if (receiver->bstate->btype != BLOCKED_MODULE)
unblockClientOnKey(receiver, rl->key);
else
Expand Down
3 changes: 2 additions & 1 deletion src/childinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void sendChildInfoGeneric(childInfoType info_type, size_t keys, size_t repl_outp

monotime now = getMonotonicUs();
if (info_type != CHILD_INFO_TYPE_CURRENT_INFO || !cow_updated ||
now - cow_updated > cow_update_cost * CHILD_COW_DUTY_CYCLE) {
now - cow_updated > cow_update_cost * CHILD_COW_DUTY_CYCLE)
{
cow = zmalloc_get_private_dirty(-1);
cow_updated = getMonotonicUs();
cow_update_cost = cow_updated - now;
Expand Down
3 changes: 2 additions & 1 deletion src/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ void parseUri(const char *uri, const char *tool_name, cliConnInfo *connInfo, int

/* URI must start with a valid scheme. */
if (!strncasecmp(tlsscheme, curr, strlen(tlsscheme)) ||
!strncasecmp(redisTlsscheme, curr, strlen(redisTlsscheme))) {
!strncasecmp(redisTlsscheme, curr, strlen(redisTlsscheme)))
{
#ifdef USE_OPENSSL
*tls_flag = 1;
const char *del = strstr(curr, "://");
Expand Down
24 changes: 16 additions & 8 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ void migrateCommand(client *c) {

/* Sanity check */
if (getLongFromObjectOrReply(c, c->argv[5], &timeout, NULL) != C_OK ||
getLongFromObjectOrReply(c, c->argv[4], &dbid, NULL) != C_OK) {
getLongFromObjectOrReply(c, c->argv[4], &dbid, NULL) != C_OK)
{
return;
}
if (timeout <= 0) timeout = 1000;
Expand Down Expand Up @@ -1202,7 +1203,8 @@ clusterNode *getNodeByQuery(client *c, int *error_code) {
* Allowing cross-DB COPY is possible, but it would require looking up the second key in the target DB.
* The command should only be allowed if the key exists. We may revisit this decision in the future. */
if (mcmd->proc == copyCommand &&
margc >= 4 && !strcasecmp(objectGetVal(margv[3]), "db")) {
margc >= 4 && !strcasecmp(objectGetVal(margv[3]), "db"))
{
long long value;
if (getLongLongFromObject(margv[4], &value) != C_OK || value != currentDb->id) {
if (error_code) *error_code = CLUSTER_REDIR_UNSTABLE;
Expand All @@ -1219,7 +1221,8 @@ clusterNode *getNodeByQuery(client *c, int *error_code) {
* NODE <node-id>. */
int flags = LOOKUP_NOTOUCH | LOOKUP_NOSTATS | LOOKUP_NONOTIFY | LOOKUP_NOEXPIRE;
if (!pubsubshard_included &&
(!c->flag.multi || (c->flag.multi && c->cmd->proc == execCommand))) {
(!c->flag.multi || (c->flag.multi && c->cmd->proc == execCommand)))
{
/* Multi/Exec validation happens on exec */
if (lookupKeyReadWithFlags(currentDb, thiskey, flags) == NULL)
missing_keys++;
Expand Down Expand Up @@ -1295,7 +1298,8 @@ clusterNode *getNodeByQuery(client *c, int *error_code) {
int is_write_command =
(cmd_flags & CMD_WRITE) || (c->cmd->proc == execCommand && (c->mstate->cmd_flags & CMD_WRITE));
if ((c->flag.readonly || pubsubshard_included) && !is_write_command && clusterNodeIsReplica(myself) &&
clusterNodeGetPrimary(myself) == n) {
clusterNodeGetPrimary(myself) == n)
{
return myself;
}

Expand Down Expand Up @@ -1351,7 +1355,8 @@ void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_co
int clusterRedirectBlockedClientIfNeeded(client *c) {
clusterNode *myself = getMyClusterNode();
if (c->flag.blocked && (c->bstate->btype == BLOCKED_LIST || c->bstate->btype == BLOCKED_ZSET ||
c->bstate->btype == BLOCKED_STREAM || c->bstate->btype == BLOCKED_MODULE)) {
c->bstate->btype == BLOCKED_STREAM || c->bstate->btype == BLOCKED_MODULE))
{
dictEntry *de;
dictIterator *di;

Expand Down Expand Up @@ -1379,7 +1384,8 @@ int clusterRedirectBlockedClientIfNeeded(client *c) {
/* if the client is read-only and attempting to access key that our
* replica can handle, allow it. */
if (c->flag.readonly && !(c->lastcmd->flags & CMD_WRITE) && clusterNodeIsReplica(myself) &&
clusterNodeGetPrimary(myself) == node) {
clusterNodeGetPrimary(myself) == node)
{
node = myself;
}

Expand Down Expand Up @@ -1431,7 +1437,8 @@ void addNodeToNodeReply(client *c, clusterNode *node) {
length++;
}
if (server.cluster_preferred_endpoint_type != CLUSTER_ENDPOINT_TYPE_HOSTNAME && hostname != NULL &&
hostname[0] != '\0') {
hostname[0] != '\0')
{
length++;
}

Expand All @@ -1447,7 +1454,8 @@ void addNodeToNodeReply(client *c, clusterNode *node) {
length--;
}
if (server.cluster_preferred_endpoint_type != CLUSTER_ENDPOINT_TYPE_HOSTNAME && hostname != NULL &&
hostname[0] != '\0') {
hostname[0] != '\0')
{
addReplyBulkCString(c, "hostname");
addReplyBulkCString(c, hostname);
length--;
Expand Down
Loading
Loading