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

Function numberOfKeysOwnedByInstance

ring/token_range_test.go:271–292  ·  view source on GitHub ↗

numberOfKeysOwnedByInstance returns how many of the supplied keys are owned by given instance.

(r *Ring, keys []uint32, op Operation, instanceID string, bufDescs []InstanceDesc, bufHosts, bufZones []string)

Source from the content-addressed store, hash-verified

269
270// numberOfKeysOwnedByInstance returns how many of the supplied keys are owned by given instance.
271func numberOfKeysOwnedByInstance(r *Ring, keys []uint32, op Operation, instanceID string, bufDescs []InstanceDesc, bufHosts, bufZones []string) (int, error) {
272 owned := 0
273 if !r.HasInstance(instanceID) {
274 return 0, nil
275 }
276
277 for _, tok := range keys {
278 s, err := r.Get(tok, op, bufDescs, bufHosts, bufZones)
279 if err != nil {
280 return 0, err
281 }
282
283 for _, inst := range s.Instances {
284 if inst.Id == instanceID {
285 owned++
286 break
287 }
288 }
289 }
290
291 return owned, nil
292}
293
294type nopReplicationStrategy struct{}
295

Callers 1

Calls 2

HasInstanceMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected