Fix diskless load handling on broken EOF marker (#9752)

During diskless replication, the check for broken EOF mark is misplaced
and should be earlier. Now we do not swap db, we do proper cleanup and
correctly raise module events on this kind of failure.

This issue existed prior to #9323, but before, the side effect was not restoring
backup and not raising the correct module events on this failure.
This commit is contained in:
Eduardo Semprebon 2021-11-09 10:46:10 +01:00 committed by GitHub
parent 2ce29e032b
commit c22d3684ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1963,11 +1963,24 @@ void readSyncBulkPayload(connection *conn) {
connRecvTimeout(conn, server.repl_timeout*1000);
startLoading(server.repl_transfer_size, RDBFLAGS_REPLICATION, asyncLoading);
int loadingFailed = 0;
if (rdbLoadRio(&rdb,RDBFLAGS_REPLICATION,&rsi,dbarray) != C_OK) {
/* RDB loading failed. */
serverLog(LL_WARNING,
"Failed trying to load the MASTER synchronization DB "
"from socket: %s", strerror(errno));
loadingFailed = 1;
} else if (usemark) {
/* Verify the end mark is correct. */
if (!rioRead(&rdb, buf, CONFIG_RUN_ID_SIZE) ||
memcmp(buf, eofmark, CONFIG_RUN_ID_SIZE) != 0)
{
serverLog(LL_WARNING, "Replication stream EOF marker is broken");
loadingFailed = 1;
}
}
if (loadingFailed) {
stopLoading(0);
cancelReplicationHandshake(1);
rioFreeConn(&rdb, NULL);
@ -2013,19 +2026,6 @@ void readSyncBulkPayload(connection *conn) {
/* Inform about db change, as replication was diskless and didn't cause a save. */
server.dirty++;
/* Verify the end mark is correct. */
if (usemark) {
if (!rioRead(&rdb,buf,CONFIG_RUN_ID_SIZE) ||
memcmp(buf,eofmark,CONFIG_RUN_ID_SIZE) != 0)
{
stopLoading(0);
serverLog(LL_WARNING,"Replication stream EOF marker is broken");
cancelReplicationHandshake(1);
rioFreeConn(&rdb, NULL);
return;
}
}
stopLoading(1);
/* Cleanup and restore the socket to the original state to continue