changeState updates consul with state transitions for us. NB this must be called from loop()! Use ChangeState for calls from outside of loop().
(ctx context.Context, state InstanceState)
| 983 | // changeState updates consul with state transitions for us. NB this must be |
| 984 | // called from loop()! Use ChangeState for calls from outside of loop(). |
| 985 | func (i *Lifecycler) changeState(ctx context.Context, state InstanceState) error { |
| 986 | currState := i.GetState() |
| 987 | // Only the following state transitions can be triggered externally |
| 988 | //nolint:staticcheck |
| 989 | if !((currState == PENDING && state == JOINING) || // triggered by TransferChunks at the beginning |
| 990 | (currState == JOINING && state == PENDING) || // triggered by TransferChunks on failure |
| 991 | (currState == JOINING && state == ACTIVE) || // triggered by TransferChunks on success |
| 992 | (currState == PENDING && state == ACTIVE) || // triggered by autoJoin |
| 993 | (currState == ACTIVE && state == LEAVING)) { // triggered by shutdown |
| 994 | return fmt.Errorf("changing instance state from %v -> %v is disallowed", currState, state) |
| 995 | } |
| 996 | |
| 997 | level.Info(i.logger).Log("msg", "changing instance state from", "old_state", currState, "new_state", state, "ring", i.RingName) |
| 998 | i.setState(state) |
| 999 | return i.updateConsul(ctx) |
| 1000 | } |
| 1001 | |
| 1002 | func (i *Lifecycler) updateCounters(ringDesc *Desc) { |
| 1003 | healthyInstancesCount := 0 |