mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 00:52:38 +00:00
rename redis functions in server.h (#179)
redisPopcount -> serverPopcount redisSetProcTitle -> serverSetProcTitle redisCommunicateSystemd -> serverCommunicateSystemd redisSetCpuAffinity -> serverSetCpuAffinity redisFork -> serverFork #144 Signed-off-by: 0del <bany.y0599@gmail.com>
This commit is contained in:
parent
add5f5615c
commit
f753db5141
@ -2467,12 +2467,12 @@ int rewriteAppendOnlyFileBackground(void) {
|
||||
|
||||
server.stat_aof_rewrites++;
|
||||
|
||||
if ((childpid = redisFork(CHILD_TYPE_AOF)) == 0) {
|
||||
if ((childpid = serverFork(CHILD_TYPE_AOF)) == 0) {
|
||||
char tmpfile[256];
|
||||
|
||||
/* Child */
|
||||
redisSetProcTitle("redis-aof-rewrite");
|
||||
redisSetCpuAffinity(server.aof_rewrite_cpulist);
|
||||
serverSetProcTitle("redis-aof-rewrite");
|
||||
serverSetCpuAffinity(server.aof_rewrite_cpulist);
|
||||
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
|
||||
if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
|
||||
serverLog(LL_NOTICE,
|
||||
|
@ -212,7 +212,7 @@ void *bioProcessBackgroundJobs(void *arg) {
|
||||
|
||||
redis_set_thread_title(bio_worker_title[worker]);
|
||||
|
||||
redisSetCpuAffinity(server.bio_cpulist);
|
||||
serverSetCpuAffinity(server.bio_cpulist);
|
||||
|
||||
makeThreadKillable();
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
/* Count number of bits set in the binary array pointed by 's' and long
|
||||
* 'count' bytes. The implementation of this function is required to
|
||||
* work with an input string length up to 512 MB or more (server.proto_max_bulk_len) */
|
||||
long long redisPopcount(void *s, long count) {
|
||||
long long serverPopcount(void *s, long count) {
|
||||
long long bits = 0;
|
||||
unsigned char *p = s;
|
||||
uint32_t *p4;
|
||||
@ -870,7 +870,7 @@ void bitcountCommand(client *c) {
|
||||
addReply(c,shared.czero);
|
||||
} else {
|
||||
long bytes = (long)(end-start+1);
|
||||
long long count = redisPopcount(p+start,bytes);
|
||||
long long count = serverPopcount(p+start,bytes);
|
||||
if (first_byte_neg_mask != 0 || last_byte_neg_mask != 0) {
|
||||
unsigned char firstlast[2] = {0, 0};
|
||||
/* We may count bits of first byte and last byte which are out of
|
||||
@ -878,7 +878,7 @@ void bitcountCommand(client *c) {
|
||||
* bits in the range to zero. So these bit will not be excluded. */
|
||||
if (first_byte_neg_mask != 0) firstlast[0] = p[start] & first_byte_neg_mask;
|
||||
if (last_byte_neg_mask != 0) firstlast[1] = p[end] & last_byte_neg_mask;
|
||||
count -= redisPopcount(firstlast,2);
|
||||
count -= serverPopcount(firstlast,2);
|
||||
}
|
||||
addReplyLongLong(c,count);
|
||||
}
|
||||
|
@ -805,7 +805,7 @@ int clusterLockConfig(char *filename) {
|
||||
* we'll retain the lock to the file as long as the process exists.
|
||||
*
|
||||
* After fork, the child process will get the fd opened by the parent process,
|
||||
* we need save `fd` to `cluster_config_file_lock_fd`, so that in redisFork(),
|
||||
* we need save `fd` to `cluster_config_file_lock_fd`, so that in serverFork(),
|
||||
* it will be closed in the child process.
|
||||
* If it is not closed, when the main process is killed -9, but the child process
|
||||
* (redis-aof-rewrite) is still alive, the fd(lock) will still be held by the
|
||||
|
@ -2445,7 +2445,7 @@ static int updateLocaleCollate(const char **err) {
|
||||
}
|
||||
|
||||
static int updateProcTitleTemplate(const char **err) {
|
||||
if (redisSetProcTitle(NULL) == C_ERR) {
|
||||
if (serverSetProcTitle(NULL) == C_ERR) {
|
||||
*err = "failed to set process title";
|
||||
return 0;
|
||||
}
|
||||
|
@ -865,7 +865,7 @@ void ldbSendLogs(void) {
|
||||
int ldbStartSession(client *c) {
|
||||
ldb.forked = (c->flags & CLIENT_LUA_DEBUG_SYNC) == 0;
|
||||
if (ldb.forked) {
|
||||
pid_t cp = redisFork(CHILD_TYPE_LDB);
|
||||
pid_t cp = serverFork(CHILD_TYPE_LDB);
|
||||
if (cp == -1) {
|
||||
addReplyErrorFormat(c,"Fork() failed: can't run EVAL in debugging mode: %s", strerror(errno));
|
||||
return 0;
|
||||
|
@ -11248,9 +11248,9 @@ int RM_ScanKey(RedisModuleKey *key, RedisModuleScanCursor *cursor, RedisModuleSc
|
||||
int RM_Fork(RedisModuleForkDoneHandler cb, void *user_data) {
|
||||
pid_t childpid;
|
||||
|
||||
if ((childpid = redisFork(CHILD_TYPE_MODULE)) == 0) {
|
||||
if ((childpid = serverFork(CHILD_TYPE_MODULE)) == 0) {
|
||||
/* Child */
|
||||
redisSetProcTitle("redis-module-fork");
|
||||
serverSetProcTitle("redis-module-fork");
|
||||
} else if (childpid == -1) {
|
||||
serverLog(LL_WARNING,"Can't fork for module: %s", strerror(errno));
|
||||
} else {
|
||||
|
@ -4226,7 +4226,7 @@ void *IOThreadMain(void *myid) {
|
||||
|
||||
snprintf(thdname, sizeof(thdname), "io_thd_%ld", id);
|
||||
redis_set_thread_title(thdname);
|
||||
redisSetCpuAffinity(server.server_cpulist);
|
||||
serverSetCpuAffinity(server.server_cpulist);
|
||||
makeThreadKillable();
|
||||
|
||||
while(1) {
|
||||
|
12
src/rdb.c
12
src/rdb.c
@ -1577,12 +1577,12 @@ int rdbSaveBackground(int req, char *filename, rdbSaveInfo *rsi, int rdbflags) {
|
||||
server.dirty_before_bgsave = server.dirty;
|
||||
server.lastbgsave_try = time(NULL);
|
||||
|
||||
if ((childpid = redisFork(CHILD_TYPE_RDB)) == 0) {
|
||||
if ((childpid = serverFork(CHILD_TYPE_RDB)) == 0) {
|
||||
int retval;
|
||||
|
||||
/* Child */
|
||||
redisSetProcTitle("redis-rdb-bgsave");
|
||||
redisSetCpuAffinity(server.bgsave_cpulist);
|
||||
serverSetProcTitle("redis-rdb-bgsave");
|
||||
serverSetCpuAffinity(server.bgsave_cpulist);
|
||||
retval = rdbSave(req, filename,rsi,rdbflags);
|
||||
if (retval == C_OK) {
|
||||
sendChildCowInfo(CHILD_INFO_TYPE_RDB_COW_SIZE, "RDB");
|
||||
@ -3583,7 +3583,7 @@ int rdbSaveToSlavesSockets(int req, rdbSaveInfo *rsi) {
|
||||
}
|
||||
|
||||
/* Create the child process. */
|
||||
if ((childpid = redisFork(CHILD_TYPE_RDB)) == 0) {
|
||||
if ((childpid = serverFork(CHILD_TYPE_RDB)) == 0) {
|
||||
/* Child */
|
||||
int retval, dummy;
|
||||
rio rdb;
|
||||
@ -3594,8 +3594,8 @@ int rdbSaveToSlavesSockets(int req, rdbSaveInfo *rsi) {
|
||||
* get a write error and exit. */
|
||||
close(server.rdb_pipe_read);
|
||||
|
||||
redisSetProcTitle("redis-rdb-to-slaves");
|
||||
redisSetCpuAffinity(server.bgsave_cpulist);
|
||||
serverSetProcTitle("redis-rdb-to-slaves");
|
||||
serverSetCpuAffinity(server.bgsave_cpulist);
|
||||
|
||||
retval = rdbSaveRioWithEOFMark(req,&rdb,NULL,rsi);
|
||||
if (retval == C_OK && rioFlush(&rdb) == 0)
|
||||
|
@ -2288,7 +2288,7 @@ void readSyncBulkPayload(connection *conn) {
|
||||
serverLog(LL_NOTICE, "MASTER <-> REPLICA sync: Finished with success");
|
||||
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
|
||||
redisCommunicateSystemd("STATUS=MASTER <-> REPLICA sync: Finished with success. Ready to accept connections in read-write mode.\n");
|
||||
serverCommunicateSystemd("STATUS=MASTER <-> REPLICA sync: Finished with success. Ready to accept connections in read-write mode.\n");
|
||||
}
|
||||
|
||||
/* Send the initial ACK immediately to put this replica in online state. */
|
||||
@ -2859,7 +2859,7 @@ void syncWithMaster(connection *conn) {
|
||||
if (psync_result == PSYNC_CONTINUE) {
|
||||
serverLog(LL_NOTICE, "MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.");
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
|
||||
redisCommunicateSystemd("STATUS=MASTER <-> REPLICA sync: Partial Resynchronization accepted. Ready to accept connections in read-write mode.\n");
|
||||
serverCommunicateSystemd("STATUS=MASTER <-> REPLICA sync: Partial Resynchronization accepted. Ready to accept connections in read-write mode.\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
36
src/server.c
36
src/server.c
@ -4318,7 +4318,7 @@ int prepareForShutdown(int flags) {
|
||||
|
||||
serverLog(LL_NOTICE,"User requested shutdown...");
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD)
|
||||
redisCommunicateSystemd("STOPPING=1\n");
|
||||
serverCommunicateSystemd("STOPPING=1\n");
|
||||
|
||||
/* If we have any replicas, let them catch up the replication offset before
|
||||
* we shut down, to avoid data loss. */
|
||||
@ -4454,7 +4454,7 @@ int finishShutdown(void) {
|
||||
} else {
|
||||
serverLog(LL_WARNING, "Writing initial AOF, can't exit.");
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD)
|
||||
redisCommunicateSystemd("STATUS=Writing initial AOF, can't exit.\n");
|
||||
serverCommunicateSystemd("STATUS=Writing initial AOF, can't exit.\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -4476,7 +4476,7 @@ int finishShutdown(void) {
|
||||
if ((server.saveparamslen > 0 && !nosave) || save) {
|
||||
serverLog(LL_NOTICE,"Saving the final RDB snapshot before exiting.");
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD)
|
||||
redisCommunicateSystemd("STATUS=Saving the final RDB snapshot\n");
|
||||
serverCommunicateSystemd("STATUS=Saving the final RDB snapshot\n");
|
||||
/* Snapshotting. Perform a SYNC SAVE and exit */
|
||||
rdbSaveInfo rsi, *rsiptr;
|
||||
rsiptr = rdbPopulateSaveInfo(&rsi);
|
||||
@ -4492,7 +4492,7 @@ int finishShutdown(void) {
|
||||
} else {
|
||||
serverLog(LL_WARNING,"Error trying to save the DB, can't exit.");
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD)
|
||||
redisCommunicateSystemd("STATUS=Error trying to save the DB, can't exit.\n");
|
||||
serverCommunicateSystemd("STATUS=Error trying to save the DB, can't exit.\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -6349,7 +6349,7 @@ int changeListener(connListener *listener) {
|
||||
|
||||
/* Just close the server if port disabled */
|
||||
if (listener->port == 0) {
|
||||
if (server.set_proc_title) redisSetProcTitle(NULL);
|
||||
if (server.set_proc_title) serverSetProcTitle(NULL);
|
||||
return C_OK;
|
||||
}
|
||||
|
||||
@ -6363,7 +6363,7 @@ int changeListener(connListener *listener) {
|
||||
serverPanic("Unrecoverable error creating %s accept handler.", listener->ct->get_type(NULL));
|
||||
}
|
||||
|
||||
if (server.set_proc_title) redisSetProcTitle(NULL);
|
||||
if (server.set_proc_title) serverSetProcTitle(NULL);
|
||||
|
||||
return C_OK;
|
||||
}
|
||||
@ -6449,7 +6449,7 @@ void closeChildUnusedResourceAfterFork(void) {
|
||||
}
|
||||
|
||||
/* purpose is one of CHILD_TYPE_ types */
|
||||
int redisFork(int purpose) {
|
||||
int serverFork(int purpose) {
|
||||
if (isMutuallyExclusiveChildType(purpose)) {
|
||||
if (hasActiveChildProcess()) {
|
||||
errno = EEXIST;
|
||||
@ -6749,7 +6749,7 @@ int validateProcTitleTemplate(const char *template) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
int redisSetProcTitle(char *title) {
|
||||
int serverSetProcTitle(char *title) {
|
||||
#ifdef USE_SETPROCTITLE
|
||||
if (!title) title = server.exec_argv[0];
|
||||
sds proc_title = expandProcTitleTemplate(server.proc_title_template, title);
|
||||
@ -6764,7 +6764,7 @@ int redisSetProcTitle(char *title) {
|
||||
return C_OK;
|
||||
}
|
||||
|
||||
void redisSetCpuAffinity(const char *cpulist) {
|
||||
void serverSetCpuAffinity(const char *cpulist) {
|
||||
#ifdef USE_SETCPUAFFINITY
|
||||
setcpuaffinity(cpulist);
|
||||
#else
|
||||
@ -6774,7 +6774,7 @@ void redisSetCpuAffinity(const char *cpulist) {
|
||||
|
||||
/* Send a notify message to systemd. Returns sd_notify return code which is
|
||||
* a positive number on success. */
|
||||
int redisCommunicateSystemd(const char *sd_notify_msg) {
|
||||
int serverCommunicateSystemd(const char *sd_notify_msg) {
|
||||
#ifdef HAVE_LIBSYSTEMD
|
||||
int ret = sd_notify(0, sd_notify_msg);
|
||||
|
||||
@ -6812,7 +6812,7 @@ static int redisSupervisedSystemd(void) {
|
||||
"systemd supervision requested or auto-detected, but Redis is compiled without libsystemd support!");
|
||||
return 0;
|
||||
#else
|
||||
if (redisCommunicateSystemd("STATUS=Redis is loading...\n") <= 0)
|
||||
if (serverCommunicateSystemd("STATUS=Redis is loading...\n") <= 0)
|
||||
return 0;
|
||||
serverLog(LL_NOTICE,
|
||||
"Supervised by systemd. Please make sure you set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit.");
|
||||
@ -7169,7 +7169,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
initServer();
|
||||
if (background || server.pidfile) createPidFile();
|
||||
if (server.set_proc_title) redisSetProcTitle(NULL);
|
||||
if (server.set_proc_title) serverSetProcTitle(NULL);
|
||||
redisAsciiArt();
|
||||
checkTcpBacklogSettings();
|
||||
if (server.cluster_enabled) {
|
||||
@ -7207,17 +7207,17 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
|
||||
if (!server.masterhost) {
|
||||
redisCommunicateSystemd("STATUS=Ready to accept connections\n");
|
||||
serverCommunicateSystemd("STATUS=Ready to accept connections\n");
|
||||
} else {
|
||||
redisCommunicateSystemd("STATUS=Ready to accept connections in read-only mode. Waiting for MASTER <-> REPLICA sync\n");
|
||||
serverCommunicateSystemd("STATUS=Ready to accept connections in read-only mode. Waiting for MASTER <-> REPLICA sync\n");
|
||||
}
|
||||
redisCommunicateSystemd("READY=1\n");
|
||||
serverCommunicateSystemd("READY=1\n");
|
||||
}
|
||||
} else {
|
||||
sentinelIsRunning();
|
||||
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
|
||||
redisCommunicateSystemd("STATUS=Ready to accept connections\n");
|
||||
redisCommunicateSystemd("READY=1\n");
|
||||
serverCommunicateSystemd("STATUS=Ready to accept connections\n");
|
||||
serverCommunicateSystemd("READY=1\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -7226,7 +7226,7 @@ int main(int argc, char **argv) {
|
||||
serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
|
||||
}
|
||||
|
||||
redisSetCpuAffinity(server.server_cpulist);
|
||||
serverSetCpuAffinity(server.server_cpulist);
|
||||
setOOMScoreAdj(-1);
|
||||
|
||||
aeMain(server.el);
|
||||
|
10
src/server.h
10
src/server.h
@ -2551,11 +2551,11 @@ void getRandomHexChars(char *p, size_t len);
|
||||
void getRandomBytes(unsigned char *p, size_t len);
|
||||
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
|
||||
void exitFromChild(int retcode);
|
||||
long long redisPopcount(void *s, long count);
|
||||
int redisSetProcTitle(char *title);
|
||||
long long serverPopcount(void *s, long count);
|
||||
int serverSetProcTitle(char *title);
|
||||
int validateProcTitleTemplate(const char *template);
|
||||
int redisCommunicateSystemd(const char *sd_notify_msg);
|
||||
void redisSetCpuAffinity(const char *cpulist);
|
||||
int serverCommunicateSystemd(const char *sd_notify_msg);
|
||||
void serverSetCpuAffinity(const char *cpulist);
|
||||
|
||||
/* afterErrorReply flags */
|
||||
#define ERR_REPLY_FLAG_NO_STATS_UPDATE (1ULL<<0) /* Indicating that we should not update
|
||||
@ -2906,7 +2906,7 @@ void sendChildInfo(childInfoType info_type, size_t keys, char *pname);
|
||||
void receiveChildInfo(void);
|
||||
|
||||
/* Fork helpers */
|
||||
int redisFork(int purpose);
|
||||
int serverFork(int purpose);
|
||||
int hasActiveChildProcess(void);
|
||||
void resetChildState(void);
|
||||
int isMutuallyExclusiveChildType(int type);
|
||||
|
Loading…
Reference in New Issue
Block a user