Skip to content

Commit

Permalink
Use goto to cleanup error handling in readSyncBulkPayload
Browse files Browse the repository at this point in the history
The goto error label is the same as the error return, use goto
to reduce the references.
```
error:
    cancelReplicationHandshake(1);
    return;
```

Also this can make the log printing more continuous under the
error, that is, we print the error log first, and then print
the reconnecting log at the last (in cancelReplicationHandshake).

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Nov 21, 2024
1 parent 4986310 commit f3ffeaa
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,7 @@ void readSyncBulkPayload(connection *conn) {
}
serverLog(LL_WARNING, "I/O error trying to sync with PRIMARY: %s",
(nread == -1) ? connGetLastError(conn) : "connection lost");
cancelReplicationHandshake(1);
return;
goto error;
}
server.stat_net_repl_input_bytes += nread;

Expand Down Expand Up @@ -2257,7 +2256,6 @@ void readSyncBulkPayload(connection *conn) {

if (loadingFailed) {
stopLoading(0);
cancelReplicationHandshake(1);
rioFreeConn(&rdb, NULL);

if (server.repl_diskless_load == REPL_DISKLESS_LOAD_SWAPDB) {
Expand All @@ -2277,7 +2275,7 @@ void readSyncBulkPayload(connection *conn) {
/* Note that there's no point in restarting the AOF on SYNC
* failure, it'll be restarted when sync succeeds or the replica
* gets promoted. */
return;
goto error;
}

/* RDB loading succeeded if we reach this point. */
Expand Down Expand Up @@ -2319,8 +2317,7 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to sync the temp DB to disk in "
"PRIMARY <-> REPLICA synchronization: %s",
strerror(errno));
cancelReplicationHandshake(1);
return;
goto error;
}

/* Rename rdb like renaming rewrite aof asynchronously. */
Expand All @@ -2330,9 +2327,8 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to rename the temp DB into %s in "
"PRIMARY <-> REPLICA synchronization: %s",
server.rdb_filename, strerror(errno));
cancelReplicationHandshake(1);
if (old_rdb_fd != -1) close(old_rdb_fd);
return;
goto error;
}
/* Close old rdb asynchronously. */
if (old_rdb_fd != -1) bioCreateCloseJob(old_rdb_fd, 0, 0);
Expand All @@ -2343,8 +2339,7 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to sync DB directory %s in "
"PRIMARY <-> REPLICA synchronization: %s",
server.rdb_filename, strerror(errno));
cancelReplicationHandshake(1);
return;
goto error;
}

/* We will soon start loading the RDB from disk, the replication history is changed,
Expand All @@ -2361,7 +2356,6 @@ void readSyncBulkPayload(connection *conn) {
if (rdbLoad(server.rdb_filename, &rsi, RDBFLAGS_REPLICATION) != RDB_OK) {
serverLog(LL_WARNING, "Failed trying to load the PRIMARY synchronization "
"DB from disk, check server logs.");
cancelReplicationHandshake(1);
if (server.rdb_del_sync_files && allPersistenceDisabled()) {
serverLog(LL_NOTICE, "Removing the RDB file obtained from "
"the primary. This replica has persistence "
Expand All @@ -2375,7 +2369,7 @@ void readSyncBulkPayload(connection *conn) {

/* Note that there's no point in restarting the AOF on sync failure,
it'll be restarted when sync succeeds or replica promoted. */
return;
goto error;
}

/* Cleanup. */
Expand Down

0 comments on commit f3ffeaa

Please sign in to comment.