Skip to content

Commit 448291c

Browse files
fix hang
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
1 parent 77c28ce commit 448291c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

go/vt/vtorc/logic/tablet_discovery.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ func hasShardInKeyRanges(shard string, keyRanges []*topodatapb.KeyRange) (bool,
9999
// getKeyspaceShardsToWatch converts the input clustersToWatch into a list of individual keyspace/shards.
100100
func getKeyspaceShardsToWatch() ([]*topo.KeyspaceShard, error) {
101101
var keyspaceShards []*topo.KeyspaceShard
102-
keyspaceWatchKeyRanges := make(map[string][]*topodatapb.KeyRange)
102+
keyspaceWatchKeyRanges := make(map[string][]*topodatapb.KeyRange, 0)
103103
for _, clusterToWatch := range clustersToWatch {
104104
var err error
105-
var keyRange *topodatapb.KeyRange
105+
keyRange := &topodatapb.KeyRange{}
106106
keyspace := clusterToWatch
107107
if strings.Contains(clusterToWatch, "/") {
108108
var shard string
@@ -143,11 +143,11 @@ func getKeyspaceShardsToWatch() ([]*topo.KeyspaceShard, error) {
143143
log.Errorf("Failed to parse key ranges for shard %q: %+v", s, err)
144144
} else if found {
145145
keyspaceShardsMu.Lock()
146-
defer keyspaceShardsMu.Unlock()
147146
keyspaceShards = append(keyspaceShards, &topo.KeyspaceShard{
148147
Keyspace: keyspace,
149148
Shard: s,
150149
})
150+
keyspaceShardsMu.Unlock()
151151
}
152152
}
153153
return nil
@@ -157,10 +157,6 @@ func getKeyspaceShardsToWatch() ([]*topo.KeyspaceShard, error) {
157157
return nil, err
158158
}
159159

160-
slices.SortStableFunc(keyspaceShards, func(a, b *topo.KeyspaceShard) int {
161-
return strings.Compare(a.String(), b.String())
162-
})
163-
164160
return keyspaceShards, nil
165161
}
166162

go/vt/vtorc/logic/tablet_discovery_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package logic
1919
import (
2020
"context"
2121
"fmt"
22+
"slices"
23+
"strings"
2224
"sync/atomic"
2325
"testing"
2426
"time"
@@ -396,6 +398,13 @@ func TestGetKeyspaceShardsToWatch(t *testing.T) {
396398
clustersToWatch = testcase.clusters
397399
res, err := getKeyspaceShardsToWatch()
398400

401+
slices.SortStableFunc(res, func(a, b *topo.KeyspaceShard) int {
402+
return strings.Compare(a.String(), b.String())
403+
})
404+
slices.SortStableFunc(testcase.expected, func(a, b *topo.KeyspaceShard) int {
405+
return strings.Compare(a.String(), b.String())
406+
})
407+
399408
assert.NoError(t, err)
400409
assert.ElementsMatch(t, testcase.expected, res)
401410
})

0 commit comments

Comments
 (0)