Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #362 from canonical/revert-351-null-address
Browse files Browse the repository at this point in the history
Revert "replication: Drop append entries result if a state transition has occurred"
  • Loading branch information
cole-miller authored Jan 10, 2023
2 parents 7a4a65a + 1819829 commit 6cdfe67
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,24 +849,23 @@ static void appendFollowerCb(struct raft_io_append *req, int status)
assert(args->entries != NULL);
assert(args->n_entries > 0);

/* If we're shutting down or have errored, ignore the result. */
if (r->state == RAFT_UNAVAILABLE) {
tracef("local server is unavailable -> ignore I/O result");
goto out;
}
/* If a new term has started since the request came in, ignore the result. */
if (args->term != r->current_term) {
tracef("new term while processing request -> ignore I/O result");
goto out;
}

result.term = r->current_term;
result.version = RAFT_APPEND_ENTRIES_RESULT_VERSION;
result.term = args->term;
if (status != 0) {
if (r->state != RAFT_FOLLOWER) {
tracef("local server is not follower -> ignore I/O failure");
goto out;
}
result.rejected = args->prev_log_index + 1;
goto respond;
}

/* If we're shutting down or have errored, ignore the result. */
if (r->state == RAFT_UNAVAILABLE) {
tracef("local server is unavailable -> ignore I/O result");
goto out;
}

/* We received an InstallSnapshot RCP while these entries were being
* persisted to disk */
if (replicationInstallSnapshotBusy(r)) {
Expand Down Expand Up @@ -1196,7 +1195,6 @@ struct recvInstallSnapshot
{
struct raft *raft;
struct raft_snapshot snapshot;
raft_term term; /* Used to check for state transitions. */
};

static void installSnapshotCb(struct raft_io_snapshot_put *req, int status)
Expand All @@ -1215,13 +1213,11 @@ static void installSnapshotCb(struct raft_io_snapshot_put *req, int status)
result.term = r->current_term;
result.version = RAFT_APPEND_ENTRIES_RESULT_VERSION;

/* If we are shutting down, let's discard the result. */
/* If we are shutting down, let's discard the result. TODO: what about other
* states? */
if (r->state == RAFT_UNAVAILABLE) {
tracef("shutting down -> discard result of snapshot installation");
goto discard;
}
/* We don't transition to candidate state while a snapshot is being installed. */
assert(request->term == r->current_term);

if (status != 0) {
result.rejected = snapshot->index;
Expand Down Expand Up @@ -1317,7 +1313,6 @@ int replicationInstallSnapshot(struct raft *r,
goto err;
}
request->raft = r;
request->term = r->current_term;

snapshot = &request->snapshot;
snapshot->term = args->last_term;
Expand Down

0 comments on commit 6cdfe67

Please sign in to comment.