Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions go/vt/vtorc/logic/keyspace_shard_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ package logic

import (
"context"
"sync"

"golang.org/x/exp/maps"
"golang.org/x/sync/errgroup"

"vitess.io/vitess/go/vt/log"

"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/vtorc/inst"
)
Expand All @@ -47,27 +46,25 @@ func RefreshAllKeyspacesAndShards(ctx context.Context) error {

refreshCtx, refreshCancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
defer refreshCancel()
var wg sync.WaitGroup

eg, _ := errgroup.WithContext(ctx)
for idx, keyspace := range keyspaces {
// Check if the current keyspace name is the same as the last one.
// If it is, then we know we have already refreshed its information.
// We do not need to do it again.
if idx != 0 && keyspace == keyspaces[idx-1] {
continue
}
wg.Add(2)
go func(keyspace string) {
defer wg.Done()
_ = refreshKeyspaceHelper(refreshCtx, keyspace)
}(keyspace)
go func(keyspace string) {
defer wg.Done()
_ = refreshAllShards(refreshCtx, keyspace)
}(keyspace)
}
wg.Wait()

return nil
eg.Go(func() error {
return refreshKeyspaceHelper(refreshCtx, keyspace)
})

eg.Go(func() error {
return refreshAllShards(refreshCtx, keyspace)
})
}
return eg.Wait()
}

// RefreshKeyspaceAndShard refreshes the keyspace record and shard record for the given keyspace and shard.
Expand Down
Loading