Skip to content

Commit

Permalink
v1: Move r->io->start() call late in raft_start()
Browse files Browse the repository at this point in the history
This will allow to move the core logic of raft_start() to raft_step(), when
handling RAFT_START events.

Signed-off-by: Free Ekanayaka <free@ekanayaka.io>
  • Loading branch information
freeekanayaka committed Dec 22, 2023
1 parent adb349e commit fa6872d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,6 @@ int raft_start(struct raft *r)
return rv;
}

/* Start the I/O backend. The tickCb function is expected to fire every
* r->heartbeat_timeout milliseconds and recvCb whenever an RPC is
* received. */
rv = r->io->start(r->io, r->heartbeat_timeout, tickCb, recvCb);
if (rv != 0) {
tracef("io start failed %d", rv);
return rv;
}

/* By default we start as followers. */
convertToFollower(r);

Expand All @@ -278,6 +269,15 @@ int raft_start(struct raft *r)
event.time = r->now;
LegacyForwardToRaftIo(r, &event);

/* Start the I/O backend. The tickCb function is expected to fire every
* r->heartbeat_timeout milliseconds and recvCb whenever an RPC is
* received. */
rv = r->io->start(r->io, r->heartbeat_timeout, tickCb, recvCb);
if (rv != 0) {
tracef("io start failed %d", rv);
return rv;
}

return 0;
}

Expand Down

0 comments on commit fa6872d

Please sign in to comment.