clientV3: fix behavior of WithPrefix and WithFromKey functions

The use of WithPrefix() and WithFromKey() together is not supported. The
client doesn't respect this behavior currently.

Fixes #10431
This commit is contained in:
Sahdev P. Zala
2019-02-26 16:45:47 -05:00
parent 784daa0498
commit 8782bbae65
2 changed files with 32 additions and 0 deletions

View File

@ -16,6 +16,9 @@ package clientv3
import (
"math/rand"
"reflect"
"runtime"
"strings"
"time"
)
@ -29,3 +32,18 @@ func jitterUp(duration time.Duration, jitter float64) time.Duration {
multiplier := jitter * (rand.Float64()*2 - 1)
return time.Duration(float64(duration) * (1 + multiplier))
}
// Check if the provided function is being called in the op options.
func isOpFuncCalled(op string, opts []OpOption) bool {
for _, opt := range opts {
v := reflect.ValueOf(opt)
if v.Kind() == reflect.Func {
if opFunc := runtime.FuncForPC(v.Pointer()); opFunc != nil {
if strings.Contains(opFunc.Name(), op) {
return true
}
}
}
}
return false
}