transitions icon indicating copy to clipboard operation
transitions copied to clipboard

Practice on collecting states from multiple machine

Open hu6360567 opened this issue 2 years ago • 0 comments

I'm trying to use transistions to implment a scheduler for distributed system. Let's say, there are three participants A, B, C in a distrubted task; scheduler runs on each participant to broadcast its own state periodicity and collect peer state to make callback to its own participant. Each participant have states ['unspecified', 'inited', 'prepared, 'done', 'error']; to_prepared should be triggered when all participants are inited. to_done(execute) should be triggered when all participants are prepared.

For more detail,

  1. scheduler of A is inited and all peers are unspecified on initial;
  2. after receiving "inited" messages from B and C, scheduler call to_prepared; sceduler of A become prepared after the trigger
  3. after receiving "prepared" messages from all peers, scheduler call to_done

Since messages that send from one to another participant may be lost, or disordering, to be robust, peer state can be skipped, e.g. B from unspecified to prepared from the perspective of A [ B received A and C inited messages, but A missed the "inited" message from B].

I'd like to implement the scheduler by HSM at the first place, but it seems much more complicated. paralleled states cannot be inherited between top level states, then the skipped states are not able to be presented. For now, the scheduler is implemented in a separate state machine, process each message to update peer state, and after that, it calculates the overall state of peers to identify its state.

What's the best practice of such scenario? Can it be done by nested state machine?

hu6360567 avatar Apr 05 '22 07:04 hu6360567