[
https://issues.apache.org/jira/browse/RATIS-2721?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tsz-wo Sze updated RATIS-2721:
------------------------------
Component/s: StateMachine
> Notify the StateMachine when a server shutdown starts
> -----------------------------------------------------
>
> Key: RATIS-2721
> URL: https://issues.apache.org/jira/browse/RATIS-2721
> Project: Ratis
> Issue Type: Improvement
> Components: StateMachine
> Reporter: Rui Wang
> Assignee: Rui Wang
> Priority: Major
>
> h2. Problem
> A {{StateMachine}} has no notification, within a bounded time, that its
> server is
> shutting down. There is only a configurable parameter to wait until force
> close the state machine
> whose default value is one hour. Both existing signals are delivered only
> *after* the shutdown has
> waited for all committed entries to be applied, which is unbounded in time:
> * {{RaftServerProxy.close()}} -> {{ImplMap.close()}} ->
> {{RaftServerImpl.close()}}
> -> {{ServerState.close()}} -> {{StateMachineUpdater.stopAndJoin()}}, which
> sets
> {{stopIndex = raftLog.getLastCommittedIndex()}} and then joins the updater
> thread.
> It returns only once every entry up to {{stopIndex}} has been applied.
> * {{StateMachine.close()}} is invoked from {{StateMachineUpdater.stop()}},
> which runs
> only when {{appliedIndex >= stopIndex}}.
> * {{EventApi.notifyServerShutdown(RoleInfoProto, boolean)}} is invoked in
> {{ImplMap.close(..)}} after {{impl.close()}} has returned.
> So both callbacks are effectively "shutdown completed" signals, and an
> application
> embedding a {{RaftServer}} cannot use either one to react to a shutdown in
> progress.
> This matters because a server can initiate its own shutdown:
> {{JvmPauseMonitor}} calls
> {{RaftServerProxy.close()}} when a detected pause exceeds
> {{raft.server.close.threshold}} (default 60s). The division moves to
> {{CLOSING}} and
> starts rejecting {{appendEntries}} immediately, so a lagging follower stops
> replicating
> while it keeps applying toward {{stopIndex}}. Until that finishes, the
> embedding
> application is not told anything.
> h2. Observed impact
> Ozone already terminates the SCM process when Ratis closes its state machine
> ({{SCMStateMachine.close()}}), but because that callback only arrives after
> the drain,
> the process stayed up in a half-dead state for the whole period: Raft
> rejecting
> {{appendEntries}}, datanode heartbeats still being accepted, and no signal
> that Raft was
> down. The shutdown eventually surfaced only as
> {{IllegalStateException: ... shutdown timeout in 1day}} from
> {{ConcurrentUtils.shutdownAndWait(ExecutorService)}}.
> h2. Proposal
> Add a new default no-op method to {{StateMachine.EventApi}}:
> {code:java}
> default void notifyServerShutdownStarted(RoleInfoProto roleInfo, boolean
> allServer) {}
> {code}
> invoked before the shutdown releases any resources, so an application can
> react
> immediately -- e.g. reject incoming requests, or terminate itself -- instead
> of waiting
> for the shutdown to complete.
> A new callback is used rather than invoking {{StateMachine.close()}} earlier,
> because at
> that point the {{StateMachineUpdater}} is still calling {{applyTransaction}}.
> Closing the
> state machine there would break the existing contract that {{close()}}
> happens after the
> apply loop has stopped, and in practice would release resources underneath an
> active
> applier.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)