Factor out dependencies on rdb_child_pid which will be going away
Former-commit-id: 2ab4c6b99e3f3cb9f216bd81e78914a6fcd394f6
This commit is contained in:
parent
5fb7d4a325
commit
764a05fedd
10
src/aof.cpp
10
src/aof.cpp
@ -264,7 +264,7 @@ int startAppendOnly(void) {
|
||||
strerror(errno));
|
||||
return C_ERR;
|
||||
}
|
||||
if (g_pserver->rdb_child_pid != -1) {
|
||||
if (g_pserver->FRdbSaveInProgress()) {
|
||||
g_pserver->aof_rewrite_scheduled = 1;
|
||||
serverLog(LL_WARNING,"AOF was enabled but there is already a child process saving an RDB file on disk. An AOF background was scheduled to start when possible.");
|
||||
} else {
|
||||
@ -397,7 +397,7 @@ void flushAppendOnlyFile(int force) {
|
||||
* useful for graphing / monitoring purposes. */
|
||||
if (sync_in_progress) {
|
||||
latencyAddSampleIfNeeded("aof-write-pending-fsync",latency);
|
||||
} else if (g_pserver->aof_child_pid != -1 || g_pserver->rdb_child_pid != -1) {
|
||||
} else if (g_pserver->aof_child_pid != -1 || g_pserver->FRdbSaveInProgress()) {
|
||||
latencyAddSampleIfNeeded("aof-write-active-child",latency);
|
||||
} else {
|
||||
latencyAddSampleIfNeeded("aof-write-alone",latency);
|
||||
@ -494,7 +494,7 @@ try_fsync:
|
||||
/* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
|
||||
* children doing I/O in the background. */
|
||||
if (g_pserver->aof_no_fsync_on_rewrite &&
|
||||
(g_pserver->aof_child_pid != -1 || g_pserver->rdb_child_pid != -1))
|
||||
(g_pserver->aof_child_pid != -1 || g_pserver->FRdbSaveInProgress()))
|
||||
return;
|
||||
|
||||
/* Perform the fsync if needed. */
|
||||
@ -1593,7 +1593,7 @@ int rewriteAppendOnlyFileBackground(void) {
|
||||
pid_t childpid;
|
||||
long long start;
|
||||
|
||||
if (g_pserver->aof_child_pid != -1 || g_pserver->rdb_child_pid != -1) return C_ERR;
|
||||
if (g_pserver->aof_child_pid != -1 || g_pserver->FRdbSaveInProgress()) return C_ERR;
|
||||
if (aofCreatePipes() != C_OK) return C_ERR;
|
||||
openChildInfoPipe();
|
||||
start = ustime();
|
||||
@ -1652,7 +1652,7 @@ int rewriteAppendOnlyFileBackground(void) {
|
||||
void bgrewriteaofCommand(client *c) {
|
||||
if (g_pserver->aof_child_pid != -1) {
|
||||
addReplyError(c,"Background append only file rewriting already in progress");
|
||||
} else if (g_pserver->rdb_child_pid != -1) {
|
||||
} else if (g_pserver->FRdbSaveInProgress()) {
|
||||
g_pserver->aof_rewrite_scheduled = 1;
|
||||
addReplyStatus(c,"Background append only file rewriting scheduled");
|
||||
} else if (rewriteAppendOnlyFileBackground() == C_OK) {
|
||||
|
@ -74,7 +74,7 @@ static robj *lookupKey(redisDb *db, robj *key, int flags) {
|
||||
/* Update the access time for the ageing algorithm.
|
||||
* Don't do it if we have a saving child, as this will trigger
|
||||
* a copy on write madness. */
|
||||
if (g_pserver->rdb_child_pid == -1 &&
|
||||
if (!g_pserver->FRdbSaveInProgress() &&
|
||||
g_pserver->aof_child_pid == -1 &&
|
||||
!(flags & LOOKUP_NOTOUCH))
|
||||
{
|
||||
@ -545,7 +545,7 @@ void flushallCommand(client *c) {
|
||||
signalFlushedDb(-1);
|
||||
g_pserver->dirty += emptyDb(-1,flags,NULL);
|
||||
addReply(c,shared.ok);
|
||||
if (g_pserver->rdb_child_pid != -1) killRDBChild();
|
||||
if (g_pserver->FRdbSaveInProgress()) killRDBChild();
|
||||
if (g_pserver->saveparamslen > 0) {
|
||||
/* Normally rdbSave() will reset dirty, but we don't want this here
|
||||
* as otherwise FLUSHALL will not be replicated nor put into the AOF. */
|
||||
|
@ -1046,7 +1046,7 @@ void activeDefragCycle(void) {
|
||||
mstime_t latency;
|
||||
int quit = 0;
|
||||
|
||||
if (g_pserver->aof_child_pid!=-1 || g_pserver->rdb_child_pid!=-1)
|
||||
if (g_pserver->aof_child_pid!=-1 || g_pserver->FRdbSaveInProgress())
|
||||
return; /* Defragging memory while there's a fork will just do damage. */
|
||||
|
||||
/* Once a second, check if we the fragmentation justfies starting a scan
|
||||
|
@ -1365,7 +1365,7 @@ int rdbSaveBackground(rdbSaveInfo *rsi) {
|
||||
pid_t childpid;
|
||||
long long start;
|
||||
|
||||
if (g_pserver->aof_child_pid != -1 || g_pserver->rdb_child_pid != -1) return C_ERR;
|
||||
if (g_pserver->aof_child_pid != -1 || g_pserver->FRdbSaveInProgress()) return C_ERR;
|
||||
|
||||
g_pserver->dirty_before_bgsave = g_pserver->dirty;
|
||||
g_pserver->lastbgsave_try = time(NULL);
|
||||
@ -2400,7 +2400,7 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
|
||||
long long start;
|
||||
int pipefds[2];
|
||||
|
||||
if (g_pserver->aof_child_pid != -1 || g_pserver->rdb_child_pid != -1) return C_ERR;
|
||||
if (g_pserver->aof_child_pid != -1 || g_pserver->FRdbSaveInProgress()) return C_ERR;
|
||||
|
||||
/* Before to fork, create a pipe that will be used in order to
|
||||
* send back to the parent the IDs of the slaves that successfully
|
||||
@ -2556,7 +2556,7 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
|
||||
}
|
||||
|
||||
void saveCommand(client *c) {
|
||||
if (g_pserver->rdb_child_pid != -1) {
|
||||
if (g_pserver->FRdbSaveInProgress()) {
|
||||
addReplyError(c,"Background save already in progress");
|
||||
return;
|
||||
}
|
||||
@ -2587,7 +2587,7 @@ void bgsaveCommand(client *c) {
|
||||
rdbSaveInfo rsi, *rsiptr;
|
||||
rsiptr = rdbPopulateSaveInfo(&rsi);
|
||||
|
||||
if (g_pserver->rdb_child_pid != -1) {
|
||||
if (g_pserver->FRdbSaveInProgress()) {
|
||||
addReplyError(c,"Background save already in progress");
|
||||
} else if (g_pserver->aof_child_pid != -1) {
|
||||
if (schedule) {
|
||||
|
@ -858,7 +858,7 @@ void syncCommand(client *c) {
|
||||
}
|
||||
|
||||
/* CASE 1: BGSAVE is in progress, with disk target. */
|
||||
if (g_pserver->rdb_child_pid != -1 &&
|
||||
if (g_pserver->FRdbSaveInProgress() &&
|
||||
g_pserver->rdb_child_type == RDB_CHILD_TYPE_DISK)
|
||||
{
|
||||
/* Ok a background save is in progress. Let's check if it is a good
|
||||
@ -889,7 +889,7 @@ void syncCommand(client *c) {
|
||||
}
|
||||
|
||||
/* CASE 2: BGSAVE is in progress, with socket target. */
|
||||
} else if (g_pserver->rdb_child_pid != -1 &&
|
||||
} else if (g_pserver->FRdbSaveInProgress() &&
|
||||
g_pserver->rdb_child_type == RDB_CHILD_TYPE_SOCKET)
|
||||
{
|
||||
/* There is an RDB child process but it is writing directly to
|
||||
@ -1510,7 +1510,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
int aof_is_enabled = g_pserver->aof_state != AOF_OFF;
|
||||
|
||||
/* Ensure background save doesn't overwrite synced data */
|
||||
if (g_pserver->rdb_child_pid != -1) {
|
||||
if (g_pserver->FRdbSaveInProgress()) {
|
||||
serverLog(LL_NOTICE,
|
||||
"Replica is about to load the RDB file received from the "
|
||||
"master, but there is a pending RDB child running. "
|
||||
@ -3143,7 +3143,7 @@ void replicationCron(void) {
|
||||
* In case of diskless replication, we make sure to wait the specified
|
||||
* number of seconds (according to configuration) so that other slaves
|
||||
* have the time to arrive before we start streaming. */
|
||||
if (g_pserver->rdb_child_pid == -1 && g_pserver->aof_child_pid == -1) {
|
||||
if (!g_pserver->FRdbSaveInProgress() && g_pserver->aof_child_pid == -1) {
|
||||
time_t idle, max_idle = 0;
|
||||
int slaves_waiting = 0;
|
||||
int mincapa = -1;
|
||||
|
@ -1465,7 +1465,7 @@ int redisDbPersistentData::incrementallyRehash() {
|
||||
* for dict.c to resize the hash tables accordingly to the fact we have o not
|
||||
* running childs. */
|
||||
void updateDictResizePolicy(void) {
|
||||
if (g_pserver->rdb_child_pid == -1 && g_pserver->aof_child_pid == -1)
|
||||
if (!g_pserver->FRdbSaveInProgress() && g_pserver->aof_child_pid == -1)
|
||||
dictEnableResize();
|
||||
else
|
||||
dictDisableResize();
|
||||
@ -1712,7 +1712,7 @@ void databasesCron(void) {
|
||||
/* Perform hash tables rehashing if needed, but only if there are no
|
||||
* other processes saving the DB on disk. Otherwise rehashing is bad
|
||||
* as will cause a lot of copy-on-write of memory pages. */
|
||||
if (g_pserver->rdb_child_pid == -1 && g_pserver->aof_child_pid == -1) {
|
||||
if (!g_pserver->FRdbSaveInProgress() && g_pserver->aof_child_pid == -1) {
|
||||
/* We use global counters so if we stop the computation at a given
|
||||
* DB we'll be able to start from the successive in the next
|
||||
* cron loop iteration. */
|
||||
@ -1921,14 +1921,14 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
|
||||
|
||||
/* Start a scheduled AOF rewrite if this was requested by the user while
|
||||
* a BGSAVE was in progress. */
|
||||
if (g_pserver->rdb_child_pid == -1 && g_pserver->aof_child_pid == -1 &&
|
||||
if (!g_pserver->FRdbSaveInProgress() && g_pserver->aof_child_pid == -1 &&
|
||||
g_pserver->aof_rewrite_scheduled)
|
||||
{
|
||||
rewriteAppendOnlyFileBackground();
|
||||
}
|
||||
|
||||
/* Check if a background saving or AOF rewrite in progress terminated. */
|
||||
if (g_pserver->rdb_child_pid != -1 || g_pserver->aof_child_pid != -1 ||
|
||||
if (g_pserver->FRdbSaveInProgress() || g_pserver->aof_child_pid != -1 ||
|
||||
ldbPendingChildren())
|
||||
{
|
||||
int statloc;
|
||||
@ -1989,7 +1989,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
|
||||
|
||||
/* Trigger an AOF rewrite if needed. */
|
||||
if (g_pserver->aof_state == AOF_ON &&
|
||||
g_pserver->rdb_child_pid == -1 &&
|
||||
!g_pserver->FRdbSaveInProgress() &&
|
||||
g_pserver->aof_child_pid == -1 &&
|
||||
g_pserver->aof_rewrite_perc &&
|
||||
g_pserver->aof_current_size > g_pserver->aof_rewrite_min_size)
|
||||
@ -2045,7 +2045,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
|
||||
* Note: this code must be after the replicationCron() call above so
|
||||
* make sure when refactoring this file to keep this order. This is useful
|
||||
* because we want to give priority to RDB savings for replication. */
|
||||
if (g_pserver->rdb_child_pid == -1 && g_pserver->aof_child_pid == -1 &&
|
||||
if (!g_pserver->FRdbSaveInProgress() && g_pserver->aof_child_pid == -1 &&
|
||||
g_pserver->rdb_bgsave_scheduled &&
|
||||
(g_pserver->unixtime-g_pserver->lastbgsave_try > CONFIG_BGSAVE_RETRY_DELAY ||
|
||||
g_pserver->lastbgsave_status == C_OK))
|
||||
@ -3742,7 +3742,7 @@ int prepareForShutdown(int flags) {
|
||||
/* Kill the saving child if there is a background saving in progress.
|
||||
We want to avoid race conditions, for instance our saving child may
|
||||
overwrite the synchronous saving did by SHUTDOWN. */
|
||||
if (g_pserver->rdb_child_pid != -1) {
|
||||
if (g_pserver->FRdbSaveInProgress()) {
|
||||
serverLog(LL_WARNING,"There is a child saving an .rdb. Killing it!");
|
||||
killRDBChild();
|
||||
}
|
||||
@ -4256,12 +4256,12 @@ sds genRedisInfoString(const char *section) {
|
||||
"aof_last_cow_size:%zu\r\n",
|
||||
g_pserver->loading,
|
||||
g_pserver->dirty,
|
||||
g_pserver->rdb_child_pid != -1,
|
||||
g_pserver->FRdbSaveInProgress(),
|
||||
(intmax_t)g_pserver->lastsave,
|
||||
(g_pserver->lastbgsave_status == C_OK) ? "ok" : "err",
|
||||
(intmax_t)g_pserver->rdb_save_time_last,
|
||||
(intmax_t)((g_pserver->rdb_child_pid == -1) ?
|
||||
-1 : time(NULL)-g_pserver->rdb_save_time_start),
|
||||
(intmax_t)(g_pserver->FRdbSaveInProgress() ?
|
||||
time(NULL)-g_pserver->rdb_save_time_start : -1),
|
||||
g_pserver->stat_rdb_cow_bytes,
|
||||
g_pserver->aof_state != AOF_OFF,
|
||||
g_pserver->aof_child_pid != -1,
|
||||
|
@ -2000,6 +2000,8 @@ struct redisServer {
|
||||
|
||||
/* System hardware info */
|
||||
size_t system_memory_size; /* Total memory in system as reported by OS */
|
||||
|
||||
bool FRdbSaveInProgress() const { return rdb_child_pid != -1; }
|
||||
};
|
||||
|
||||
typedef struct pubsubPattern {
|
||||
|
Loading…
x
Reference in New Issue
Block a user