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

Method matchingKeys

kv/etcd/mock.go:348–374  ·  view source on GitHub ↗

matchingKeys returns the keys of elements that match the given Op

(op clientv3.Op, kvps map[string]mvccpb.KeyValue)

Source from the content-addressed store, hash-verified

346
347// matchingKeys returns the keys of elements that match the given Op
348func (m *mockKV) matchingKeys(op clientv3.Op, kvps map[string]mvccpb.KeyValue) []string {
349 // NOTE that even when Op is a prefix match, the key bytes will be the same
350 // as they would be for an exact match. We use the fact that RangeBytes will
351 // be non-nil for prefix matches to understand how to select keys.
352 keyBytes := op.KeyBytes()
353 rangeBytes := op.RangeBytes()
354 keys := make([]string, 0)
355
356 if keyBytes != nil && rangeBytes == nil {
357 // Exact match
358 k := string(keyBytes)
359
360 if _, ok := kvps[k]; ok {
361 keys = append(keys, k)
362 }
363 } else if keyBytes != nil {
364 // Prefix match
365 emptyPrefix := len(keyBytes) == 1 && keyBytes[0] == byte(0)
366 for k := range kvps {
367 if emptyPrefix || bytes.HasPrefix([]byte(k), keyBytes) {
368 keys = append(keys, k)
369 }
370 }
371 }
372
373 return keys
374}
375
376// isMatch returns true if the provided key-value pair matches the given Op
377func (m *mockKV) isMatch(op clientv3.Op, kvp mvccpb.KeyValue) bool {

Callers 3

doGetMethod · 0.95
doDeleteMethod · 0.95
isMatchMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected