rajesh created HDDS-17842:
-----------------------------

             Summary: Refactor SCMStateMachine: extract request dispatch, 
readiness and DN server startup out of the Ratis state machine
                 Key: HDDS-17842
                 URL: https://issues.apache.org/jira/browse/HDDS-17842
             Project: Apache Ozone
          Issue Type: Task
            Reporter: rajesh
            Assignee: rajesh


{{SCMStateMachine}} mixes several responsibilities, and callers depend on the 
concrete class instead of an abstraction.

_Problems_
 # Request dispatch is registered through the concrete class. 
 ** {{SCMStateMachine}} owns a {{Map<RequestType, ScmInvoker<?>>}} filled 
through {{{}registerInvoker(...){}}}.
 ** {{SCMRatisServerImpl.registerStateMachineHandler}} has to hold a concrete 
{{SCMStateMachine}} just to push handlers into it.
 ** Dispatch is a separate concern from applying Ratis transactions, and 
nothing names it.
 # Callers depend on the class and not on {{{}StateMachine{}}}. 
 ** {{SCMRatisServer.getSCMStateMachine()}} returns the class, and 3 production 
callers and about 10 test callers use it.
 ** They need {{getIsStateMachineReady()}} or {{{}stopDNServerStartRetry(){}}}, 
which exist only on the class.
 ** The state machine cannot be wrapped (for example by a tracing proxy) or 
substituted without breaking those callers.
 # Readiness is a flag with {{if}} checks. 
 ** {{getIsStateMachineReady()}} and {{isStateMachineReady}} are checked in 
many places in {{SCMStateMachine}} and polled by {{{}StateMachineReadyRule{}}}.
 ** The behaviour differs before and after readiness, which suggests two states 
(for example a safe-mode state machine and a full-mode state machine) and not 
conditionals.
 # Datanode server startup lives in the state machine. 
 ** {{{}tryStartDNServerAndRefreshSafeMode{}}}, the retry executor and 
{{stopDNServerStartRetry()}} are datanode-protocol-server lifecycle code.
 ** It is called from Ratis callbacks, and {{StorageContainerManager.stop}} has 
to reach into the state machine to stop it.

_Proposal (to be refined)_
 * Introduce a request registry abstraction, for example {{ScmRequestRegistry}} 
with {{register}} and lookup, plus an {{{}Impl{}}}. The Ratis server creates it 
and passes it to the state machine through the constructor.
 * Make callers depend on a narrow interface that extends Ratis 
{{{}StateMachine{}}}.
 * Move datanode server start and retry out of {{SCMStateMachine}} into its own 
component, with {{StorageContainerManager}} owning its lifecycle.
 * Investigate modelling readiness as separate state-machine behaviour and 
removing the readiness checks.

_Benefits_
 * Wrapping or decorating the state machine, for example the tracing proxy via 
{{{}TracingUtil.createInternalProxy{}}}, works without a raw-instance 
workaround or {{@SkipTracing}} hacks.
 * Dispatch and readiness can be unit-tested without a full 
{{{}SCMStateMachine{}}}.
 * The state machine shrinks to Ratis concerns, and SCM shutdown ordering 
becomes explicit.
 * Less test churn, because callers stop depending on the concrete class.

_Out of scope:_ any behaviour change, and any change to the Ratis log or 
protocol.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to