Skip to content

Commit

Permalink
In replication scenario, entry_sm gets updated every time it is used.
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bilenko <[email protected]>
  • Loading branch information
just-now committed Nov 29, 2024
1 parent fe22b28 commit b18dfbc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/raft/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,10 @@ int replicationApply(struct raft *r)
tracef("replicationApply - ENTRY NULL");
return 0;
}
struct sm *entry_sm = log_get_entry_sm(r->log, entry->term, index);
raft_term entry_sm_term = entry->term;
raft_index entry_sm_index = index;
struct sm *entry_sm = log_get_entry_sm(r->log, entry_sm_term,
entry_sm_index);
assert(entry_sm != NULL);

assert(entry->type == RAFT_COMMAND ||
Expand All @@ -1865,6 +1868,11 @@ int replicationApply(struct raft *r)
}

if (rv == 0) {
/* applyCommand() may change raft log thus the reference
* to the entry_sm may be no longer valid. */
entry_sm = log_get_entry_sm(r->log, entry_sm_term,
entry_sm_index);
assert(entry_sm != NULL);
sm_move(entry_sm, ENTRY_APPLIED);
} else {
break;
Expand Down

0 comments on commit b18dfbc

Please sign in to comment.