Skip to content

Commit

Permalink
improves scheduler & compactor ringwatcher checks (#4607)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored Nov 1, 2021
1 parent 0c9bead commit 84220c4
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions pkg/util/ring_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,16 @@ func (w *ringWatcher) lookupAddresses() {
}

func (w *ringWatcher) getAddresses() ([]string, error) {
var addrs []string

// If there are less than 2 existing addresses, odds are we are running just a single instance
// so just get the first healthy address and use it. If the call returns to continue on to
// check for the actual replicaset instances
if len(w.addresses) < 2 {
rs, err := w.ring.GetAllHealthy(ring.WriteNoExtend)
if err != nil {
return nil, err
}
addrs = rs.GetAddresses()
if len(addrs) == 1 {
return addrs, nil
}
}

// We use ring.Write combined with the `ring.NewIgnoreUnhealthyInstancesReplicationStrategy`
// during ring creation to fetch at least 1 and ideally $REPLICATION_FACTOR nodes from the ring.
// If the ideal nodes for the desired token position are unhealthy, ring.Write ensures
// we continue to traverse the ring looking for more, until we've acquired $REPLICATION_FACTOR
// nodes or the ring is exhausted.
op := ring.Write

bufDescs, bufHosts, bufZones := ring.MakeBuffersForGet()
rs, err := w.ring.Get(RingKeyOfLeader, ring.WriteNoExtend, bufDescs, bufHosts, bufZones)
rs, err := w.ring.Get(RingKeyOfLeader, op, bufDescs, bufHosts, bufZones)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 84220c4

Please sign in to comment.