Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and cleanup treatment of keyspace IDs and KeyRange #140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions go/test/endtoend/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ limitations under the License.
package sequence

import (
"bytes"
"encoding/binary"
"encoding/json"
"flag"
"os"
"strings"
"testing"

"vitess.io/vitess/go/vt/key"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -392,8 +393,8 @@ func TestKeyspaceToShardName(t *testing.T) {
shardKIDs := shardKIdMap[shardRef.Name]
for _, kid := range shardKIDs {
id = packKeyspaceID(kid)
assert.True(t, bytes.Compare(shardRef.KeyRange.Start, id) <= 0 &&
(len(shardRef.KeyRange.End) == 0 || bytes.Compare(id, shardRef.KeyRange.End) < 0))
assert.True(t, key.Compare(shardRef.KeyRange.Start, id) <= 0 &&
(key.Empty(shardRef.KeyRange.End) || key.Compare(id, shardRef.KeyRange.End) < 0))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/discovery/topology_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (fbs *FilterByShard) IsIncluded(tablet *topodata.Tablet) bool {
// Exact match (probably a non-sharded keyspace).
return true
}
if kr != nil && c.keyRange != nil && key.KeyRangeIncludes(c.keyRange, kr) {
if kr != nil && c.keyRange != nil && key.KeyRangeContainsKeyRange(c.keyRange, kr) {
// Our filter's KeyRange includes the provided KeyRange
return true
}
Expand Down
6 changes: 3 additions & 3 deletions go/vt/key/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d DestinationExactKeyRange) String() string {

func processExactKeyRange(allShards []*topodatapb.ShardReference, kr *topodatapb.KeyRange, addShard func(shard string) error) error {
sort.SliceStable(allShards, func(i, j int) bool {
return KeyRangeStartSmaller(allShards[i].GetKeyRange(), allShards[j].GetKeyRange())
return KeyRangeLess(allShards[i].GetKeyRange(), allShards[j].GetKeyRange())
})

shardnum := 0
Expand All @@ -139,7 +139,7 @@ func processExactKeyRange(allShards []*topodatapb.ShardReference, kr *topodatapb
shardnum++
}
for shardnum < len(allShards) {
if !KeyRangesIntersect(kr, allShards[shardnum].KeyRange) {
if !KeyRangeIntersect(kr, allShards[shardnum].KeyRange) {
// If we are over the requested keyrange, we
// can stop now, we won't find more.
break
Expand Down Expand Up @@ -215,7 +215,7 @@ func (d DestinationKeyRange) String() string {

func processKeyRange(allShards []*topodatapb.ShardReference, kr *topodatapb.KeyRange, addShard func(shard string) error) error {
for _, shard := range allShards {
if !KeyRangesIntersect(kr, shard.KeyRange) {
if !KeyRangeIntersect(kr, shard.KeyRange) {
// We don't need that shard.
continue
}
Expand Down
Loading
Loading