Code-Fight commented on code in PR #897:
URL:
https://github.com/apache/incubator-seata-go/pull/897#discussion_r2412491728
##########
pkg/saga/statemachine/engine/repo/repository/state_machine_repository.go:
##########
@@ -71,6 +71,14 @@ func GetStateMachineRepositoryImpl()
*StateMachineRepositoryImpl {
return stateMachineRepositoryImpl
}
+func (s *StateMachineRepositoryImpl) SetDefaultTenantId(tenantId string) {
+ s.defaultTenantId = tenantId
+}
+
+func (s *StateMachineRepositoryImpl) GetDefaultTenantId() string {
+ return s.defaultTenantId
Review Comment:
这个不需要,目前java实现也是这么做的
##########
pkg/saga/statemachine/engine/pcext/state_router_impl.go:
##########
@@ -53,15 +68,81 @@ func (t TaskStateRouter) Route(ctx context.Context,
processContext process_ctrl.
return nil, nil
}
- // The current CompensationTriggerState can mark the compensation
process is started and perform compensation
- // route processing.
- compensationTriggerState, ok :=
processContext.GetVariable(constant.VarNameCurrentCompensateTriggerState).(statelang.State)
- if ok {
+ // If current state is CompensationTrigger or compensation has been
flagged, start compensation routing
+ if state != nil && state.Type() ==
constant.StateTypeCompensationTrigger {
+ // flag into context for downstream calls (best-effort)
+ if hpc, ok :=
processContext.(process_ctrl.HierarchicalProcessContext); ok {
+
hpc.SetVariableLocally(constant.VarNameCurrentCompensateTriggerState, state)
+
hpc.SetVariableLocally(constant.VarNameFirstCompensationStateStarted, false)
+ } else {
+
processContext.SetVariable(constant.VarNameCurrentCompensateTriggerState, state)
+
processContext.SetVariable(constant.VarNameFirstCompensationStateStarted, false)
+ }
+
+ // build compensation stack from executed forward states
(latest first)
+ smInst :=
processContext.GetVariable(constant.VarNameStateMachineInst).(statelang.StateMachineInstance)
+ holder := GetCurrentCompensationHolder(ctx, processContext,
true)
+ stack := holder.StateStackNeedCompensation()
+ sm :=
processContext.GetVariable(constant.VarNameStateMachine).(statelang.StateMachine)
+ states := smInst.StateList()
+ for i := len(states) - 1; i >= 0; i-- {
+ si := states[i]
+ // exclude compensation states
+ if si.StateIDCompensatedFor() != "" {
+ continue
+ }
+ // only successful forward states are subject to
compensation
+ if si.Status() != statelang.SU {
+ continue
+ }
+ originName := GetOriginStateName(si)
+ def := sm.State(originName)
+ // ensure the definition has a compensate state
+ var task *sagaState.AbstractTaskState
+ switch s := def.(type) {
+ case *sagaState.ServiceTaskStateImpl:
+ task = s.AbstractTaskState
+ case *sagaState.ScriptTaskStateImpl:
+ task = s.AbstractTaskState
+ case *sagaState.SubStateMachineImpl:
+ if s.ServiceTaskStateImpl != nil {
+ task =
s.ServiceTaskStateImpl.AbstractTaskState
+ }
+ }
+ if task == nil || task.CompensateState() == "" {
+ continue
+ }
+ stack.Push(si)
+ }
+ // fallback: if nothing pushed, try last successful forward
state
+ if stack.Empty() {
+ for i := len(states) - 1; i >= 0; i-- {
+ si := states[i]
+ if si.StateIDCompensatedFor() != "" {
+ continue
+ }
+ if si.Status() != statelang.SU {
+ continue
+ }
+ stack.Push(si)
+ break
+ }
+ }
+
+ // mark machine compensation running
+ smInst.SetCompensationStatus(statelang.RU)
+
+ return t.compensateRoute(ctx, processContext, state)
Review Comment:
这个暂时不需要,已经在 statelog.go:231-258 有完善的补偿逻辑
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]