Skip to content

Commit

Permalink
replication: Always trigger replication in replicationProgress()
Browse files Browse the repository at this point in the history
Some call sites require to skip the progressShouldReplicate() check and force
triggering replication. For example when probing a server fails because of
missing entries, the leader should retry immediately without waiting the
heartbeat timeout.

Signed-off-by: Free Ekanayaka <free@ekanayaka.io>
  • Loading branch information
freeekanayaka committed Dec 27, 2023
1 parent aacf671 commit a2fa4e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ int replicationProgress(struct raft *r, unsigned i)
assert(server->id != r->id);
assert(next_index >= 1);

if (!progressShouldReplicate(r, i)) {
return 0;
}

/* From Section 3.5:
*
* When sending an AppendEntries RPC, the leader includes the index and
Expand Down Expand Up @@ -321,6 +317,9 @@ static int triggerAll(struct raft *r)
server->id != r->leader_state.promotee_id) {
continue;
}
if (!progressShouldReplicate(r, i)) {
continue;
}
rv = replicationProgress(r, i);
if (rv != 0 && rv != RAFT_NOCONNECTION) {
/* This is not a critical failure, let's just log it. */
Expand Down Expand Up @@ -628,8 +627,10 @@ int replicationUpdate(struct raft *r,
}
}

/* If this follower is in pipeline mode, send it more entries. */
if (progressState(r, i) == PROGRESS__PIPELINE) {
/* If this follower is in pipeline mode, send it more entries if
* needed. */
if (progressState(r, i) == PROGRESS__PIPELINE &&
progressShouldReplicate(r, i)) {
replicationProgress(r, i);
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ TEST(snapshot,
(void)params;

/* Set very low threshold and trailing entries number */
SET_SNAPSHOT_THRESHOLD(3);
SET_SNAPSHOT_THRESHOLD(4);
SET_SNAPSHOT_TRAILING(1);
SET_SNAPSHOT_TIMEOUT(200);

Expand Down

0 comments on commit a2fa4e0

Please sign in to comment.