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
3bab69e9
Commit
3bab69e9
authored
Mar 04, 2020
by
antirez
Browse files
Make sync RDB deletion configurable. Default to no.
parent
d16bb64f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/config.c
View file @
3bab69e9
...
@@ -2084,6 +2084,7 @@ standardConfig configs[] = {
...
@@ -2084,6 +2084,7 @@ standardConfig configs[] = {
createBoolConfig
(
"always-show-logo"
,
NULL
,
IMMUTABLE_CONFIG
,
server
.
always_show_logo
,
0
,
NULL
,
NULL
),
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
(
"protected-mode"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
protected_mode
,
1
,
NULL
,
NULL
),
createBoolConfig
(
"rdbcompression"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
rdb_compression
,
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
(
"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
(
"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.*/
createBoolConfig
(
"dynamic-hz"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
dynamic_hz
,
1
,
NULL
,
NULL
),
/* Adapt hz to # of clients.*/
...
...
src/replication.c
View file @
3bab69e9
...
@@ -625,8 +625,12 @@ int startBgsaveForReplication(int mincapa) {
...
@@ -625,8 +625,12 @@ int startBgsaveForReplication(int mincapa) {
}
}
/* If we succeeded to start a BGSAVE with disk target, let's remember
/* 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. */
* this fact, so that we can later delete the file if needed. Note
if
(
retval
==
C_OK
&&
!
socket_target
)
RDBGeneratedByReplication
=
1
;
* 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
/* 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
...
@@ -926,6 +930,17 @@ void putSlaveOnline(client *slave) {
...
@@ -926,6 +930,17 @@ void putSlaveOnline(client *slave) {
* to take RDB files around, this violates certain policies in certain
* to take RDB files around, this violates certain policies in certain
* environments. */
* environments. */
void
removeRDBUsedToSyncReplicas
(
void
)
{
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
)
{
if
(
allPersistenceDisabled
()
&&
RDBGeneratedByReplication
)
{
client
*
slave
;
client
*
slave
;
listNode
*
ln
;
listNode
*
ln
;
...
@@ -1713,7 +1728,7 @@ void readSyncBulkPayload(connection *conn) {
...
@@ -1713,7 +1728,7 @@ 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
())
{
if
(
server
.
rdb_del_sync_files
&&
allPersistenceDisabled
())
{
serverLog
(
LL_NOTICE
,
"Removing the RDB file obtained from "
serverLog
(
LL_NOTICE
,
"Removing the RDB file obtained from "
"the master. This replica has persistence "
"the master. This replica has persistence "
"disabled"
);
"disabled"
);
...
@@ -1725,7 +1740,7 @@ void readSyncBulkPayload(connection *conn) {
...
@@ -1725,7 +1740,7 @@ void readSyncBulkPayload(connection *conn) {
}
}
/* Cleanup. */
/* Cleanup. */
if
(
allPersistenceDisabled
())
{
if
(
server
.
rdb_del_sync_files
&&
allPersistenceDisabled
())
{
serverLog
(
LL_NOTICE
,
"Removing the RDB file obtained from "
serverLog
(
LL_NOTICE
,
"Removing the RDB file obtained from "
"the master. This replica has persistence "
"the master. This replica has persistence "
"disabled"
);
"disabled"
);
...
...
src/server.h
View file @
3bab69e9
...
@@ -1202,6 +1202,8 @@ struct redisServer {
...
@@ -1202,6 +1202,8 @@ struct redisServer {
char
*
rdb_filename
;
/* Name of RDB file */
char
*
rdb_filename
;
/* Name of RDB file */
int
rdb_compression
;
/* Use compression in RDB? */
int
rdb_compression
;
/* Use compression in RDB? */
int
rdb_checksum
;
/* Use RDB checksum? */
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
lastsave
;
/* Unix time of last successful save */
time_t
lastbgsave_try
;
/* Unix time of last attempted bgsave */
time_t
lastbgsave_try
;
/* Unix time of last attempted bgsave */
time_t
rdb_save_time_last
;
/* Time used by last RDB save run. */
time_t
rdb_save_time_last
;
/* Time used by last RDB save run. */
...
...
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