Skip to content
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
5 changes: 5 additions & 0 deletions src/legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ static void takeSnapshotCb(struct raft_io_snapshot_put *put, int status)
event.snapshot.metadata = metadata;
event.snapshot.trailing = r->legacy.snapshot_trailing;
LegacyForwardToRaftIo(r, &event);
raft_configuration_close(&metadata.configuration);

if (r->legacy.snapshot_pending != NULL) {
struct legacyPersistSnapshot *persist;
Expand Down Expand Up @@ -1115,6 +1116,10 @@ static int legacyHandleEvent(struct raft *r,
return rv;
}

if (event->type == RAFT_CONFIGURATION) {
raft_configuration_close(&event->configuration.conf);
}

if (update.flags & RAFT_UPDATE_STATE) {
legacyHandleStateUpdate(r);
}
Expand Down
19 changes: 14 additions & 5 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,11 @@ int replicationApplyConfigurationChange(struct raft *r,
struct raft_configuration *conf,
raft_index index)
{
int rv;

assert(index > 0);

if (r->configuration_uncommitted_index != index) {
configurationClose(conf);
return 0;
}

Expand All @@ -1036,8 +1037,12 @@ int replicationApplyConfigurationChange(struct raft *r,
* index, since that uncommitted configuration is now committed. */
r->configuration_uncommitted_index = 0;
r->configuration_committed_index = index;

configurationClose(&r->configuration_committed);
r->configuration_committed = *conf;
rv = configurationCopy(conf, &r->configuration_committed);
if (rv != 0) {
return rv;
}

if (r->state == RAFT_LEADER) {
const struct raft_server *server;
Expand Down Expand Up @@ -1070,6 +1075,8 @@ int replicationSnapshot(struct raft *r,
struct raft_snapshot_metadata *metadata,
unsigned trailing)
{
int rv;

(void)trailing;

/* Make also a copy of the index of the configuration contained in the
Expand All @@ -1078,9 +1085,11 @@ int replicationSnapshot(struct raft *r,

if (metadata->configuration_index > r->configuration_committed_index) {
configurationClose(&r->configuration_committed);
r->configuration_committed = metadata->configuration;
} else {
configurationClose(&metadata->configuration);
rv = configurationCopy(&metadata->configuration,
&r->configuration_committed);
if (rv != 0) {
return rv;
}
}

TrailSnapshot(&r->trail, metadata->index, trailing);
Expand Down
7 changes: 3 additions & 4 deletions test/lib/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ static void serverCompleteConfiguration(struct test_server *s,
rv = serverStep(s, event);
munit_assert_int(rv, ==, 0);

raft_configuration_close(&event->configuration.conf);

/* The last call to raft_step() did not change the commit index. */
munit_assert_ullong(raft_commit_index(r), ==, commit_index);
}
Expand All @@ -1104,10 +1106,7 @@ static void serverCompleteTakeSnapshot(struct test_server *s, struct step *step)
* entry. */
snapshot->metadata.index = event->snapshot.metadata.index;
snapshot->metadata.term = event->snapshot.metadata.term;

confCopy(&event->snapshot.metadata.configuration,
&snapshot->metadata.configuration);

snapshot->metadata.configuration = event->snapshot.metadata.configuration;
snapshot->data.len = 8;
snapshot->data.base = munit_malloc(snapshot->data.len);

Expand Down
Loading