Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
35942383
Commit
35942383
authored
Nov 02, 2017
by
zhaozhao.zz
Committed by
antirez
Nov 24, 2017
Browse files
PSYNC2: clarify the scenario when repl_stream_db can be -1
parent
be1b9ee0
Changes
2
Show whitespace changes
Inline
Side-by-side
src/rdb.c
View file @
35942383
...
@@ -2036,14 +2036,25 @@ rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) {
...
@@ -2036,14 +2036,25 @@ rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) {
*
rsi
=
rsi_init
;
*
rsi
=
rsi_init
;
/* If the instance is a master, we can populate the replication info
/* If the instance is a master, we can populate the replication info
* in all the cases, even if sometimes in incomplete (but safe) form. */
* only when repl_backlog is not NULL. If the repl_backlog is NULL,
if
(
!
server
.
masterhost
)
{
* it means that the instance isn't in any replication chains. In this
if
(
server
.
repl_backlog
)
rsi
->
repl_stream_db
=
server
.
slaveseldb
;
* scenario the replication info is useless, because when a slave
/* Note that if repl_backlog is NULL, it means that histories
* connect to us, the NULL repl_backlog will trigger a full synchronization,
* following from this point will trigger a full synchronization
* at the same time we will use a new replid and clear replid2.
* generating a SELECT statement, so we can leave the currently
* And remember that after free backlog if we reach repl_backlog_time_limit,
* selected DB set to -1. This allows a restarted master to reload
* we will use a new replid and clear replid2 too. So there is only one
* its replication ID/offset when there are no connected slaves. */
* scenario which can make repl_stream_db be -1, that is the instance is
* a master, and it have repl_backlog, but server.slaveseldb is -1. */
if
(
!
server
.
masterhost
&&
server
.
repl_backlog
)
{
rsi
->
repl_stream_db
=
server
.
slaveseldb
;
/* Note that server.slaveseldb may be -1, it means that this master
* didn't apply any write commands after a full synchronization,
* so we can leave the currently selected DB set to -1, because the
* next write command must generate a SELECT statement. This allows
* a restarted slave to reload replication ID/offset even the repl_stream_db
* is -1, but we should not do that, because older implementations
* may save a repl_stream_db as -1 in a wrong way. Maybe we can fix
* it in the next release version. */
return
rsi
;
return
rsi
;
}
}
...
...
src/server.c
View file @
35942383
...
@@ -3540,7 +3540,8 @@ void loadDataFromDisk(void) {
...
@@ -3540,7 +3540,8 @@ void loadDataFromDisk(void) {
rsi
.
repl_id_is_set
&&
rsi
.
repl_id_is_set
&&
rsi
.
repl_offset
!=
-
1
&&
rsi
.
repl_offset
!=
-
1
&&
/* Note that older implementations may save a repl_stream_db
/* Note that older implementations may save a repl_stream_db
* of -1 inside the RDB file. */
* of -1 inside the RDB file in a wrong way, see more information
* in function rdbPopulateSaveInfo. */
rsi
.
repl_stream_db
!=
-
1
)
rsi
.
repl_stream_db
!=
-
1
)
{
{
memcpy
(
server
.
replid
,
rsi
.
repl_id
,
sizeof
(
server
.
replid
));
memcpy
(
server
.
replid
,
rsi
.
repl_id
,
sizeof
(
server
.
replid
));
...
...
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