generation-aware playback statuses
This commit is contained in:
@@ -109,9 +109,8 @@ func (c *SessionController) Run(
|
||||
}
|
||||
|
||||
desired := initial
|
||||
runtime := c.startSessionRuntime(ctx, plan)
|
||||
|
||||
generation := uint64(1)
|
||||
runtime := c.startSessionRuntime(ctx, plan, generation)
|
||||
c.publish(SessionSnapshot{
|
||||
Desired: initial,
|
||||
Plan: plan,
|
||||
@@ -148,11 +147,16 @@ func (c *SessionController) Run(
|
||||
continue
|
||||
}
|
||||
|
||||
nextGeneration := generation
|
||||
if plan.Topology != nextPlan.Topology {
|
||||
nextGeneration++
|
||||
}
|
||||
nextRuntime, err := c.reconcileSessionRuntime(
|
||||
ctx,
|
||||
runtime,
|
||||
plan,
|
||||
nextPlan,
|
||||
nextGeneration,
|
||||
)
|
||||
if err != nil {
|
||||
stopSessionRuntime(runtime)
|
||||
@@ -162,9 +166,7 @@ func (c *SessionController) Run(
|
||||
return err
|
||||
}
|
||||
|
||||
if plan.Topology != nextPlan.Topology {
|
||||
generation++
|
||||
}
|
||||
generation = nextGeneration
|
||||
desired = nextDesired
|
||||
plan = nextPlan
|
||||
runtime = nextRuntime
|
||||
@@ -180,12 +182,13 @@ func (c *SessionController) Run(
|
||||
func (c *SessionController) startSessionRuntime(
|
||||
ctx context.Context,
|
||||
plan SessionPlan,
|
||||
generation uint64,
|
||||
) *sessionRuntime {
|
||||
if plan.Topology == TopologyIdle {
|
||||
return &sessionRuntime{topology: TopologyIdle}
|
||||
}
|
||||
|
||||
runtimeCtx, cancel := context.WithCancel(ctx)
|
||||
runtimeCtx, cancel := context.WithCancel(withGeneration(ctx, generation))
|
||||
runtime := &sessionRuntime{
|
||||
topology: plan.Topology,
|
||||
cancel: cancel,
|
||||
@@ -255,13 +258,14 @@ func (c *SessionController) reconcileSessionRuntime(
|
||||
runtime *sessionRuntime,
|
||||
current SessionPlan,
|
||||
next SessionPlan,
|
||||
nextGeneration uint64,
|
||||
) (*sessionRuntime, error) {
|
||||
if current.Topology != next.Topology {
|
||||
stopSessionRuntime(runtime)
|
||||
if err := ctx.Err(); err != nil {
|
||||
return runtime, err
|
||||
}
|
||||
return c.startSessionRuntime(ctx, next), nil
|
||||
return c.startSessionRuntime(ctx, next, nextGeneration), nil
|
||||
}
|
||||
|
||||
switch next.Topology {
|
||||
|
||||
Reference in New Issue
Block a user