MCPcopy Create free account
hub / github.com/cortexproject/cortex / FindDifference

Method FindDifference

pkg/ring/model.go:732–804  ·  view source on GitHub ↗
(o codec.MultiKey)

Source from the content-addressed store, hash-verified

730}
731
732func (d *Desc) FindDifference(o codec.MultiKey) (any, []string, error) {
733 out, ok := o.(*Desc)
734 if !ok {
735 // This method only deals with non-nil rings.
736 return nil, nil, fmt.Errorf("expected *ring.Desc, got %T", out)
737 }
738
739 toUpdated := NewDesc()
740 toDelete := make([]string, 0)
741 tokensChanged := false
742
743 // If both are null
744 if d == nil && out == nil {
745 return toUpdated, toDelete, nil
746 }
747
748 // If new data is empty
749 if out == nil {
750 for k := range d.Ingesters {
751 toDelete = append(toDelete, k)
752 }
753 return toUpdated, toDelete, nil
754 }
755
756 //If existent data is empty
757 if d == nil {
758 maps.Copy(toUpdated.Ingesters, out.Ingesters)
759 return toUpdated, toDelete, nil
760 }
761
762 //If new added
763 for name, oing := range out.Ingesters {
764 if _, ok := d.Ingesters[name]; !ok {
765 tokensChanged = true
766 toUpdated.Ingesters[name] = oing
767 }
768 }
769
770 // If removed or updated
771 for name, ing := range d.Ingesters {
772 oing, ok := out.Ingesters[name]
773 if !ok {
774 toDelete = append(toDelete, name)
775 } else if !ing.Equal(oing) {
776 if oing.Timestamp > ing.Timestamp {
777 toUpdated.Ingesters[name] = oing
778 if !tokensEqual(ing.Tokens, oing.Tokens) {
779 tokensChanged = true
780 }
781 } else if oing.Timestamp == ing.Timestamp && ing.State != LEFT && oing.State == LEFT {
782 // we accept LEFT even if timestamp hasn't changed
783 toUpdated.Ingesters[name] = oing
784 if !tokensEqual(ing.Tokens, oing.Tokens) {
785 tokensChanged = true
786 }
787 }
788 }
789 }

Callers

nothing calls this directly

Calls 6

NewDescFunction · 0.85
tokensEqualFunction · 0.85
conflictingTokensExistFunction · 0.85
resolveConflictsFunction · 0.85
EqualMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected