Skip to content

Commit

Permalink
re-use KeyRange from shard object
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Feb 24, 2025
1 parent 469cf00 commit 8588aec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
17 changes: 3 additions & 14 deletions go/vt/vtorc/logic/keyspace_shard_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,9 @@ func shouldWatchShard(shard *topo.ShardInfo) bool {
return false
}

shardRanges, err := key.ParseShardingSpec(shard.ShardName())
if err != nil {
// This parse should never fail because we get the shard names
// from the topo using ts.FindAllShardsInKeyspace().
log.Error(err)
return false
}

for _, keyRange := range watchRanges {
for _, shardRange := range shardRanges {
if key.KeyRangeContainsKeyRange(keyRange, shardRange) {
return true
}
if key.KeyRangeContainsKeyRange(keyRange, shard.GetKeyRange()) {
return true
}
}
return false
Expand Down Expand Up @@ -204,8 +194,7 @@ func refreshAllShards(ctx context.Context, keyspaceName string) error {
}
shardName := topoproto.KeyspaceShardString(keyspaceName, shard)
log.Infof("Forgetting shard: %s", shardName)
err = inst.DeleteShard(keyspaceName, shard)
if err != nil {
if err = inst.DeleteShard(keyspaceName, shard); err != nil {
log.Errorf("Failed to delete shard %s: %+v", shardName, err)
return err
}
Expand Down
9 changes: 3 additions & 6 deletions go/vt/vtorc/logic/keyspace_shard_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,13 @@ func TestRefreshAllShards(t *testing.T) {
ctx := context.Background()
ts = memorytopo.NewServer(ctx, "zone1")
require.NoError(t, initializeShardsToWatch())
require.NoError(t, ts.CreateKeyspace(ctx, "ks1", &topodatapb.Keyspace{
KeyspaceType: topodatapb.KeyspaceType_NORMAL,
DurabilityPolicy: policy.DurabilityNone,
}))

// test shard refresh
require.NoError(t, ts.CreateKeyspace(ctx, "ks1", keyspaceDurabilityNone))
shards := []string{"-40", "40-80", "80-c0", "c0-"}
for _, shard := range shards {
require.NoError(t, ts.CreateShard(ctx, "ks1", shard))
}

// test shard refresh
require.NoError(t, refreshAllShards(ctx, "ks1"))
shardNames, err := inst.ReadShardNames("ks1")
require.NoError(t, err)
Expand Down

0 comments on commit 8588aec

Please sign in to comment.