提交 874c21d8 编写于 作者: J jonathan pickett

issue 166: master/slave sync with RDB > 2G. cause: off_t defined as long....

issue 166: master/slave sync with RDB > 2G.  cause: off_t defined as long. longs are 4-bytes on x64 Windows. Redefined impacted vars as int64_t.
上级 763d7b7c
...@@ -770,9 +770,15 @@ struct redisServer { ...@@ -770,9 +770,15 @@ struct redisServer {
redisClient *cached_master; /* Cached master to be reused for PSYNC. */ redisClient *cached_master; /* Cached master to be reused for PSYNC. */
int repl_syncio_timeout; /* Timeout for synchronous I/O calls */ int repl_syncio_timeout; /* Timeout for synchronous I/O calls */
int repl_state; /* Replication status if the instance is a slave */ int repl_state; /* Replication status if the instance is a slave */
#ifdef _WIN64
int64_t repl_transfer_size; /* Size of RDB to read from master during sync. */
int64_t repl_transfer_read; /* Amount of RDB read from master during sync. */
int64_t repl_transfer_last_fsync_off; /* Offset when we fsync-ed last time. */
#else
off_t repl_transfer_size; /* Size of RDB to read from master during sync. */ off_t repl_transfer_size; /* Size of RDB to read from master during sync. */
off_t repl_transfer_read; /* Amount of RDB read from master during sync. */ off_t repl_transfer_read; /* Amount of RDB read from master during sync. */
off_t repl_transfer_last_fsync_off; /* Offset when we fsync-ed last time. */ off_t repl_transfer_last_fsync_off; /* Offset when we fsync-ed last time. */
#endif
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 */
......
...@@ -847,8 +847,13 @@ void replicationEmptyDbCallback(void *privdata) { ...@@ -847,8 +847,13 @@ void replicationEmptyDbCallback(void *privdata) {
#define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */ #define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */
void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
char buf[4096]; char buf[4096];
#ifdef _WIN64
int64_t nread, readlen;
int64_t left;
#else
ssize_t nread, readlen; ssize_t nread, readlen;
off_t left; off_t left;
#endif
REDIS_NOTUSED(el); REDIS_NOTUSED(el);
REDIS_NOTUSED(privdata); REDIS_NOTUSED(privdata);
REDIS_NOTUSED(mask); REDIS_NOTUSED(mask);
...@@ -881,7 +886,11 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { ...@@ -881,7 +886,11 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
redisLog(REDIS_WARNING,"Bad protocol from MASTER, the first byte is not '$' (we received '%s'), are you sure the host and port are right?", buf); redisLog(REDIS_WARNING,"Bad protocol from MASTER, the first byte is not '$' (we received '%s'), are you sure the host and port are right?", buf);
goto error; goto error;
} }
#ifdef _WIN64
server.repl_transfer_size = strtoll(buf+1,NULL,10);
#else
server.repl_transfer_size = strtol(buf+1,NULL,10); server.repl_transfer_size = strtol(buf+1,NULL,10);
#endif
redisLog(REDIS_NOTICE, redisLog(REDIS_NOTICE,
"MASTER <-> SLAVE sync: receiving %lld bytes from master", "MASTER <-> SLAVE sync: receiving %lld bytes from master",
(long long) server.repl_transfer_size); (long long) server.repl_transfer_size);
...@@ -896,10 +905,17 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { ...@@ -896,10 +905,17 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
if (nread <= 0) { if (nread <= 0) {
if (server.repl_transfer_size) { if (server.repl_transfer_size) {
errno = WSAGetLastError(); errno = WSAGetLastError();
#ifdef _WIN64
redisLog(REDIS_WARNING,"I/O error %d (left %lld) trying to sync with MASTER: %s",
errno, server.repl_transfer_size,
(nread == -1) ? wsa_strerror(errno) : "connection lost");
}
#else
redisLog(REDIS_WARNING,"I/O error %d (left %d) trying to sync with MASTER: %s", redisLog(REDIS_WARNING,"I/O error %d (left %d) trying to sync with MASTER: %s",
errno, server.repl_transfer_size, errno, server.repl_transfer_size,
(nread == -1) ? wsa_strerror(errno) : "connection lost"); (nread == -1) ? wsa_strerror(errno) : "connection lost");
} }
#endif
replicationAbortSyncTransfer(); replicationAbortSyncTransfer();
return; return;
} }
...@@ -926,8 +942,13 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { ...@@ -926,8 +942,13 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
if (server.repl_transfer_read >= if (server.repl_transfer_read >=
server.repl_transfer_last_fsync_off + REPL_MAX_WRITTEN_BEFORE_FSYNC) server.repl_transfer_last_fsync_off + REPL_MAX_WRITTEN_BEFORE_FSYNC)
{ {
#ifdef _WIN64
int64_t sync_size = server.repl_transfer_read -
server.repl_transfer_last_fsync_off;
#else
off_t sync_size = server.repl_transfer_read - off_t sync_size = server.repl_transfer_read -
server.repl_transfer_last_fsync_off; server.repl_transfer_last_fsync_off;
#endif
rdb_fsync_range(server.repl_transfer_fd, rdb_fsync_range(server.repl_transfer_fd,
server.repl_transfer_last_fsync_off, sync_size); server.repl_transfer_last_fsync_off, sync_size);
server.repl_transfer_last_fsync_off += sync_size; server.repl_transfer_last_fsync_off += sync_size;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册