MCPcopy
hub / github.com/grafana/dskit / changeState

Method changeState

ring/lifecycler.go:985–1000  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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().
985func (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
1002func (i *Lifecycler) updateCounters(ringDesc *Desc) {
1003 healthyInstancesCount := 0

Callers 6

ChangeStateMethod · 0.95
loopMethod · 0.95
stoppingMethod · 0.95

Calls 5

GetStateMethod · 0.95
setStateMethod · 0.95
updateConsulMethod · 0.95
ErrorfMethod · 0.80
LogMethod · 0.45