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 #257 from MathieuBordere/check-0-entries
Browse files Browse the repository at this point in the history
replication: Ensure there are entries to append
  • Loading branch information
stgraber authored Dec 14, 2021
2 parents c058abb + 00f0597 commit 456fd20
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,13 @@ static int appendLeader(struct raft *r, raft_index index)

/* We expect this function to be called only when there are actually
* some entries to write. */
assert(n > 0);
if (n == 0) {
assert(false);
tracef("No log entries found at index %llu", index);
ErrMsgPrintf(r->errmsg, "No log entries found at index %llu", index);
rv = RAFT_SHUTDOWN;
goto err_after_entries_acquired;
}

/* Allocate a new request. */
request = raft_malloc(sizeof *request);
Expand Down Expand Up @@ -1133,6 +1139,12 @@ int replicationAppend(struct raft *r,
}

assert(request->args.n_entries == n);
if (request->args.n_entries == 0) {
tracef("No log entries found at index %llu", request->index);
ErrMsgPrintf(r->errmsg, "No log entries found at index %llu", request->index);
rv = RAFT_SHUTDOWN;
goto err_after_acquire_entries;
}

request->req.data = request;
rv = r->io->append(r->io, &request->req, request->args.entries,
Expand Down

0 comments on commit 456fd20

Please sign in to comment.