Skip to content

Commit

Permalink
fix hang
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Jan 16, 2025
1 parent 77c28ce commit 448291c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 3 additions & 7 deletions go/vt/vtorc/logic/tablet_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func hasShardInKeyRanges(shard string, keyRanges []*topodatapb.KeyRange) (bool,
// getKeyspaceShardsToWatch converts the input clustersToWatch into a list of individual keyspace/shards.
func getKeyspaceShardsToWatch() ([]*topo.KeyspaceShard, error) {
var keyspaceShards []*topo.KeyspaceShard
keyspaceWatchKeyRanges := make(map[string][]*topodatapb.KeyRange)
keyspaceWatchKeyRanges := make(map[string][]*topodatapb.KeyRange, 0)
for _, clusterToWatch := range clustersToWatch {
var err error
var keyRange *topodatapb.KeyRange
keyRange := &topodatapb.KeyRange{}
keyspace := clusterToWatch
if strings.Contains(clusterToWatch, "/") {
var shard string
Expand Down Expand Up @@ -143,11 +143,11 @@ func getKeyspaceShardsToWatch() ([]*topo.KeyspaceShard, error) {
log.Errorf("Failed to parse key ranges for shard %q: %+v", s, err)
} else if found {
keyspaceShardsMu.Lock()
defer keyspaceShardsMu.Unlock()
keyspaceShards = append(keyspaceShards, &topo.KeyspaceShard{
Keyspace: keyspace,
Shard: s,
})
keyspaceShardsMu.Unlock()
}
}
return nil
Expand All @@ -157,10 +157,6 @@ func getKeyspaceShardsToWatch() ([]*topo.KeyspaceShard, error) {
return nil, err
}

slices.SortStableFunc(keyspaceShards, func(a, b *topo.KeyspaceShard) int {
return strings.Compare(a.String(), b.String())
})

return keyspaceShards, nil
}

Expand Down
9 changes: 9 additions & 0 deletions go/vt/vtorc/logic/tablet_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package logic
import (
"context"
"fmt"
"slices"
"strings"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -396,6 +398,13 @@ func TestGetKeyspaceShardsToWatch(t *testing.T) {
clustersToWatch = testcase.clusters
res, err := getKeyspaceShardsToWatch()

slices.SortStableFunc(res, func(a, b *topo.KeyspaceShard) int {
return strings.Compare(a.String(), b.String())
})
slices.SortStableFunc(testcase.expected, func(a, b *topo.KeyspaceShard) int {
return strings.Compare(a.String(), b.String())
})

assert.NoError(t, err)
assert.ElementsMatch(t, testcase.expected, res)
})
Expand Down

0 comments on commit 448291c

Please sign in to comment.