|
|
@@ -203,15 +203,22 @@ func (t *tokenRing) GetHostForToken(token token) *HostInfo {
|
|
|
if t == nil {
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ l := len(t.tokens)
|
|
|
+ // no host tokens, no available hosts
|
|
|
+ if l == 0{
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
// find the primary replica
|
|
|
ringIndex := sort.Search(
|
|
|
- len(t.tokens),
|
|
|
+ l,
|
|
|
func(i int) bool {
|
|
|
return !t.tokens[i].Less(token)
|
|
|
},
|
|
|
)
|
|
|
- if ringIndex == len(t.tokens) {
|
|
|
+
|
|
|
+ if ringIndex == l {
|
|
|
// wrap around to the first in the ring
|
|
|
ringIndex = 0
|
|
|
}
|