Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1: Drop status field from RAFT_PERSISTED_SNAPSHOT #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/raft.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ struct raft_event
size_t offset;
struct raft_buffer chunk;
bool last;
int status;
} persisted_snapshot;
struct
{
Expand Down Expand Up @@ -617,6 +616,7 @@ struct raft; /* Forward declaration. */
raft_index snapshot_index; /* Last persisted snapshot */ \
struct raft_buffer snapshot_chunk; /* Cache of snapshot data */ \
bool snapshot_taking; /* True when taking a snapshot */ \
void *snapshot_pending; /* Pending install snapshot */ \
struct raft_log *log; /* Cache on-disk log */ \
} legacy;
#endif /* RAFT__LEGACY_no */
Expand Down
5 changes: 2 additions & 3 deletions src/legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ static void legacyPersistSnapshotCb(struct raft_io_snapshot_put *put,
event.persisted_snapshot.offset = req->offset;
event.persisted_snapshot.chunk = req->chunk;
event.persisted_snapshot.last = req->last;
event.persisted_snapshot.status = status;

/* If we successfully persisted the snapshot, keep the snapshot data around,
* since we'll then need it immediately after calling raft_step(), in order
Expand All @@ -253,15 +252,15 @@ static void legacyPersistSnapshotCb(struct raft_io_snapshot_put *put,
assert(r->legacy.snapshot_index == 0);
r->legacy.snapshot_index = req->metadata.index;
r->legacy.snapshot_chunk = req->chunk;
LegacyForwardToRaftIo(r, &event);
} else {
assert(r->legacy.closing);
assert(status == RAFT_CANCELED);
raft_free(req->chunk.base);
raft_configuration_close(&req->metadata.configuration);
}

raft_free(req);

LegacyForwardToRaftIo(r, &event);
}

static int legacyHandleUpdateSnapshot(struct raft *r,
Expand Down
10 changes: 4 additions & 6 deletions src/raft.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ int raft_init(struct raft *r,
r->legacy.change = NULL;
r->legacy.snapshot_index = 0;
r->legacy.snapshot_taking = false;
r->legacy.snapshot_pending = NULL;
r->transfer = NULL;
r->legacy.log = logInit();
if (r->legacy.log == NULL) {
Expand Down Expand Up @@ -414,13 +415,11 @@ static int stepPersistedSnapshot(struct raft *r,
struct raft_snapshot_metadata *metadata,
size_t offset,
struct raft_buffer *chunk,
bool last,
int status)
bool last)
{
int rv;
infof("persisted snapshot (%llu^%llu)", metadata->index, metadata->term);
rv = replicationPersistSnapshotDone(r, metadata, offset, chunk, last,
status);
rv = replicationPersistSnapshotDone(r, metadata, offset, chunk, last);
if (rv != 0) {
return rv;
}
Expand Down Expand Up @@ -515,8 +514,7 @@ int raft_step(struct raft *r,
rv = stepPersistedSnapshot(r, &event->persisted_snapshot.metadata,
event->persisted_snapshot.offset,
&event->persisted_snapshot.chunk,
event->persisted_snapshot.last,
event->persisted_snapshot.status);
event->persisted_snapshot.last);
break;
case RAFT_RECEIVE:
rv = stepReceive(r, event->receive.message);
Expand Down
12 changes: 2 additions & 10 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,7 @@ int replicationPersistSnapshotDone(struct raft *r,
struct raft_snapshot_metadata *metadata,
size_t offset,
struct raft_buffer *chunk,
bool last,
int status)
bool last)
{
struct raft_append_entries_result result;
int rv;
Expand All @@ -892,21 +891,14 @@ int replicationPersistSnapshotDone(struct raft *r,
result.features = MESSAGE__FEATURE_CAPACITY;
result.rejected = 0;

if (status != 0) {
infof("failed to persist snapshot %llu^%llu: %s", metadata->index,
metadata->term, raft_strerror(status));
goto discard;
}

/* From Figure 5.3:
*
* 7. Discard the entire log
* 8. ... load lastConfig as cluster configuration
*/
rv = RestoreSnapshot(r, metadata);
if (rv != 0) {
tracef("restore snapshot %llu: %s", metadata->index,
raft_strerror(status));
tracef("restore snapshot %llu: %s", metadata->index, raft_strerror(rv));
goto discard;
}

Expand Down
3 changes: 1 addition & 2 deletions src/replication.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ int replicationPersistSnapshotDone(struct raft *r,
struct raft_snapshot_metadata *metadata,
size_t offset,
struct raft_buffer *chunk,
bool last,
int status);
bool last);

/* Called when a RAFT_SNAPSHOT event is fired, signalling the completion of a
* new snapshot. */
Expand Down
5 changes: 1 addition & 4 deletions test/integration/test_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ TEST(snapshot, AbortIfRejected, setUp, tearDown, 0, NULL)
" start persisting snapshot (2^2)\n");
CLUSTER_STOP(2);
CLUSTER_START(2);
CLUSTER_TRACE(
"[ 150] 2 > persisted snapshot (2^2)\n"
" failed to persist snapshot 2^2: operation canceled\n"
"[ 150] 2 > term 3, voted for 1, 1 entry (1^1)\n");
CLUSTER_TRACE("[ 150] 2 > term 3, voted for 1, 1 entry (1^1)\n");

/* Server 1 eventually sends server 2 a heartbeat, which server 2 rejects.
* At that point server 1 sends again the snapshot. */
Expand Down
10 changes: 2 additions & 8 deletions test/lib/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,10 @@ static void serverCancelEntries(struct test_server *s, struct step *step)
static void serverCancelSnapshot(struct test_server *s, struct step *step)
{
struct raft_event *event = &step->event;
int rv;

event->time = s->cluster->time;
event->persisted_snapshot.status = RAFT_CANCELED;
(void)s;

/* XXX: this should probably be done by raft core */
raft_free(event->persisted_snapshot.chunk.base);

rv = serverStep(s, event);
munit_assert_int(rv, ==, 0);
raft_configuration_close(&event->persisted_snapshot.metadata.configuration);
}

/* Release the memory used by a RAFT_RECEIVE event. */
Expand Down
Loading