Skip to content

Commit

Permalink
handle keyspace with trailing-slash, no shards
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Dec 12, 2024
1 parent ddf7514 commit 2bec10c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion go/vt/vtorc/logic/tablet_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ 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)
continue
}
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()
Expand Down
17 changes: 11 additions & 6 deletions go/vt/vtorc/logic/tablet_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-"},
Expand All @@ -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 {
Expand Down

0 comments on commit 2bec10c

Please sign in to comment.