Skip to content

Commit

Permalink
legacy: Miscellaneous code cleanups (#118)
Browse files Browse the repository at this point in the history
Clean up a bit the legacy compatibility code in `src/legacy.c`, which
had accumulated some cruft due to the v1 API changes from `struct
raft_task` to `struct raft_update`.
  • Loading branch information
freeekanayaka authored Dec 28, 2023
2 parents a03b994 + f87bedd commit 72b4804
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 184 deletions.
26 changes: 2 additions & 24 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "assert.h"
#include "byte.h"
#include "tracing.h"

/* Current encoding format version. */
#define ENCODING_FORMAT 1
Expand Down Expand Up @@ -118,9 +117,9 @@ int configurationCopy(const struct raft_configuration *src,
}

int configurationAdd(struct raft_configuration *c,
raft_id id,
const raft_id id,
const char *address,
int role)
const int role)
{
struct raft_server *servers;
struct raft_server *server;
Expand Down Expand Up @@ -379,24 +378,3 @@ int configurationDecode(const struct raft_buffer *buf,
configurationClose(c);
return rv;
}

#define tracef(...) Tracef(r->tracer, __VA_ARGS__)
void configurationTrace(const struct raft *r,
struct raft_configuration *c,
const char *msg)
{
if (r == NULL || c == NULL || !r->tracer->enabled) {
return;
}

tracef("%s", msg);
tracef("=== CONFIG START ===");
unsigned i;
struct raft_server *s;
for (i = 0; i < c->n; i++) {
s = &c->servers[i];
tracef("id:%llu address:%s role:%d", s->id, s->address, s->role);
}
tracef("=== CONFIG END ===");
}
#undef tracef
5 changes: 0 additions & 5 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,4 @@ int configurationEncode(const struct raft_configuration *c,
int configurationDecode(const struct raft_buffer *buf,
struct raft_configuration *c);

/* Output the configuration to the raft tracer */
void configurationTrace(const struct raft *r,
struct raft_configuration *c,
const char *msg);

#endif /* CONFIGURATION_H_ */
4 changes: 0 additions & 4 deletions src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ static void convertSetState(struct raft *r, unsigned short new_state)
/* Check that the transition is legal, see Figure 3.3. Note that with
* respect to the paper we have an additional "unavailable" state, which is
* the initial or final state. */
tracef("old_state:%u new_state:%u", r->state, new_state);
assert(r->state != new_state);
assert((r->state == RAFT_UNAVAILABLE && new_state == RAFT_FOLLOWER) ||
(r->state == RAFT_FOLLOWER && new_state == RAFT_CANDIDATE) ||
Expand All @@ -38,7 +37,6 @@ static void convertSetState(struct raft *r, unsigned short new_state)
/* Clear follower state. */
static void convertClearFollower(struct raft *r)
{
tracef("clear follower state");
r->follower_state.current_leader.id = 0;
if (r->follower_state.current_leader.address != NULL) {
raft_free(r->follower_state.current_leader.address);
Expand All @@ -49,7 +47,6 @@ static void convertClearFollower(struct raft *r)
/* Clear candidate state. */
static void convertClearCandidate(struct raft *r)
{
tracef("clear candidate state");
if (r->candidate_state.votes != NULL) {
raft_free(r->candidate_state.votes);
r->candidate_state.votes = NULL;
Expand All @@ -59,7 +56,6 @@ static void convertClearCandidate(struct raft *r)
/* Clear leader state. */
static void convertClearLeader(struct raft *r)
{
tracef("clear leader state");
if (r->leader_state.progress != NULL) {
raft_free(r->leader_state.progress);
r->leader_state.progress = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/election.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ void electionStart(struct raft *r)
if (!r->candidate_state.in_pre_vote) {
/* Increment current term and vote for self */
term = r->current_term + 1;
tracef("beginning of term %llu", term);

/* Mark both the current term and vote as changed. */
r->update->flags |= RAFT_UPDATE_CURRENT_TERM | RAFT_UPDATE_VOTED_FOR;
Expand Down
Loading

0 comments on commit 72b4804

Please sign in to comment.