summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2020-03-04 17:44:21 +0100
committerantirez <antirez@gmail.com>2020-03-05 12:51:15 +0100
commit127e09bca16a23e987820dc45f5cdb8a6fa6a3fa (patch)
tree9106ea9f30a0523f36696eed2c1aaa549a331f62
parenta20303c62339fcaa07bd7872df7fe05d9fe54b1f (diff)
downloadredis-127e09bca16a23e987820dc45f5cdb8a6fa6a3fa.tar.gz
Make sync RDB deletion configurable. Default to no.
-rw-r--r--src/config.c1
-rw-r--r--src/replication.c23
-rw-r--r--src/server.h2
3 files changed, 22 insertions, 4 deletions
diff --git a/src/config.c b/src/config.c
index fd04b7c87..211b6d003 100644
--- a/src/config.c
+++ b/src/config.c
@@ -2084,6 +2084,7 @@ standardConfig configs[] = {
createBoolConfig("always-show-logo", NULL, IMMUTABLE_CONFIG, server.always_show_logo, 0, NULL, NULL),
createBoolConfig("protected-mode", NULL, MODIFIABLE_CONFIG, server.protected_mode, 1, NULL, NULL),
createBoolConfig("rdbcompression", NULL, MODIFIABLE_CONFIG, server.rdb_compression, 1, NULL, NULL),
+ createBoolConfig("rdb-del-sync-files", NULL, MODIFIABLE_CONFIG, server.rdb_del_sync_files, 0, NULL, NULL),
createBoolConfig("activerehashing", NULL, MODIFIABLE_CONFIG, server.activerehashing, 1, NULL, NULL),
createBoolConfig("stop-writes-on-bgsave-error", NULL, MODIFIABLE_CONFIG, server.stop_writes_on_bgsave_err, 1, NULL, NULL),
createBoolConfig("dynamic-hz", NULL, MODIFIABLE_CONFIG, server.dynamic_hz, 1, NULL, NULL), /* Adapt hz to # of clients.*/
diff --git a/src/replication.c b/src/replication.c
index 20666bd20..429e1d8a8 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -625,8 +625,12 @@ int startBgsaveForReplication(int mincapa) {
}
/* 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;
+ * this fact, so that we can later delete the file if needed. Note
+ * that we don't set the flag to 1 if the feature is disabled, otherwise
+ * it would never be cleared: the file is not deleted. This way if
+ * the user enables it later with CONFIG SET, we are fine. */
+ if (retval == C_OK && !socket_target && server.rdb_del_sync_files)
+ RDBGeneratedByReplication = 1;
/* If we failed to BGSAVE, remove the slaves waiting for a full
* resynchronization from the list of slaves, inform them with
@@ -926,6 +930,17 @@ void putSlaveOnline(client *slave) {
* to take RDB files around, this violates certain policies in certain
* environments. */
void removeRDBUsedToSyncReplicas(void) {
+ /* If the feature is disabled, return ASAP but also clear the
+ * RDBGeneratedByReplication flag in case it was set. Otherwise if the
+ * feature was enabled, but gets disabled later with CONFIG SET, the
+ * flag may remain set to one: then next time the feature is re-enabled
+ * via CONFIG SET we have have it set even if no RDB was generated
+ * because of replication recently. */
+ if (!server.rdb_del_sync_files) {
+ RDBGeneratedByReplication = 0;
+ return;
+ }
+
if (allPersistenceDisabled() && RDBGeneratedByReplication) {
client *slave;
listNode *ln;
@@ -1713,7 +1728,7 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to load the MASTER synchronization "
"DB from disk");
cancelReplicationHandshake();
- if (allPersistenceDisabled()) {
+ if (server.rdb_del_sync_files && allPersistenceDisabled()) {
serverLog(LL_NOTICE,"Removing the RDB file obtained from "
"the master. This replica has persistence "
"disabled");
@@ -1725,7 +1740,7 @@ void readSyncBulkPayload(connection *conn) {
}
/* Cleanup. */
- if (allPersistenceDisabled()) {
+ if (server.rdb_del_sync_files && allPersistenceDisabled()) {
serverLog(LL_NOTICE,"Removing the RDB file obtained from "
"the master. This replica has persistence "
"disabled");
diff --git a/src/server.h b/src/server.h
index 5763671e4..3c19a17ea 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1202,6 +1202,8 @@ struct redisServer {
char *rdb_filename; /* Name of RDB file */
int rdb_compression; /* Use compression in RDB? */
int rdb_checksum; /* Use RDB checksum? */
+ int rdb_del_sync_files; /* Remove RDB files used only for SYNC if
+ the instance does not use persistence. */
time_t lastsave; /* Unix time of last successful save */
time_t lastbgsave_try; /* Unix time of last attempted bgsave */
time_t rdb_save_time_last; /* Time used by last RDB save run. */