| 1542 | /* Asynchronously read the SYNC payload we receive from a master */ |
| 1543 | #define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */ |
| 1544 | void readSyncBulkPayload(connection *conn) { |
| 1545 | char buf[PROTO_IOBUF_LEN]; |
| 1546 | ssize_t nread, readlen, nwritten; |
| 1547 | int use_diskless_load = useDisklessLoad(); |
| 1548 | dbBackup *diskless_load_backup = NULL; |
| 1549 | int empty_db_flags = server.repl_slave_lazy_flush ? EMPTYDB_ASYNC : |
| 1550 | EMPTYDB_NO_FLAGS; |
| 1551 | off_t left; |
| 1552 | |
| 1553 | /* Static vars used to hold the EOF mark, and the last bytes received |
| 1554 | * from the server: when they match, we reached the end of the transfer. */ |
| 1555 | static char eofmark[CONFIG_RUN_ID_SIZE]; |
| 1556 | static char lastbytes[CONFIG_RUN_ID_SIZE]; |
| 1557 | static int usemark = 0; |
| 1558 | |
| 1559 | /* If repl_transfer_size == -1 we still have to read the bulk length |
| 1560 | * from the master reply. */ |
| 1561 | if (server.repl_transfer_size == -1) { |
| 1562 | if (connSyncReadLine(conn,buf,1024,server.repl_syncio_timeout*1000) == -1) { |
| 1563 | serverLog(LL_WARNING, |
| 1564 | "I/O error reading bulk count from MASTER: %s", |
| 1565 | strerror(errno)); |
| 1566 | goto error; |
| 1567 | } |
| 1568 | |
| 1569 | if (buf[0] == '-') { |
| 1570 | serverLog(LL_WARNING, |
| 1571 | "MASTER aborted replication with an error: %s", |
| 1572 | buf+1); |
| 1573 | goto error; |
| 1574 | } else if (buf[0] == '\0') { |
| 1575 | /* At this stage just a newline works as a PING in order to take |
| 1576 | * the connection live. So we refresh our last interaction |
| 1577 | * timestamp. */ |
| 1578 | server.repl_transfer_lastio = server.unixtime; |
| 1579 | return; |
| 1580 | } else if (buf[0] != '$') { |
| 1581 | serverLog(LL_WARNING,"Bad protocol from MASTER, the first byte is not '$' (we received '%s'), are you sure the host and port are right?", buf); |
| 1582 | goto error; |
| 1583 | } |
| 1584 | |
| 1585 | /* There are two possible forms for the bulk payload. One is the |
| 1586 | * usual $<count> bulk format. The other is used for diskless transfers |
| 1587 | * when the master does not know beforehand the size of the file to |
| 1588 | * transfer. In the latter case, the following format is used: |
| 1589 | * |
| 1590 | * $EOF:<40 bytes delimiter> |
| 1591 | * |
| 1592 | * At the end of the file the announced delimiter is transmitted. The |
| 1593 | * delimiter is long and random enough that the probability of a |
| 1594 | * collision with the actual file content can be ignored. */ |
| 1595 | if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= CONFIG_RUN_ID_SIZE) { |
| 1596 | usemark = 1; |
| 1597 | memcpy(eofmark,buf+5,CONFIG_RUN_ID_SIZE); |
| 1598 | memset(lastbytes,0,CONFIG_RUN_ID_SIZE); |
| 1599 | /* Set any repl_transfer_size to avoid entering this code path |
| 1600 | * at the next call. */ |
| 1601 | server.repl_transfer_size = 0; |
nothing calls this directly
no test coverage detected