From b18dfbc3f9f89ed219611e88bad1fa17d1e9e818 Mon Sep 17 00:00:00 2001 From: Anatoliy Bilenko Date: Mon, 25 Nov 2024 11:09:15 +0000 Subject: [PATCH] In replication scenario, entry_sm gets updated every time it is used. Signed-off-by: Anatoliy Bilenko --- src/raft/replication.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/raft/replication.c b/src/raft/replication.c index 59576cd97..ef63396c0 100644 --- a/src/raft/replication.c +++ b/src/raft/replication.c @@ -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 || @@ -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;