updateAndPersist should be called before switchBehavior.
Otherwise, when the EntityOwnershipShard trigger a new write transaction
in onLeaderChanged base on last term, It will lead to fail in this
transaction because of the term value is inconsistent between AppendEntries
and AppendEntriesReply
Change-Id: I9118f7ec283f23e02dc285ccf6a3fbbce47dc508
Signed-off-by: HeYunBo <he.yunbo@zte.com.cn>
if (!getRaftActorContext().getRaftPolicy().automaticElectionsEnabled()) {
RaftState newState = message.getNewState();
if (newState == RaftState.Leader || newState == RaftState.Follower) {
+ getRaftActorContext().getTermInformation().updateAndPersist(message.getNewTerm(), "");
switchBehavior(behaviorStateTracker.capture(getCurrentBehavior()),
AbstractRaftActorBehavior.createBehavior(context, message.getNewState()));
- getRaftActorContext().getTermInformation().updateAndPersist(message.getNewTerm(), "");
} else {
LOG.warn("Switching to behavior : {} - not supported", newState);
}