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
79567b6e
Commit
79567b6e
authored
Sep 20, 2017
by
antirez
Browse files
PSYNC2: More refinements related to #4316.
parent
f1194649
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/rdb.c
View file @
79567b6e
...
@@ -2019,14 +2019,7 @@ void bgsaveCommand(client *c) {
...
@@ -2019,14 +2019,7 @@ void bgsaveCommand(client *c) {
}
}
/* Populate the rdbSaveInfo structure used to persist the replication
/* Populate the rdbSaveInfo structure used to persist the replication
* information inside the RDB file.
* information inside the RDB file. Currently the structure explicitly
* For master, if server.repl_backlog is not NULL, fill rdbSaveInfo with
* server.slaveseldb, otherwise just use init -1.
* Don't worry, master will send SELECT command to replication stream,
* because if server.repl_backlog is NULL, that will trigger full synchronization,
* function replicationSetupSlaveForFullResync() sets server.slaveseldb be -1,
* then replicationFeedSlaves() will send SELECT command when server.slaveseldb is -1.
* For slave, currently the structure explicitly
* contains just the currently selected DB from the master stream, however
* contains just the currently selected DB from the master stream, however
* if the rdbSave*() family functions receive a NULL rsi structure also
* if the rdbSave*() family functions receive a NULL rsi structure also
* the Replication ID/offset is not saved. The function popultes 'rsi'
* the Replication ID/offset is not saved. The function popultes 'rsi'
...
@@ -2037,15 +2030,24 @@ void bgsaveCommand(client *c) {
...
@@ -2037,15 +2030,24 @@ void bgsaveCommand(client *c) {
rdbSaveInfo
*
rdbPopulateSaveInfo
(
rdbSaveInfo
*
rsi
)
{
rdbSaveInfo
*
rdbPopulateSaveInfo
(
rdbSaveInfo
*
rsi
)
{
rdbSaveInfo
rsi_init
=
RDB_SAVE_INFO_INIT
;
rdbSaveInfo
rsi_init
=
RDB_SAVE_INFO_INIT
;
*
rsi
=
rsi_init
;
*
rsi
=
rsi_init
;
/* If the instance is a master, we can populate the replication info
* in all the cases, even if sometimes in incomplete (but safe) form. */
if
(
!
server
.
masterhost
)
{
if
(
!
server
.
masterhost
)
{
if
(
server
.
repl_backlog
)
rsi
->
repl_stream_db
=
server
.
slaveseldb
;
if
(
server
.
repl_backlog
)
rsi
->
repl_stream_db
=
server
.
slaveseldb
;
/* Note that if repl_backlog is NULL, it means that histories
* following from this point will trigger a full synchronization
* generating a SELECT statement, so we can leave the currently
* selected DB set to -1. This allows a restarted master to reload
* its replication ID/offset when there are no connected slaves. */
return
rsi
;
return
rsi
;
}
}
/* If the instance is a slave we need a connected master in order to
* fetch the currently selected DB. */
if
(
server
.
master
)
{
if
(
server
.
master
)
{
rsi
->
repl_stream_db
=
server
.
master
->
db
->
id
;
rsi
->
repl_stream_db
=
server
.
master
->
db
->
id
;
return
rsi
;
return
rsi
;
}
else
{
serverLog
(
LL_WARNING
,
"As a slave there is no valid master, can not persist replication information"
);
return
NULL
;
}
}
return
NULL
;
}
}
src/replication.c
View file @
79567b6e
...
@@ -579,6 +579,7 @@ int startBgsaveForReplication(int mincapa) {
...
@@ -579,6 +579,7 @@ int startBgsaveForReplication(int mincapa) {
else
else
retval
=
rdbSaveBackground
(
server
.
rdb_filename
,
rsiptr
);
retval
=
rdbSaveBackground
(
server
.
rdb_filename
,
rsiptr
);
}
else
{
}
else
{
serverLog
(
LL_WARNING
,
"BGSAVE for replication: replication information not available, can't generate the RDB file right now. Try later."
);
retval
=
C_ERR
;
retval
=
C_ERR
;
}
}
...
...
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