diff --git a/go/vt/vtorc/logic/tablet_discovery.go b/go/vt/vtorc/logic/tablet_discovery.go index c56836f089d..08b3b9cc7a2 100644 --- a/go/vt/vtorc/logic/tablet_discovery.go +++ b/go/vt/vtorc/logic/tablet_discovery.go @@ -59,7 +59,7 @@ var ( // time because the list never changes. func parseClustersToWatch() { for _, ks := range clustersToWatch { - if strings.Contains(ks, "/") { + if strings.Contains(ks, "/") && !strings.HasSuffix(ks, "/") { // Validate keyspace/shard parses. if _, _, err := topoproto.ParseKeyspaceShard(ks); err != nil { log.Errorf("Could not parse keyspace/shard %q: %+v", ks, err) @@ -67,6 +67,11 @@ func parseClustersToWatch() { } shardsToWatch[ks] = true } else { + // Remove trailing slash, if exists + if strings.HasSuffix(ks, "/") { + ks = strings.TrimSuffix(ks, "/") + } + // Assume this is a keyspace and find all shards in keyspace. ctx, cancel := context.WithTimeout(context.Background(), topo.RemoteOperationTimeout) defer cancel() diff --git a/go/vt/vtorc/logic/tablet_discovery_test.go b/go/vt/vtorc/logic/tablet_discovery_test.go index ac7bc26bf86..a03f69906a4 100644 --- a/go/vt/vtorc/logic/tablet_discovery_test.go +++ b/go/vt/vtorc/logic/tablet_discovery_test.go @@ -132,12 +132,10 @@ func TestParseClustersToWatch(t *testing.T) { expected: map[string]bool{}, }, { - in: []string{"test/"}, - expected: map[string]bool{"test/": true}, - }, - { - in: []string{"test/-"}, - expected: map[string]bool{"test/-": true}, + in: []string{"test/-"}, + expected: map[string]bool{ + "test/-": true, + }, }, { in: []string{"test/-", "test2/-80", "test2/80-"}, @@ -154,6 +152,13 @@ func TestParseClustersToWatch(t *testing.T) { topoproto.KeyspaceShardString(keyspace, shard): true, }, }, + { + // confirm shards fetch from topo when keyspace has trailing-slash + in: []string{keyspace + "/"}, + expected: map[string]bool{ + topoproto.KeyspaceShardString(keyspace, shard): true, + }, + }, } for _, testCase := range testCases {