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
62ec599c
Commit
62ec599c
authored
Nov 04, 2010
by
antirez
Browse files
typos and minor stuff fixed in the new non blocking replication code
parent
f4aa600b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/redis.c
View file @
62ec599c
...
@@ -635,7 +635,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
...
@@ -635,7 +635,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* Replication cron function -- used to reconnect to master and
/* Replication cron function -- used to reconnect to master and
* to detect transfer failures. */
* to detect transfer failures. */
if
(
!
(
loops
%
10
))
replicationCron
(
void
);
if
(
!
(
loops
%
10
))
replicationCron
();
return
100
;
return
100
;
}
}
...
...
src/redis.h
View file @
62ec599c
...
@@ -152,7 +152,7 @@
...
@@ -152,7 +152,7 @@
/* 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_TRANFER 2
/* Receiving .rdb from master */
#define REDIS_REPL_TRAN
S
FER 2
/* Receiving .rdb from master */
#define REDIS_REPL_CONNECTED 3
/* Connected to master */
#define REDIS_REPL_CONNECTED 3
/* Connected to master */
/* Slave replication state - from the point of view of master
/* Slave replication state - from the point of view of master
...
@@ -408,7 +408,7 @@ struct redisServer {
...
@@ -408,7 +408,7 @@ struct redisServer {
int
masterport
;
int
masterport
;
redisClient
*
master
;
/* client that is master for this slave */
redisClient
*
master
;
/* client that is master for this slave */
int
replstate
;
/* replication status if the instance is a slave */
int
replstate
;
/* replication status if the instance is a slave */
off_t
repl_transfer_left
;
/* bytes left reading .rdb
if this is a slave
*/
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 */
char
*
repl_transfer_tmpfile
;
/* slave-> master SYNC temp file name */
char
*
repl_transfer_tmpfile
;
/* slave-> master SYNC temp file name */
...
...
src/replication.c
View file @
62ec599c
...
@@ -306,11 +306,14 @@ void replicationAbortSyncTransfer(void) {
...
@@ -306,11 +306,14 @@ void replicationAbortSyncTransfer(void) {
/* Asynchronously read the SYNC payload we receive from a master */
/* Asynchronously read the SYNC payload we receive from a master */
void
readSyncBulkPayload
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
void
readSyncBulkPayload
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
unsigned
char
buf
[
4096
]
unsigned
char
buf
[
4096
];
size_t
nread
,
readlen
;
ssize_t
nread
,
readlen
;
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
privdata
);
REDIS_NOTUSED
(
mask
);
readlen
=
(
server
.
repl_transfer_left
<
sizeof
(
buf
))
?
readlen
=
(
server
.
repl_transfer_left
<
(
signed
)
sizeof
(
buf
))
?
server
.
repl_transfer_left
:
sizeof
(
buf
);
server
.
repl_transfer_left
:
(
signed
)
sizeof
(
buf
);
nread
=
read
(
fd
,
buf
,
readlen
);
nread
=
read
(
fd
,
buf
,
readlen
);
if
(
nread
<=
0
)
{
if
(
nread
<=
0
)
{
redisLog
(
REDIS_WARNING
,
"I/O error trying to sync with MASTER: %s"
,
redisLog
(
REDIS_WARNING
,
"I/O error trying to sync with MASTER: %s"
,
...
@@ -425,8 +428,8 @@ int syncWithMaster(void) {
...
@@ -425,8 +428,8 @@ int syncWithMaster(void) {
}
}
/* Setup the non blocking download of the bulk file. */
/* Setup the non blocking download of the bulk file. */
if
(
aeCreateFileEvent
(
server
.
el
,
fd
,
AE_READABLE
,
readSyncBulkPayload
)
==
if
(
aeCreateFileEvent
(
server
.
el
,
fd
,
AE_READABLE
,
readSyncBulkPayload
,
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"
);
...
@@ -481,7 +484,7 @@ void replicationCron(void) {
...
@@ -481,7 +484,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
&&
!
(
loops
%
10
)
)
{
if
(
server
.
replstate
==
REDIS_REPL_CONNECT
)
{
redisLog
(
REDIS_NOTICE
,
"Connecting to MASTER..."
);
redisLog
(
REDIS_NOTICE
,
"Connecting to MASTER..."
);
if
(
syncWithMaster
()
==
REDIS_OK
)
{
if
(
syncWithMaster
()
==
REDIS_OK
)
{
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync succeeded"
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync succeeded"
);
...
...
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