Skip to content

Commit

Permalink
Merge branch 'unstable' into rename-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivshankar-Reddy authored Apr 23, 2024
2 parents 82ad8df + 393c8fd commit 4bb9af4
Show file tree
Hide file tree
Showing 25 changed files with 121 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ int ACLSaveToFile(const char *filename) {
}
offset += written_bytes;
}
if (redis_fsync(fd) == -1) {
if (valkey_fsync(fd) == -1) {
serverLog(LL_WARNING,"Syncing ACL file for ACL SAVE: %s",
strerror(errno));
goto cleanup;
Expand Down
18 changes: 9 additions & 9 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int writeAofManifestFile(sds buf) {
buf += nwritten;
}

if (redis_fsync(fd) == -1) {
if (valkey_fsync(fd) == -1) {
serverLog(LL_WARNING, "Fail to fsync the temp AOF file %s: %s.",
tmp_am_name, strerror(errno));

Expand Down Expand Up @@ -953,7 +953,7 @@ void killAppendOnlyChild(void) {
void stopAppendOnly(void) {
serverAssert(server.aof_state != AOF_OFF);
flushAppendOnlyFile(1);
if (redis_fsync(server.aof_fd) == -1) {
if (valkey_fsync(server.aof_fd) == -1) {
serverLog(LL_WARNING,"Fail to fsync the AOF file: %s",strerror(errno));
} else {
server.aof_last_fsync = server.mstime;
Expand Down Expand Up @@ -1248,13 +1248,13 @@ void flushAppendOnlyFile(int force) {

/* Perform the fsync if needed. */
if (server.aof_fsync == AOF_FSYNC_ALWAYS) {
/* redis_fsync is defined as fdatasync() for Linux in order to avoid
/* valkey_fsync is defined as fdatasync() for Linux in order to avoid
* flushing metadata. */
latencyStartMonitor(latency);
/* Let's try to get this data on the disk. To guarantee data safe when
* the AOF fsync policy is 'always', we should exit if failed to fsync
* AOF (see comment next to the exit(1) after write error above). */
if (redis_fsync(server.aof_fd) == -1) {
if (valkey_fsync(server.aof_fd) == -1) {
serverLog(LL_WARNING,"Can't persist AOF for fsync error when the "
"AOF fsync policy is 'always': %s. Exiting...", strerror(errno));
exit(1);
Expand Down Expand Up @@ -1403,7 +1403,7 @@ struct client *createAOFClient(void) {
* AOF_FAILED: Failed to load the AOF file. */
int loadSingleAppendOnlyFile(char *filename) {
struct client *fakeClient;
struct redis_stat sb;
struct valkey_stat sb;
int old_aof_state = server.aof_state;
long loops = 0;
off_t valid_up_to = 0; /* Offset of latest well-formed command loaded. */
Expand All @@ -1415,7 +1415,7 @@ int loadSingleAppendOnlyFile(char *filename) {
FILE *fp = fopen(aof_filepath, "r");
if (fp == NULL) {
int en = errno;
if (redis_stat(aof_filepath, &sb) == 0 || errno != ENOENT) {
if (valkey_stat(aof_filepath, &sb) == 0 || errno != ENOENT) {
serverLog(LL_WARNING,"Fatal error: can't open the append log file %s for reading: %s", filename, strerror(en));
sdsfree(aof_filepath);
return AOF_OPEN_ERR;
Expand All @@ -1426,7 +1426,7 @@ int loadSingleAppendOnlyFile(char *filename) {
}
}

if (fp && redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
if (fp && valkey_fstat(fileno(fp), &sb) != -1 && sb.st_size == 0) {
fclose(fp);
sdsfree(aof_filepath);
return AOF_EMPTY;
Expand Down Expand Up @@ -2531,13 +2531,13 @@ void aofRemoveTempFile(pid_t childpid) {
* The status argument is an optional output argument to be filled with
* one of the AOF_ status values. */
off_t getAppendOnlyFileSize(sds filename, int *status) {
struct redis_stat sb;
struct valkey_stat sb;
off_t size;
mstime_t latency;

sds aof_filepath = makePath(server.aof_dirname, filename);
latencyStartMonitor(latency);
if (redis_stat(aof_filepath, &sb) == -1) {
if (valkey_stat(aof_filepath, &sb) == -1) {
if (status) *status = errno == ENOENT ? AOF_NOT_EXIST : AOF_OPEN_ERR;
serverLog(LL_WARNING, "Unable to obtain the AOF file %s length. stat: %s",
filename, strerror(errno));
Expand Down
10 changes: 5 additions & 5 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void *bioProcessBackgroundJobs(void *arg);

/* Make sure we have enough stack to perform all the things we do in the
* main thread. */
#define REDIS_THREAD_STACK_SIZE (1024*1024*4)
#define VALKEY_THREAD_STACK_SIZE (1024*1024*4)

/* Initialize the background system, spawning the thread. */
void bioInit(void) {
Expand All @@ -133,7 +133,7 @@ void bioInit(void) {
pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr,&stacksize);
if (!stacksize) stacksize = 1; /* The world is full of Solaris Fixes */
while (stacksize < REDIS_THREAD_STACK_SIZE) stacksize *= 2;
while (stacksize < VALKEY_THREAD_STACK_SIZE) stacksize *= 2;
pthread_attr_setstacksize(&attr, stacksize);

/* Ready to spawn our threads. We use the single argument the thread
Expand Down Expand Up @@ -210,7 +210,7 @@ void *bioProcessBackgroundJobs(void *arg) {
/* Check that the worker is within the right interval. */
serverAssert(worker < BIO_WORKER_NUM);

redis_set_thread_title(bio_worker_title[worker]);
valkey_set_thread_title(bio_worker_title[worker]);

serverSetCpuAffinity(server.bio_cpulist);

Expand Down Expand Up @@ -245,7 +245,7 @@ void *bioProcessBackgroundJobs(void *arg) {

if (job_type == BIO_CLOSE_FILE) {
if (job->fd_args.need_fsync &&
redis_fsync(job->fd_args.fd) == -1 &&
valkey_fsync(job->fd_args.fd) == -1 &&
errno != EBADF && errno != EINVAL)
{
serverLog(LL_WARNING, "Fail to fsync the AOF file: %s",strerror(errno));
Expand All @@ -260,7 +260,7 @@ void *bioProcessBackgroundJobs(void *arg) {
/* The fd may be closed by main thread and reused for another
* socket, pipe, or file. We just ignore these errno because
* aof fsync did not really fail. */
if (redis_fsync(job->fd_args.fd) == -1 &&
if (valkey_fsync(job->fd_args.fd) == -1 &&
errno != EBADF && errno != EINVAL)
{
int last_status;
Expand Down
2 changes: 1 addition & 1 deletion src/bitops.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void getbitCommand(client *c) {
}

/* BITOP op_name target_key src_key1 src_key2 src_key3 ... src_keyN */
REDIS_NO_SANITIZE("alignment")
VALKEY_NO_SANITIZE("alignment")
void bitopCommand(client *c) {
char *opname = c->argv[1]->ptr;
robj *o, *targetkey = c->argv[2];
Expand Down
21 changes: 17 additions & 4 deletions src/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static sds percentDecode(const char *pe, size_t len) {
/* Parse a URI and extract the server connection information.
* URI scheme is based on the provisional specification[1] excluding support
* for query parameters. Valid URIs are:
* scheme: "redis://"
* scheme: "valkey://"
* authority: [[<username> ":"] <password> "@"] [<hostname> [":" <port>]]
* path: ["/" [<db>]]
*
Expand All @@ -318,8 +318,11 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo
UNUSED(tls_flag);
#endif

const char *scheme = "redis://";
const char *tlsscheme = "rediss://";
const char *scheme = "valkey://";
const char *tlsscheme = "valkeys://";
/* We need to support redis:// and rediss:// too for compatibility. */
const char *redisScheme = "redis://";
const char *redisTlsscheme = "rediss://";
const char *curr = uri;
const char *end = uri + strlen(uri);
const char *userinfo, *username, *port, *host, *path;
Expand All @@ -330,11 +333,21 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo
*tls_flag = 1;
curr += strlen(tlsscheme);
#else
fprintf(stderr,"rediss:// is only supported when %s is compiled with OpenSSL\n", tool_name);
fprintf(stderr,"valkeys:// and rediss:// are only supported when %s is compiled with OpenSSL\n", tool_name);
exit(1);
#endif
} else if (!strncasecmp(redisTlsscheme, curr, strlen(redisTlsscheme))) {
#ifdef USE_OPENSSL
*tls_flag = 1;
curr += strlen(redisTlsscheme);
#else
fprintf(stderr,"valkeys:// and rediss:// are only supported when %s is compiled with OpenSSL\n", tool_name);
exit(1);
#endif
} else if (!strncasecmp(scheme, curr, strlen(scheme))) {
curr += strlen(scheme);
} else if (!strncasecmp(redisScheme, curr, strlen(redisScheme))) {
curr += strlen(redisScheme);
} else {
fprintf(stderr,"Invalid URI scheme\n");
exit(1);
Expand Down
6 changes: 3 additions & 3 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ int clusterLoadConfig(char *filename) {
}
}

if (redis_fstat(fileno(fp),&sb) == -1) {
if (valkey_fstat(fileno(fp), &sb) == -1) {
serverLog(LL_WARNING,
"Unable to obtain the cluster node config file stat %s: %s",
filename, strerror(errno));
Expand Down Expand Up @@ -727,7 +727,7 @@ int clusterSaveConfig(int do_fsync) {

if (do_fsync) {
server.cluster->todo_before_sleep &= ~CLUSTER_TODO_FSYNC_CONFIG;
if (redis_fsync(fd) == -1) {
if (valkey_fsync(fd) == -1) {
serverLog(LL_WARNING,"Could not sync tmp cluster config file: %s",strerror(errno));
goto cleanup;
}
Expand Down Expand Up @@ -3772,7 +3772,7 @@ void clusterBroadcastPong(int target) {
* As all the struct is used as a buffer, when more than 8 bytes are copied into
* the 'bulk_data', sanitizer generates an out-of-bounds error which is a false
* positive in this context. */
REDIS_NO_SANITIZE("bounds")
VALKEY_NO_SANITIZE("bounds")
clusterMsgSendBlock *clusterCreatePublishMsgBlock(robj *channel, robj *message, uint16_t type) {

uint32_t channel_len, message_len;
Expand Down
4 changes: 2 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,8 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) {
FILE *fp = fopen(path,"r");
if (fp == NULL && errno != ENOENT) return NULL;

struct redis_stat sb;
if (fp && redis_fstat(fileno(fp),&sb) == -1) {
struct valkey_stat sb;
if (fp && valkey_fstat(fileno(fp), &sb) == -1) {
fclose(fp);
return NULL;
}
Expand Down
46 changes: 23 additions & 23 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __CONFIG_H
#define __CONFIG_H
#ifndef CONFIG_H
#define CONFIG_H

#ifdef __APPLE__
#include <fcntl.h> // for fcntl(fd, F_FULLFSYNC)
Expand All @@ -44,13 +44,13 @@
#define MAC_OS_10_6_DETECTED
#endif

/* Define redis_fstat to fstat or fstat64() */
/* Define valkey_fstat to fstat or fstat64() */
#if defined(__APPLE__) && !defined(MAC_OS_10_6_DETECTED)
#define redis_fstat fstat64
#define redis_stat stat64
#define valkey_fstat fstat64
#define valkey_stat stat64
#else
#define redis_fstat fstat
#define redis_stat stat
#define valkey_fstat fstat
#define valkey_stat stat
#endif

/* Test for proc filesystem */
Expand Down Expand Up @@ -114,13 +114,13 @@
#endif
#endif

/* Define redis_fsync to fdatasync() in Linux and fsync() for all the rest */
/* Define valkey_fsync to fdatasync() in Linux and fsync() for all the rest */
#if defined(__linux__)
#define redis_fsync(fd) fdatasync(fd)
#define valkey_fsync(fd) fdatasync(fd)
#elif defined(__APPLE__)
#define redis_fsync(fd) fcntl(fd, F_FULLFSYNC)
#define valkey_fsync(fd) fcntl(fd, F_FULLFSYNC)
#else
#define redis_fsync(fd) fsync(fd)
#define valkey_fsync(fd) fsync(fd)
#endif

#if defined(__FreeBSD__)
Expand All @@ -138,9 +138,9 @@
#endif

#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define redis_unreachable __builtin_unreachable
#define valkey_unreachable __builtin_unreachable
#else
#define redis_unreachable abort
#define valkey_unreachable abort
#endif

#if __GNUC__ >= 3
Expand All @@ -153,11 +153,11 @@

#if defined(__has_attribute)
#if __has_attribute(no_sanitize)
#define REDIS_NO_SANITIZE(sanitizer) __attribute__((no_sanitize(sanitizer)))
#define VALKEY_NO_SANITIZE(sanitizer) __attribute__((no_sanitize(sanitizer)))
#endif
#endif
#if !defined(REDIS_NO_SANITIZE)
#define REDIS_NO_SANITIZE(sanitizer)
#if !defined(VALKEY_NO_SANITIZE)
#define VALKEY_NO_SANITIZE(sanitizer)
#endif

/* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use
Expand Down Expand Up @@ -285,26 +285,26 @@ void setproctitle(const char *fmt, ...);
#define USE_ALIGNED_ACCESS
#endif

/* Define for redis_set_thread_title */
/* Define for valkey_set_thread_title */
#ifdef __linux__
#define redis_set_thread_title(name) pthread_setname_np(pthread_self(), name)
#define valkey_set_thread_title(name) pthread_setname_np(pthread_self(), name)
#else
#if (defined __FreeBSD__ || defined __OpenBSD__)
#include <pthread_np.h>
#define redis_set_thread_title(name) pthread_set_name_np(pthread_self(), name)
#define valkey_set_thread_title(name) pthread_set_name_np(pthread_self(), name)
#elif defined __NetBSD__
#include <pthread.h>
#define redis_set_thread_title(name) pthread_setname_np(pthread_self(), "%s", name)
#define valkey_set_thread_title(name) pthread_setname_np(pthread_self(), "%s", name)
#elif defined __HAIKU__
#include <kernel/OS.h>
#define redis_set_thread_title(name) rename_thread(find_thread(0), name)
#define valkey_set_thread_title(name) rename_thread(find_thread(0), name)
#else
#if (defined __APPLE__ && defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
int pthread_setname_np(const char *name);
#include <pthread.h>
#define redis_set_thread_title(name) pthread_setname_np(name)
#define valkey_set_thread_title(name) pthread_setname_np(name)
#else
#define redis_set_thread_title(name)
#define valkey_set_thread_title(name)
#endif
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ static void* getAndSetMcontextEip(ucontext_t *uc, void *eip) {
#undef NOT_SUPPORTED
}

REDIS_NO_SANITIZE("address")
VALKEY_NO_SANITIZE("address")
void logStackContent(void **sp) {
int i;
for (i = 15; i >= 0; i--) {
Expand Down
2 changes: 1 addition & 1 deletion src/hyperloglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static char *invalid_hll_err = "-INVALIDOBJ Corrupted HLL object detected";
/* Our hash function is MurmurHash2, 64 bit version.
* It was modified in order to provide the same result in
* big and little endian archs (endian neutral). */
REDIS_NO_SANITIZE("alignment")
VALKEY_NO_SANITIZE("alignment")
uint64_t MurmurHash64A (const void * key, int len, unsigned int seed) {
const uint64_t m = 0xc6a4a7935bd1e995;
const int r = 47;
Expand Down
2 changes: 1 addition & 1 deletion src/listpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ unsigned char *lpInsert(unsigned char *lp, unsigned char *elestr, unsigned char
} else if (elestr) {
lpEncodeString(dst,elestr,size);
} else {
redis_unreachable();
valkey_unreachable();
}
dst += enclen;
memcpy(dst,backlen,backlen_size);
Expand Down
4 changes: 2 additions & 2 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int prepareClientToWrite(client *c) {
* Sanitizer suppression: client->buf_usable_size determined by
* zmalloc_usable_size() call. Writing beyond client->buf boundaries confuses
* sanitizer and generates a false positive out-of-bounds error */
REDIS_NO_SANITIZE("bounds")
VALKEY_NO_SANITIZE("bounds")
size_t _addReplyToBuffer(client *c, const char *s, size_t len) {
size_t available = c->buf_usable_size - c->bufpos;

Expand Down Expand Up @@ -4224,7 +4224,7 @@ void *IOThreadMain(void *myid) {
char thdname[16];

snprintf(thdname, sizeof(thdname), "io_thd_%ld", id);
redis_set_thread_title(thdname);
valkey_set_thread_title(thdname);
serverSetCpuAffinity(server.server_cpulist);
makeThreadKillable();

Expand Down
2 changes: 1 addition & 1 deletion src/quicklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ int quicklistNodeExceedsLimit(int fill, size_t new_sz, unsigned int new_count) {
return new_count > count_limit;
}

redis_unreachable();
valkey_unreachable();
}

/* Determines whether a given size qualifies as a large element based on a threshold
Expand Down
Loading

0 comments on commit 4bb9af4

Please sign in to comment.