Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
5e2319c3
Commit
5e2319c3
authored
Mar 03, 2020
by
antirez
Browse files
Remove RDB files used for replication in persistence-less instances.
parent
6dd8de17
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/replication.c
View file @
5e2319c3
...
@@ -45,6 +45,11 @@ void replicationSendAck(void);
...
@@ -45,6 +45,11 @@ void replicationSendAck(void);
void putSlaveOnline(client *slave);
void putSlaveOnline(client *slave);
int cancelReplicationHandshake(void);
int cancelReplicationHandshake(void);
/* We take a global flag to remember if this instance generated an RDB
* because of replication, so that we can remove the RDB file in case
* the instance is configured to have no persistence. */
int RDBGeneratedByReplication = 0;
/* --------------------------- Utility functions ---------------------------- */
/* --------------------------- Utility functions ---------------------------- */
/* Return the pointer to a string representing the slave ip:listening_port
/* Return the pointer to a string representing the slave ip:listening_port
...
@@ -591,6 +596,10 @@ int startBgsaveForReplication(int mincapa) {
...
@@ -591,6 +596,10 @@ int startBgsaveForReplication(int mincapa) {
retval = C_ERR;
retval = C_ERR;
}
}
/* If we succeeded to start a BGSAVE with disk target, let's remember
* this fact, so that we can later delete the file if needed. */
if (retval == C_OK && !socket_target) RDBGeneratedByReplication = 1;
/* If we failed to BGSAVE, remove the slaves waiting for a full
/* If we failed to BGSAVE, remove the slaves waiting for a full
* resynchronization from the list of slaves, inform them with
* resynchronization from the list of slaves, inform them with
* an error about what happened, close the connection ASAP. */
* an error about what happened, close the connection ASAP. */
...
@@ -883,6 +892,36 @@ void putSlaveOnline(client *slave) {
...
@@ -883,6 +892,36 @@ void putSlaveOnline(client *slave) {
replicationGetSlaveName(slave));
replicationGetSlaveName(slave));
}
}
/* We call this function periodically to remove an RDB file that was
* generated because of replication, in an instance that is otherwise
* without any persistence. We don't want instances without persistence
* to take RDB files around, this violates certain policies in certain
* environments. */
void removeRDBUsedToSyncReplicas(void) {
if (allPersistenceDisabled() && RDBGeneratedByReplication) {
client *slave;
listNode *ln;
listIter li;
int delrdb = 1;
listRewind(server.slaves,&li);
while((ln = listNext(&li))) {
slave = ln->value;
if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START ||
slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END ||
slave->replstate == SLAVE_STATE_SEND_BULK)
{
delrdb = 0;
break; /* No need to check the other replicas. */
}
}
if (delrdb) {
RDBGeneratedByReplication = 0;
unlink(server.rdb_filename);
}
}
}
void sendBulkToSlave(connection *conn) {
void sendBulkToSlave(connection *conn) {
client *slave = connGetPrivateData(conn);
client *slave = connGetPrivateData(conn);
char buf[PROTO_IOBUF_LEN];
char buf[PROTO_IOBUF_LEN];
...
@@ -894,7 +933,8 @@ void sendBulkToSlave(connection *conn) {
...
@@ -894,7 +933,8 @@ void sendBulkToSlave(connection *conn) {
if (slave->replpreamble) {
if (slave->replpreamble) {
nwritten = connWrite(conn,slave->replpreamble,sdslen(slave->replpreamble));
nwritten = connWrite(conn,slave->replpreamble,sdslen(slave->replpreamble));
if (nwritten == -1) {
if (nwritten == -1) {
serverLog
(
LL_VERBOSE
,
"Write error sending RDB preamble to replica: %s"
,
serverLog(LL_VERBOSE,
"Write error sending RDB preamble to replica: %s",
connGetLastError(conn));
connGetLastError(conn));
freeClient(slave);
freeClient(slave);
return;
return;
...
@@ -1639,12 +1679,14 @@ void readSyncBulkPayload(connection *conn) {
...
@@ -1639,12 +1679,14 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to load the MASTER synchronization "
"Failed trying to load the MASTER synchronization "
"DB from disk");
"DB from disk");
cancelReplicationHandshake();
cancelReplicationHandshake();
if (allPersistenceDisabled()) unlink(server.rdb_filename);
/* Note that there's no point in restarting the AOF on sync failure,
/* Note that there's no point in restarting the AOF on sync failure,
it'll be restarted when sync succeeds or replica promoted. */
it'll be restarted when sync succeeds or replica promoted. */
return;
return;
}
}
/* Cleanup. */
/* Cleanup. */
if (allPersistenceDisabled()) unlink(server.rdb_filename);
zfree(server.repl_transfer_tmpfile);
zfree(server.repl_transfer_tmpfile);
close(server.repl_transfer_fd);
close(server.repl_transfer_fd);
server.repl_transfer_fd = -1;
server.repl_transfer_fd = -1;
...
@@ -3149,6 +3191,10 @@ void replicationCron(void) {
...
@@ -3149,6 +3191,10 @@ void replicationCron(void) {
}
}
}
}
/* Remove the RDB file used for replication if Redis is not running
* with any persistence. */
removeRDBUsedToSyncReplicas();
/* Refresh the number of slaves with lag <= min-slaves-max-lag. */
/* Refresh the number of slaves with lag <= min-slaves-max-lag. */
refreshGoodSlavesCount();
refreshGoodSlavesCount();
replication_cron_loops++; /* Incremented with frequency 1 HZ. */
replication_cron_loops++; /* Incremented with frequency 1 HZ. */
...
...
src/server.c
View file @
5e2319c3
...
@@ -1455,12 +1455,20 @@ void updateDictResizePolicy(void) {
...
@@ -1455,12 +1455,20 @@ void updateDictResizePolicy(void) {
dictDisableResize
();
dictDisableResize
();
}
}
/* Return true if there are no active children processes doing RDB saving,
* AOF rewriting, or some side process spawned by a loaded module. */
int
hasActiveChildProcess
()
{
int
hasActiveChildProcess
()
{
return
server
.
rdb_child_pid
!=
-
1
||
return
server
.
rdb_child_pid
!=
-
1
||
server
.
aof_child_pid
!=
-
1
||
server
.
aof_child_pid
!=
-
1
||
server
.
module_child_pid
!=
-
1
;
server
.
module_child_pid
!=
-
1
;
}
}
/* Return true if this instance has persistence completely turned off:
* both RDB and AOF are disabled. */
int
allPersistenceDisabled
(
void
)
{
return
server
.
saveparamslen
==
0
&&
server
.
aof_state
==
AOF_OFF
;
}
/* ======================= Cron: called every 100 ms ======================== */
/* ======================= Cron: called every 100 ms ======================== */
/* Add a sample to the operations per second array of samples. */
/* Add a sample to the operations per second array of samples. */
...
...
src/server.h
View file @
5e2319c3
...
@@ -1786,6 +1786,7 @@ void loadingProgress(off_t pos);
...
@@ -1786,6 +1786,7 @@ void loadingProgress(off_t pos);
void
stopLoading
(
int
success
);
void
stopLoading
(
int
success
);
void
startSaving
(
int
rdbflags
);
void
startSaving
(
int
rdbflags
);
void
stopSaving
(
int
success
);
void
stopSaving
(
int
success
);
int
allPersistenceDisabled
(
void
);
#define DISK_ERROR_TYPE_AOF 1
/* Don't accept writes: AOF errors. */
#define DISK_ERROR_TYPE_AOF 1
/* Don't accept writes: AOF errors. */
#define DISK_ERROR_TYPE_RDB 2
/* Don't accept writes: RDB errors. */
#define DISK_ERROR_TYPE_RDB 2
/* Don't accept writes: RDB errors. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment