Skip to content

Commit

Permalink
test: Convert replication tests to use the v1 API
Browse files Browse the repository at this point in the history
Signed-off-by: Free Ekanayaka <free@ekanayaka.io>
  • Loading branch information
freeekanayaka committed Dec 27, 2023
1 parent a2fa4e0 commit c525baa
Show file tree
Hide file tree
Showing 10 changed files with 825 additions and 347 deletions.
2 changes: 1 addition & 1 deletion src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "request.h"
#include "tracing.h"

#define infof(...) Tracef(r->tracer, __VA_ARGS__)
#define infof(...) Infof(r->tracer, " " __VA_ARGS__)
#define tracef(...) Tracef(r->tracer, __VA_ARGS__)

/* Convenience for setting a new state value and asserting that the transition
Expand Down
7 changes: 3 additions & 4 deletions src/recv_append_entries.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "tracing.h"

#define infof(...) Infof(r->tracer, " " __VA_ARGS__)
#define tracef(...) Tracef(r->tracer, __VA_ARGS__)

int recvAppendEntries(struct raft *r,
raft_id id,
Expand Down Expand Up @@ -46,7 +45,8 @@ int recvAppendEntries(struct raft *r,
* currentTerm.
*/
if (match < 0) {
tracef("local term is higher -> reject ");
infof("local term is higher (%llu vs %llu) -> reject", r->current_term,
args->term);
goto reply;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ int recvAppendEntries(struct raft *r,
* something smarter, e.g. buffering the entries in the I/O backend, which
* should be in charge of serializing everything. */
if (replicationInstallSnapshotBusy(r) && args->n_entries > 0) {
tracef("ignoring AppendEntries RPC during snapshot install");
infof("ignoring AppendEntries RPC during snapshot install");
entryBatchesDestroy(args->entries, args->n_entries);
return 0;
}
Expand Down Expand Up @@ -149,4 +149,3 @@ int recvAppendEntries(struct raft *r,
}

#undef infof
#undef tracef
2 changes: 2 additions & 0 deletions src/recv_append_entries_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "replication.h"
#include "tracing.h"

#define infof(...) Infof(r->tracer, " " __VA_ARGS__)
#define tracef(...) Tracef(r->tracer, __VA_ARGS__)

int recvAppendEntriesResult(struct raft *r,
Expand Down Expand Up @@ -70,4 +71,5 @@ int recvAppendEntriesResult(struct raft *r,
return 0;
}

#undef infof
#undef tracef
12 changes: 5 additions & 7 deletions src/recv_install_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "replication.h"
#include "tracing.h"

#define infof(...) Infof(r->tracer, " " __VA_ARGS__)
#define tracef(...) Tracef(r->tracer, __VA_ARGS__)

int recvInstallSnapshot(struct raft *r,
Expand All @@ -23,11 +24,6 @@ int recvInstallSnapshot(struct raft *r,
bool async;

assert(address != NULL);
tracef(
"self:%llu from:%llu@%s conf_index:%llu last_index:%llu last_term:%llu "
"term:%llu",
r->id, id, address, args->conf_index, args->last_index, args->last_term,
args->term);

result->rejected = args->last_index;
result->last_log_index = logLastIndex(r->log);
Expand All @@ -40,7 +36,8 @@ int recvInstallSnapshot(struct raft *r,
}

if (match < 0) {
tracef("local term is higher -> reject ");
infof("local term is higher (%llu vs %llu) -> reject", r->current_term,
args->term);
goto reply;
}

Expand All @@ -49,7 +46,7 @@ int recvInstallSnapshot(struct raft *r,
assert(r->current_term == args->term);
if (r->state == RAFT_CANDIDATE) {
assert(match == 0);
tracef("discovered leader -> step down ");
infof("discovered leader (%llu) -> step down ", id);
convertToFollower(r);
}

Expand Down Expand Up @@ -94,4 +91,5 @@ int recvInstallSnapshot(struct raft *r,
return 0;
}

#undef infof
#undef tracef
17 changes: 9 additions & 8 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ static int sendSnapshot(struct raft *r, const unsigned i)
goto err;
}

tracef("sending snapshot with last index %llu to %llu", args->last_index,
server->id);
infof("sending snapshot with last index %llu to %llu", args->last_index,
server->id);

rv = MessageEnqueue(r, &message);
if (rv != 0) {
Expand Down Expand Up @@ -565,7 +565,7 @@ int replicationUpdate(struct raft *r,
result->last_log_index);
if (retry) {
/* Retry, ignoring errors. */
tracef("log mismatch -> send old entries to %llu", server->id);
infof("log mismatch -> send old entries");
replicationProgress(r, i);
}
return 0;
Expand Down Expand Up @@ -781,7 +781,8 @@ static int checkLogMatchingProperty(struct raft *r,

local_prev_term = logTermOf(r->log, args->prev_log_index);
if (local_prev_term == 0) {
tracef("no entry at index %llu -> reject", args->prev_log_index);
infof("missing entry (%llu^%llu) -> reject", args->prev_log_index,
args->prev_log_term);
return 1;
}

Expand All @@ -795,7 +796,7 @@ static int checkLogMatchingProperty(struct raft *r,
r->commit_index);
return -1;
}
tracef("previous term mismatch -> reject");
infof("previous term mismatch -> reject");
return 1;
}

Expand Down Expand Up @@ -1085,21 +1086,21 @@ int replicationInstallSnapshot(struct raft *r,
* something smarter. */
if (r->snapshot.taking || r->snapshot.persisting) {
*async = true;
tracef("already taking or installing snapshot");
infof("already taking or installing snapshot");
return RAFT_BUSY;
}

/* If our last snapshot is more up-to-date, this is a no-op */
if (r->log->snapshot.last_index >= args->last_index) {
tracef("have more recent snapshot");
infof("have more recent snapshot");
*rejected = 0;
return 0;
}

/* If we already have all entries in the snapshot, this is a no-op */
local_term = logTermOf(r->log, args->last_index);
if (local_term != 0 && local_term >= args->last_term) {
tracef("have all entries");
infof("have all entries");
*rejected = 0;
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/test_election.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ TEST_V1(election, GrantAgain, setUp, tearDown, 0, NULL)
* result and eventually starts a new election round. */
CLUSTER_DISCONNECT(2, 1);
CLUSTER_TRACE(
"[ 270] 1 > timeout as candidate\n"
"[ 200] 1 > timeout as candidate\n"
" stay candidate, start election for term 3\n");

/* Reconnecting the two servers eventually makes the first server win the
* election. */
CLUSTER_RECONNECT(2, 1);

CLUSTER_TRACE(
"[ 280] 2 > recv request vote from server 1\n"
"[ 210] 2 > recv request vote from server 1\n"
" remote term is higher (3 vs 2) -> bump term\n"
" remote log equal or longer (1^1 vs 1^1) -> grant vote\n");

CLUSTER_TRACE(
"[ 290] 1 > recv request vote result from server 2\n"
"[ 220] 1 > recv request vote result from server 2\n"
" quorum reached with 2 votes out of 2 -> convert to leader\n"
" replicate 1 new entry (2^3)\n"
" probe server 2 sending 1 entry (2^3)\n");
Expand Down
Loading

0 comments on commit c525baa

Please sign in to comment.