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
1844f990
Commit
1844f990
authored
Dec 21, 2011
by
antirez
Browse files
server.replstate -> server.repl_state
parent
f48cd4b9
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/config.c
View file @
1844f990
...
@@ -179,7 +179,7 @@ void loadServerConfigFromString(char *config) {
...
@@ -179,7 +179,7 @@ void loadServerConfigFromString(char *config) {
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slaveof"
)
&&
argc
==
3
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slaveof"
)
&&
argc
==
3
)
{
server
.
masterhost
=
sdsnew
(
argv
[
1
]);
server
.
masterhost
=
sdsnew
(
argv
[
1
]);
server
.
masterport
=
atoi
(
argv
[
2
]);
server
.
masterport
=
atoi
(
argv
[
2
]);
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
repl
_
state
=
REDIS_REPL_CONNECT
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"repl-ping-slave-period"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"repl-ping-slave-period"
)
&&
argc
==
2
)
{
server
.
repl_ping_slave_period
=
atoi
(
argv
[
1
]);
server
.
repl_ping_slave_period
=
atoi
(
argv
[
1
]);
if
(
server
.
repl_ping_slave_period
<=
0
)
{
if
(
server
.
repl_ping_slave_period
<=
0
)
{
...
...
src/networking.c
View file @
1844f990
...
@@ -519,7 +519,7 @@ void freeClient(redisClient *c) {
...
@@ -519,7 +519,7 @@ void freeClient(redisClient *c) {
/* Case 2: we lost the connection with the master. */
/* Case 2: we lost the connection with the master. */
if
(
c
->
flags
&
REDIS_MASTER
)
{
if
(
c
->
flags
&
REDIS_MASTER
)
{
server
.
master
=
NULL
;
server
.
master
=
NULL
;
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
repl
_
state
=
REDIS_REPL_CONNECT
;
server
.
repl_down_since
=
time
(
NULL
);
server
.
repl_down_since
=
time
(
NULL
);
/* Since we lost the connection with the master, we should also
/* Since we lost the connection with the master, we should also
* close the connection with all our slaves if we have any, so
* close the connection with all our slaves if we have any, so
...
...
src/redis.c
View file @
1844f990
...
@@ -923,7 +923,7 @@ void initServerConfig() {
...
@@ -923,7 +923,7 @@ void initServerConfig() {
server
.
masterhost
=
NULL
;
server
.
masterhost
=
NULL
;
server
.
masterport
=
6379
;
server
.
masterport
=
6379
;
server
.
master
=
NULL
;
server
.
master
=
NULL
;
server
.
replstate
=
REDIS_REPL_NONE
;
server
.
repl
_
state
=
REDIS_REPL_NONE
;
server
.
repl_syncio_timeout
=
REDIS_REPL_SYNCIO_TIMEOUT
;
server
.
repl_syncio_timeout
=
REDIS_REPL_SYNCIO_TIMEOUT
;
server
.
repl_serve_stale_data
=
1
;
server
.
repl_serve_stale_data
=
1
;
server
.
repl_down_since
=
-
1
;
server
.
repl_down_since
=
-
1
;
...
@@ -1254,7 +1254,7 @@ int processCommand(redisClient *c) {
...
@@ -1254,7 +1254,7 @@ int processCommand(redisClient *c) {
/* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
/* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
* we are a slave with a broken link with master. */
* we are a slave with a broken link with master. */
if
(
server
.
masterhost
&&
server
.
replstate
!=
REDIS_REPL_CONNECTED
&&
if
(
server
.
masterhost
&&
server
.
repl
_
state
!=
REDIS_REPL_CONNECTED
&&
server
.
repl_serve_stale_data
==
0
&&
server
.
repl_serve_stale_data
==
0
&&
c
->
cmd
->
proc
!=
infoCommand
&&
c
->
cmd
->
proc
!=
slaveofCommand
)
c
->
cmd
->
proc
!=
infoCommand
&&
c
->
cmd
->
proc
!=
slaveofCommand
)
{
{
...
@@ -1592,14 +1592,14 @@ sds genRedisInfoString(char *section) {
...
@@ -1592,14 +1592,14 @@ sds genRedisInfoString(char *section) {
"master_sync_in_progress:%d
\r\n
"
"master_sync_in_progress:%d
\r\n
"
,
server
.
masterhost
,
,
server
.
masterhost
,
server
.
masterport
,
server
.
masterport
,
(
server
.
replstate
==
REDIS_REPL_CONNECTED
)
?
(
server
.
repl
_
state
==
REDIS_REPL_CONNECTED
)
?
"up"
:
"down"
,
"up"
:
"down"
,
server
.
master
?
server
.
master
?
((
int
)(
time
(
NULL
)
-
server
.
master
->
lastinteraction
))
:
-
1
,
((
int
)(
time
(
NULL
)
-
server
.
master
->
lastinteraction
))
:
-
1
,
server
.
replstate
==
REDIS_REPL_TRANSFER
server
.
repl
_
state
==
REDIS_REPL_TRANSFER
);
);
if
(
server
.
replstate
==
REDIS_REPL_TRANSFER
)
{
if
(
server
.
repl
_
state
==
REDIS_REPL_TRANSFER
)
{
info
=
sdscatprintf
(
info
,
info
=
sdscatprintf
(
info
,
"master_sync_left_bytes:%ld
\r\n
"
"master_sync_left_bytes:%ld
\r\n
"
"master_sync_last_io_seconds_ago:%d
\r\n
"
"master_sync_last_io_seconds_ago:%d
\r\n
"
...
@@ -1608,7 +1608,7 @@ sds genRedisInfoString(char *section) {
...
@@ -1608,7 +1608,7 @@ sds genRedisInfoString(char *section) {
);
);
}
}
if
(
server
.
replstate
!=
REDIS_REPL_CONNECTED
)
{
if
(
server
.
repl
_
state
!=
REDIS_REPL_CONNECTED
)
{
info
=
sdscatprintf
(
info
,
info
=
sdscatprintf
(
info
,
"master_link_down_since_seconds:%ld
\r\n
"
,
"master_link_down_since_seconds:%ld
\r\n
"
,
(
long
)
time
(
NULL
)
-
server
.
repl_down_since
);
(
long
)
time
(
NULL
)
-
server
.
repl_down_since
);
...
...
src/redis.h
View file @
1844f990
...
@@ -588,7 +588,7 @@ struct redisServer {
...
@@ -588,7 +588,7 @@ struct redisServer {
int
repl_timeout
;
/* Timeout after N seconds of master idle */
int
repl_timeout
;
/* Timeout after N seconds of master idle */
redisClient
*
master
;
/* Client that is master for this slave */
redisClient
*
master
;
/* Client that is master for this slave */
int
repl_syncio_timeout
;
/* Timeout for synchronous I/O calls */
int
repl_syncio_timeout
;
/* Timeout for synchronous I/O calls */
int
replstate
;
/* Replication status if the instance is a slave */
int
repl
_
state
;
/* Replication status if the instance is a slave */
off_t
repl_transfer_left
;
/* Bytes left reading .rdb */
off_t
repl_transfer_left
;
/* Bytes left reading .rdb */
int
repl_transfer_s
;
/* Slave -> Master SYNC socket */
int
repl_transfer_s
;
/* Slave -> Master SYNC socket */
int
repl_transfer_fd
;
/* Slave -> Master SYNC temp file descriptor */
int
repl_transfer_fd
;
/* Slave -> Master SYNC temp file descriptor */
...
...
src/replication.c
View file @
1844f990
...
@@ -89,7 +89,7 @@ void syncCommand(redisClient *c) {
...
@@ -89,7 +89,7 @@ void syncCommand(redisClient *c) {
/* Refuse SYNC requests if we are a slave but the link with our master
/* Refuse SYNC requests if we are a slave but the link with our master
* is not ok... */
* is not ok... */
if
(
server
.
masterhost
&&
server
.
replstate
!=
REDIS_REPL_CONNECTED
)
{
if
(
server
.
masterhost
&&
server
.
repl
_
state
!=
REDIS_REPL_CONNECTED
)
{
addReplyError
(
c
,
"Can't SYNC while not connected with my master"
);
addReplyError
(
c
,
"Can't SYNC while not connected with my master"
);
return
;
return
;
}
}
...
@@ -265,14 +265,14 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {
...
@@ -265,14 +265,14 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {
/* Abort the async download of the bulk dataset while SYNC-ing with master */
/* Abort the async download of the bulk dataset while SYNC-ing with master */
void
replicationAbortSyncTransfer
(
void
)
{
void
replicationAbortSyncTransfer
(
void
)
{
redisAssert
(
server
.
replstate
==
REDIS_REPL_TRANSFER
);
redisAssert
(
server
.
repl
_
state
==
REDIS_REPL_TRANSFER
);
aeDeleteFileEvent
(
server
.
el
,
server
.
repl_transfer_s
,
AE_READABLE
);
aeDeleteFileEvent
(
server
.
el
,
server
.
repl_transfer_s
,
AE_READABLE
);
close
(
server
.
repl_transfer_s
);
close
(
server
.
repl_transfer_s
);
close
(
server
.
repl_transfer_fd
);
close
(
server
.
repl_transfer_fd
);
unlink
(
server
.
repl_transfer_tmpfile
);
unlink
(
server
.
repl_transfer_tmpfile
);
zfree
(
server
.
repl_transfer_tmpfile
);
zfree
(
server
.
repl_transfer_tmpfile
);
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
repl
_
state
=
REDIS_REPL_CONNECT
;
}
}
/* Asynchronously read the SYNC payload we receive from a master */
/* Asynchronously read the SYNC payload we receive from a master */
...
@@ -356,7 +356,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -356,7 +356,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
server
.
master
=
createClient
(
server
.
repl_transfer_s
);
server
.
master
=
createClient
(
server
.
repl_transfer_s
);
server
.
master
->
flags
|=
REDIS_MASTER
;
server
.
master
->
flags
|=
REDIS_MASTER
;
server
.
master
->
authenticated
=
1
;
server
.
master
->
authenticated
=
1
;
server
.
replstate
=
REDIS_REPL_CONNECTED
;
server
.
repl
_
state
=
REDIS_REPL_CONNECTED
;
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: Finished with success"
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: Finished with success"
);
/* Restart the AOF subsystem now that we finished the sync. This
/* Restart the AOF subsystem now that we finished the sync. This
* will trigger an AOF rewrite, and when done will start appending
* will trigger an AOF rewrite, and when done will start appending
...
@@ -392,7 +392,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -392,7 +392,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
/* If this event fired after the user turned the instance into a master
/* If this event fired after the user turned the instance into a master
* with SLAVEOF NO ONE we must just return ASAP. */
* with SLAVEOF NO ONE we must just return ASAP. */
if
(
server
.
replstate
==
REDIS_REPL_NONE
)
{
if
(
server
.
repl
_
state
==
REDIS_REPL_NONE
)
{
close
(
fd
);
close
(
fd
);
return
;
return
;
}
}
...
@@ -454,7 +454,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -454,7 +454,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
goto
error
;
goto
error
;
}
}
server
.
replstate
=
REDIS_REPL_TRANSFER
;
server
.
repl
_
state
=
REDIS_REPL_TRANSFER
;
server
.
repl_transfer_left
=
-
1
;
server
.
repl_transfer_left
=
-
1
;
server
.
repl_transfer_fd
=
dfd
;
server
.
repl_transfer_fd
=
dfd
;
server
.
repl_transfer_lastio
=
time
(
NULL
);
server
.
repl_transfer_lastio
=
time
(
NULL
);
...
@@ -462,7 +462,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -462,7 +462,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
return
;
return
;
error:
error:
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
repl
_
state
=
REDIS_REPL_CONNECT
;
close
(
fd
);
close
(
fd
);
return
;
return
;
}
}
...
@@ -487,7 +487,7 @@ int connectWithMaster(void) {
...
@@ -487,7 +487,7 @@ int connectWithMaster(void) {
server
.
repl_transfer_lastio
=
time
(
NULL
);
server
.
repl_transfer_lastio
=
time
(
NULL
);
server
.
repl_transfer_s
=
fd
;
server
.
repl_transfer_s
=
fd
;
server
.
replstate
=
REDIS_REPL_CONNECTING
;
server
.
repl
_
state
=
REDIS_REPL_CONNECTING
;
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
@@ -496,11 +496,11 @@ int connectWithMaster(void) {
...
@@ -496,11 +496,11 @@ int connectWithMaster(void) {
void
undoConnectWithMaster
(
void
)
{
void
undoConnectWithMaster
(
void
)
{
int
fd
=
server
.
repl_transfer_s
;
int
fd
=
server
.
repl_transfer_s
;
redisAssert
(
server
.
replstate
==
REDIS_REPL_CONNECTING
);
redisAssert
(
server
.
repl
_
state
==
REDIS_REPL_CONNECTING
);
aeDeleteFileEvent
(
server
.
el
,
fd
,
AE_READABLE
|
AE_WRITABLE
);
aeDeleteFileEvent
(
server
.
el
,
fd
,
AE_READABLE
|
AE_WRITABLE
);
close
(
fd
);
close
(
fd
);
server
.
repl_transfer_s
=
-
1
;
server
.
repl_transfer_s
=
-
1
;
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
repl
_
state
=
REDIS_REPL_CONNECT
;
}
}
void
slaveofCommand
(
redisClient
*
c
)
{
void
slaveofCommand
(
redisClient
*
c
)
{
...
@@ -510,11 +510,11 @@ void slaveofCommand(redisClient *c) {
...
@@ -510,11 +510,11 @@ void slaveofCommand(redisClient *c) {
sdsfree
(
server
.
masterhost
);
sdsfree
(
server
.
masterhost
);
server
.
masterhost
=
NULL
;
server
.
masterhost
=
NULL
;
if
(
server
.
master
)
freeClient
(
server
.
master
);
if
(
server
.
master
)
freeClient
(
server
.
master
);
if
(
server
.
replstate
==
REDIS_REPL_TRANSFER
)
if
(
server
.
repl
_
state
==
REDIS_REPL_TRANSFER
)
replicationAbortSyncTransfer
();
replicationAbortSyncTransfer
();
else
if
(
server
.
replstate
==
REDIS_REPL_CONNECTING
)
else
if
(
server
.
repl
_
state
==
REDIS_REPL_CONNECTING
)
undoConnectWithMaster
();
undoConnectWithMaster
();
server
.
replstate
=
REDIS_REPL_NONE
;
server
.
repl
_
state
=
REDIS_REPL_NONE
;
redisLog
(
REDIS_NOTICE
,
"MASTER MODE enabled (user request)"
);
redisLog
(
REDIS_NOTICE
,
"MASTER MODE enabled (user request)"
);
}
}
}
else
{
}
else
{
...
@@ -522,9 +522,9 @@ void slaveofCommand(redisClient *c) {
...
@@ -522,9 +522,9 @@ void slaveofCommand(redisClient *c) {
server
.
masterhost
=
sdsdup
(
c
->
argv
[
1
]
->
ptr
);
server
.
masterhost
=
sdsdup
(
c
->
argv
[
1
]
->
ptr
);
server
.
masterport
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
server
.
masterport
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
if
(
server
.
master
)
freeClient
(
server
.
master
);
if
(
server
.
master
)
freeClient
(
server
.
master
);
if
(
server
.
replstate
==
REDIS_REPL_TRANSFER
)
if
(
server
.
repl
_
state
==
REDIS_REPL_TRANSFER
)
replicationAbortSyncTransfer
();
replicationAbortSyncTransfer
();
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
repl
_
state
=
REDIS_REPL_CONNECT
;
redisLog
(
REDIS_NOTICE
,
"SLAVE OF %s:%d enabled (user request)"
,
redisLog
(
REDIS_NOTICE
,
"SLAVE OF %s:%d enabled (user request)"
,
server
.
masterhost
,
server
.
masterport
);
server
.
masterhost
,
server
.
masterport
);
}
}
...
@@ -535,7 +535,7 @@ void slaveofCommand(redisClient *c) {
...
@@ -535,7 +535,7 @@ void slaveofCommand(redisClient *c) {
void
replicationCron
(
void
)
{
void
replicationCron
(
void
)
{
/* Non blocking connection timeout? */
/* Non blocking connection timeout? */
if
(
server
.
masterhost
&&
server
.
replstate
==
REDIS_REPL_CONNECTING
&&
if
(
server
.
masterhost
&&
server
.
repl
_
state
==
REDIS_REPL_CONNECTING
&&
(
time
(
NULL
)
-
server
.
repl_transfer_lastio
)
>
server
.
repl_timeout
)
(
time
(
NULL
)
-
server
.
repl_transfer_lastio
)
>
server
.
repl_timeout
)
{
{
redisLog
(
REDIS_WARNING
,
"Timeout connecting to the MASTER..."
);
redisLog
(
REDIS_WARNING
,
"Timeout connecting to the MASTER..."
);
...
@@ -543,7 +543,7 @@ void replicationCron(void) {
...
@@ -543,7 +543,7 @@ void replicationCron(void) {
}
}
/* Bulk transfer I/O timeout? */
/* Bulk transfer I/O timeout? */
if
(
server
.
masterhost
&&
server
.
replstate
==
REDIS_REPL_TRANSFER
&&
if
(
server
.
masterhost
&&
server
.
repl
_
state
==
REDIS_REPL_TRANSFER
&&
(
time
(
NULL
)
-
server
.
repl_transfer_lastio
)
>
server
.
repl_timeout
)
(
time
(
NULL
)
-
server
.
repl_transfer_lastio
)
>
server
.
repl_timeout
)
{
{
redisLog
(
REDIS_WARNING
,
"Timeout receiving bulk data from MASTER..."
);
redisLog
(
REDIS_WARNING
,
"Timeout receiving bulk data from MASTER..."
);
...
@@ -551,7 +551,7 @@ void replicationCron(void) {
...
@@ -551,7 +551,7 @@ void replicationCron(void) {
}
}
/* Timed out master when we are an already connected slave? */
/* Timed out master when we are an already connected slave? */
if
(
server
.
masterhost
&&
server
.
replstate
==
REDIS_REPL_CONNECTED
&&
if
(
server
.
masterhost
&&
server
.
repl
_
state
==
REDIS_REPL_CONNECTED
&&
(
time
(
NULL
)
-
server
.
master
->
lastinteraction
)
>
server
.
repl_timeout
)
(
time
(
NULL
)
-
server
.
master
->
lastinteraction
)
>
server
.
repl_timeout
)
{
{
redisLog
(
REDIS_WARNING
,
"MASTER time out: no data nor PING received..."
);
redisLog
(
REDIS_WARNING
,
"MASTER time out: no data nor PING received..."
);
...
@@ -559,7 +559,7 @@ void replicationCron(void) {
...
@@ -559,7 +559,7 @@ void replicationCron(void) {
}
}
/* Check if we should connect to a MASTER */
/* Check if we should connect to a MASTER */
if
(
server
.
replstate
==
REDIS_REPL_CONNECT
)
{
if
(
server
.
repl
_
state
==
REDIS_REPL_CONNECT
)
{
redisLog
(
REDIS_NOTICE
,
"Connecting to MASTER..."
);
redisLog
(
REDIS_NOTICE
,
"Connecting to MASTER..."
);
if
(
connectWithMaster
()
==
REDIS_OK
)
{
if
(
connectWithMaster
()
==
REDIS_OK
)
{
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync started"
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync started"
);
...
...
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