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

Method waitBeforeJoining

ring/lifecycler.go:865–909  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

863}
864
865func (i *Lifecycler) waitBeforeJoining(ctx context.Context) error {
866 if !i.tokenGenerator.CanJoinEnabled() {
867 return nil
868 }
869
870 level.Info(i.logger).Log("msg", "waiting to be able to join the ring", "ring", i.RingName, "id", i.cfg.ID, "timeout", i.canJoinTimeout)
871
872 ctxWithTimeout, cancel := context.WithTimeout(ctx, i.canJoinTimeout)
873 defer cancel()
874 retries := backoff.New(ctxWithTimeout, backoff.Config{
875 MinBackoff: 1 * time.Second,
876 MaxBackoff: 1 * time.Second,
877 MaxRetries: 0,
878 })
879
880 var lastError error
881 for ; retries.Ongoing(); retries.Wait() {
882 var desc interface{}
883 desc, lastError = i.KVStore.Get(ctxWithTimeout, i.RingKey)
884 if lastError != nil {
885 lastError = errors.Wrap(lastError, "error getting the ring from the KV store")
886 continue
887 }
888
889 ringDesc, ok := desc.(*Desc)
890 if !ok || ringDesc == nil {
891 lastError = fmt.Errorf("no ring returned from the KV store")
892 continue
893 }
894 lastError = i.tokenGenerator.CanJoin(ringDesc.GetIngesters())
895 if lastError == nil {
896 level.Info(i.logger).Log("msg", "it is now possible to join the ring", "ring", i.RingName, "id", i.cfg.ID, "retries", retries.NumRetries())
897 return nil
898 }
899 }
900
901 if lastError == nil {
902 lastError = retries.Err()
903 }
904 level.Warn(i.logger).Log("msg", "there was a problem while checking whether this instance could join the ring - will continue anyway", "ring", i.RingName, "id", i.cfg.ID, "err", lastError)
905
906 // Return error only in case the parent context has been cancelled.
907 // In all other cases, we just want to swallow the error and move on.
908 return ctx.Err()
909}
910
911// autoJoin selects random tokens & moves state to targetState
912func (i *Lifecycler) autoJoin(ctx context.Context, targetState InstanceState) error {

Callers 2

autoJoinMethod · 0.95
TestWaitBeforeJoiningFunction · 0.95

Calls 12

NewFunction · 0.92
OngoingMethod · 0.80
ErrorfMethod · 0.80
GetIngestersMethod · 0.80
NumRetriesMethod · 0.80
CanJoinEnabledMethod · 0.65
GetMethod · 0.65
WrapMethod · 0.65
CanJoinMethod · 0.65
LogMethod · 0.45
WaitMethod · 0.45
ErrMethod · 0.45

Tested by 1

TestWaitBeforeJoiningFunction · 0.76