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
b075621f
Commit
b075621f
authored
May 22, 2011
by
Pieter Noordhuis
Browse files
Minor changes in non-blocking repl. connect
parent
a3309139
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/redis.h
View file @
b075621f
...
@@ -155,9 +155,9 @@
...
@@ -155,9 +155,9 @@
/* Slave replication state - slave side */
/* Slave replication state - slave side */
#define REDIS_REPL_NONE 0
/* No active replication */
#define REDIS_REPL_NONE 0
/* No active replication */
#define REDIS_REPL_CONNECT 1
/* Must connect to master */
#define REDIS_REPL_CONNECT 1
/* Must connect to master */
#define REDIS_REPL_
TRANSFER 2
/* Receiving .rdb from
master */
#define REDIS_REPL_
CONNECTING 2
/* Connecting to
master */
#define REDIS_REPL_
CONNECTED 3
/* Connected to
master */
#define REDIS_REPL_
TRANSFER 3
/* Receiving .rdb from
master */
#define REDIS_REPL_CONNECT
ING
4
/* Connect
ing
to master */
#define REDIS_REPL_CONNECT
ED
4
/* Connect
ed
to master */
/* Slave replication state - from the point of view of master
/* Slave replication state - from the point of view of master
* Note that in SEND_BULK and ONLINE state the slave receives new updates
* Note that in SEND_BULK and ONLINE state the slave receives new updates
...
...
src/replication.c
View file @
b075621f
...
@@ -319,15 +319,14 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -319,15 +319,14 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
redisLog
(
REDIS_WARNING
,
redisLog
(
REDIS_WARNING
,
"I/O error reading bulk count from MASTER: %s"
,
"I/O error reading bulk count from MASTER: %s"
,
strerror
(
errno
));
strerror
(
errno
));
replicationAbortSyncTransfer
();
goto
error
;
return
;
}
}
if
(
buf
[
0
]
==
'-'
)
{
if
(
buf
[
0
]
==
'-'
)
{
redisLog
(
REDIS_WARNING
,
redisLog
(
REDIS_WARNING
,
"MASTER aborted replication with an error: %s"
,
"MASTER aborted replication with an error: %s"
,
buf
+
1
);
buf
+
1
);
replicationAbortSyncTransfer
();
goto
error
;
return
;
}
else
if
(
buf
[
0
]
==
'\0'
)
{
}
else
if
(
buf
[
0
]
==
'\0'
)
{
/* At this stage just a newline works as a PING in order to take
/* At this stage just a newline works as a PING in order to take
* the connection live. So we refresh our last interaction
* the connection live. So we refresh our last interaction
...
@@ -336,8 +335,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -336,8 +335,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
return
;
return
;
}
else
if
(
buf
[
0
]
!=
'$'
)
{
}
else
if
(
buf
[
0
]
!=
'$'
)
{
redisLog
(
REDIS_WARNING
,
"Bad protocol from MASTER, the first byte is not '$', are you sure the host and port are right?"
);
redisLog
(
REDIS_WARNING
,
"Bad protocol from MASTER, the first byte is not '$', are you sure the host and port are right?"
);
replicationAbortSyncTransfer
();
goto
error
;
return
;
}
}
server
.
repl_transfer_left
=
strtol
(
buf
+
1
,
NULL
,
10
);
server
.
repl_transfer_left
=
strtol
(
buf
+
1
,
NULL
,
10
);
redisLog
(
REDIS_NOTICE
,
redisLog
(
REDIS_NOTICE
,
...
@@ -359,8 +357,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -359,8 +357,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
server
.
repl_transfer_lastio
=
time
(
NULL
);
server
.
repl_transfer_lastio
=
time
(
NULL
);
if
(
write
(
server
.
repl_transfer_fd
,
buf
,
nread
)
!=
nread
)
{
if
(
write
(
server
.
repl_transfer_fd
,
buf
,
nread
)
!=
nread
)
{
redisLog
(
REDIS_WARNING
,
"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchrnonization: %s"
,
strerror
(
errno
));
redisLog
(
REDIS_WARNING
,
"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchrnonization: %s"
,
strerror
(
errno
));
replicationAbortSyncTransfer
();
goto
error
;
return
;
}
}
server
.
repl_transfer_left
-=
nread
;
server
.
repl_transfer_left
-=
nread
;
/* Check if the transfer is now complete */
/* Check if the transfer is now complete */
...
@@ -391,6 +388,12 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -391,6 +388,12 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
server
.
replstate
=
REDIS_REPL_CONNECTED
;
server
.
replstate
=
REDIS_REPL_CONNECTED
;
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: Finished with success"
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: Finished with success"
);
}
}
return
;
error:
replicationAbortSyncTransfer
();
return
;
}
}
void
syncWithMaster
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
void
syncWithMaster
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
...
@@ -400,8 +403,10 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -400,8 +403,10 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
REDIS_NOTUSED
(
privdata
);
REDIS_NOTUSED
(
privdata
);
REDIS_NOTUSED
(
mask
);
REDIS_NOTUSED
(
mask
);
/* Remove this event before anything else. */
/* This event should only be triggered once since it is used to have a
aeDeleteFileEvent
(
server
.
el
,
fd
,
AE_READABLE
|
AE_WRITABLE
);
* non-blocking connect(2) to the master. It has been triggered when this
* function is called, so we can delete it. */
aeDeleteFileEvent
(
server
.
el
,
fd
,
AE_WRITABLE
);
/* AUTH with the master if required. */
/* AUTH with the master if required. */
if
(
server
.
masterauth
)
{
if
(
server
.
masterauth
)
{
...
@@ -477,8 +482,8 @@ int connectWithMaster(void) {
...
@@ -477,8 +482,8 @@ int connectWithMaster(void) {
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
if
(
aeCreateFileEvent
(
server
.
el
,
fd
,
AE_
READABLE
|
AE_WRITABLE
,
if
(
aeCreateFileEvent
(
server
.
el
,
fd
,
AE_
WRITABLE
,
syncWithMaster
,
NULL
)
==
syncWithMaster
,
NULL
)
==
AE_ERR
)
AE_ERR
)
{
{
close
(
fd
);
close
(
fd
);
redisLog
(
REDIS_WARNING
,
"Can't create readable event for SYNC"
);
redisLog
(
REDIS_WARNING
,
"Can't create readable event for SYNC"
);
...
...
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