Rename macros in config.h (#257)

This patch try to do following things:

1. Rename `redis_*` and `REDIS_*` macros defined in config.h to
`valkey_*`, `VALKEY_*` and update associated used files. (`redis_fstat`,
`redis_fsync`, `REDIS_THREAD_STACK_SIZE`, etc.)
2. Remove the leading double underscore for guard macro in config.h.

---------

Signed-off-by: Lipeng Zhu <lipeng.zhu@intel.com>
This commit is contained in:
Lipeng Zhu 2024-04-23 20:20:35 +08:00 committed by GitHub
parent 87a5bfc002
commit 393c8fde29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 70 additions and 70 deletions

View File

@ -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;

View File

@ -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));
@ -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;
@ -1248,13 +1248,13 @@ try_fsync:
/* 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);
@ -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. */
@ -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;
@ -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;
@ -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));

View File

@ -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) {
@ -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
@ -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);
@ -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));
@ -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;

View File

@ -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];

View File

@ -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));
@ -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;
}
@ -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;

View File

@ -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;
}

View File

@ -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)
@ -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 */
@ -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__)
@ -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
@ -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
@ -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

View File

@ -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--) {

View File

@ -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;

View File

@ -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);

View File

@ -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;
@ -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();

View File

@ -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

View File

@ -1618,7 +1618,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
client *slave = ln->value;
if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END) {
struct redis_stat buf;
struct valkey_stat buf;
if (bgsaveerr != C_OK) {
freeClientAsync(slave);
@ -1666,8 +1666,8 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
}
slave->repl_start_cmd_stream_on_ack = 1;
} else {
if ((slave->repldbfd = open(server.rdb_filename,O_RDONLY)) == -1 ||
redis_fstat(slave->repldbfd,&buf) == -1) {
if ((slave->repldbfd = open(server.rdb_filename, O_RDONLY)) == -1 ||
valkey_fstat(slave->repldbfd, &buf) == -1) {
freeClientAsync(slave);
serverLog(LL_WARNING,"SYNC failed. Can't open/stat DB after BGSAVE: %s", strerror(errno));
continue;

View File

@ -149,7 +149,7 @@ static size_t rioFileWrite(rio *r, const void *buf, size_t len) {
return 0;
}
#else
if (redis_fsync(fileno(r->io.file.fp)) == -1) return 0;
if (valkey_fsync(fileno(r->io.file.fp)) == -1) return 0;
#endif
if (r->io.file.reclaim_cache) {
/* In Linux sync_file_range just issue a writeback request to

View File

@ -4484,7 +4484,7 @@ int finishShutdown(void) {
/* Append only file: flush buffers and fsync() the AOF at exit */
serverLog(LL_NOTICE,"Calling fsync() on the AOF file.");
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));
}

View File

@ -671,9 +671,9 @@ typedef enum {
#define run_with_period(_ms_) if (((_ms_) <= 1000/server.hz) || !(server.cronloops%((_ms_)/(1000/server.hz))))
/* We can print the stacktrace, so our assert is defined this way: */
#define serverAssertWithInfo(_c,_o,_e) (likely(_e)?(void)0 : (_serverAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),redis_unreachable()))
#define serverAssert(_e) (likely(_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),redis_unreachable()))
#define serverPanic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),redis_unreachable()
#define serverAssertWithInfo(_c,_o,_e) (likely(_e)?(void)0 : (_serverAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),valkey_unreachable()))
#define serverAssert(_e) (likely(_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),valkey_unreachable()))
#define serverPanic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),valkey_unreachable()
/* The following macros provide assertions that are only executed during test builds and should be used to add
* assertions that are too computationally expensive or dangerous to run during normal operations. */

View File

@ -40,8 +40,8 @@
#include "config.h"
#define assert(_e) (likely((_e))?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),redis_unreachable()))
#define panic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),redis_unreachable()
#define assert(_e) (likely((_e))?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),valkey_unreachable()))
#define panic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),valkey_unreachable()
void _serverAssert(const char *estr, const char *file, int line);
void _serverPanic(const char *file, int line, const char *msg, ...);

View File

@ -501,7 +501,7 @@ int string2ll(const char *s, size_t slen, long long *value) {
/* Helper function to convert a string to an unsigned long long value.
* The function attempts to use the faster string2ll() function inside
* Redis: if it fails, strtoull() is used instead. The function returns
* Valkey: if it fails, strtoull() is used instead. The function returns
* 1 if the conversion happened successfully or 0 if the number is
* invalid or out of range. */
int string2ull(const char *s, unsigned long long *value) {
@ -1161,7 +1161,7 @@ int fsyncFileDir(const char *filename) {
}
/* Some OSs don't allow us to fsync directories at all, so we can ignore
* those errors. */
if (redis_fsync(dir_fd) == -1 && !(errno == EBADF || errno == EINVAL)) {
if (valkey_fsync(dir_fd) == -1 && !(errno == EBADF || errno == EINVAL)) {
int save_errno = errno;
close(dir_fd);
errno = save_errno;
@ -1620,7 +1620,7 @@ static void test_reclaimFilePageCache(void) {
char buf[4] = "foo";
assert(write(fd, buf, sizeof(buf)) > 0);
assert(cache_exist(fd));
assert(redis_fsync(fd) == 0);
assert(valkey_fsync(fd) == 0);
assert(reclaimFilePageCache(fd, 0, 0) == 0);
assert(!cache_exist(fd));

View File

@ -231,8 +231,8 @@ int checkSingleAof(char *aof_filename, char *aof_filepath, int last_file, int fi
exit(1);
}
struct redis_stat sb;
if (redis_fstat(fileno(fp),&sb) == -1) {
struct valkey_stat sb;
if (valkey_fstat(fileno(fp), &sb) == -1) {
printf("Cannot stat file: %s, aborting...\n", aof_filename);
fclose(fp);
exit(1);
@ -343,8 +343,8 @@ int fileIsRDB(char *filepath) {
exit(1);
}
struct redis_stat sb;
if (redis_fstat(fileno(fp), &sb) == -1) {
struct valkey_stat sb;
if (valkey_fstat(fileno(fp), &sb) == -1) {
printf("Cannot stat file: %s\n", filepath);
fclose(fp);
exit(1);
@ -380,8 +380,8 @@ int fileIsManifest(char *filepath) {
exit(1);
}
struct redis_stat sb;
if (redis_fstat(fileno(fp), &sb) == -1) {
struct valkey_stat sb;
if (valkey_fstat(fileno(fp), &sb) == -1) {
printf("Cannot stat file: %s\n", filepath);
fclose(fp);
exit(1);

View File

@ -350,7 +350,7 @@ static inline unsigned int zipIntSize(unsigned char encoding) {
if (encoding >= ZIP_INT_IMM_MIN && encoding <= ZIP_INT_IMM_MAX)
return 0; /* 4 bit immediate */
/* bad encoding, covered by a previous call to ZIP_ASSERT_ENCODING */
redis_unreachable();
valkey_unreachable();
return 0;
}