Skip to content

Commit

Permalink
scylla: ensure we use the correct token to determine shard
Browse files Browse the repository at this point in the history
The driver silently replaced the current token with the closest one
from the token ring that it could find. This worked well enough
to route the request to the correct host but to pick the right shard
we need the actual token for the qiven query.
  • Loading branch information
Henrik Johansson committed Mar 26, 2019
1 parent f1af639 commit 1ad3b47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ func (t *tokenRing) String() string {
return string(buf.Bytes())
}

func (t *tokenRing) GetHostForPartitionKey(partitionKey []byte) (host *HostInfo, endToken token) {
func (t *tokenRing) GetHostForPartitionKey(partitionKey []byte) (host *HostInfo, token token) {
if t == nil {
return nil, nil
}

return t.GetHostForToken(t.partitioner.Hash(partitionKey))
token = t.partitioner.Hash(partitionKey)
host, _ = t.GetHostForToken(token)
return host, token
}

func (t *tokenRing) GetHostForToken(token token) (host *HostInfo, endToken token) {
Expand Down
2 changes: 1 addition & 1 deletion token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestTokenRing_Nil(t *testing.T) {
if host, endToken := ring.GetHostForToken(nil); host != nil || endToken != nil {
t.Error("Expected nil for nil token ring")
}
if host, endToken := ring.GetHostForPartitionKey(nil); host != nil || endToken != nil {
if host, token := ring.GetHostForPartitionKey(nil); host != nil || token != nil {
t.Error("Expected nil for nil token ring")
}
}
Expand Down

0 comments on commit 1ad3b47

Please sign in to comment.