@@ -40,27 +40,34 @@ func (s *syncClient) syncDfs(ctx context.Context, resolvedResources chan<- *sche
40
40
s .metrics .initWithClients (table , clients )
41
41
}
42
42
43
- var wg sync. WaitGroup
43
+ tableClients := make ([] tableClient , 0 )
44
44
for i , table := range s .tables {
45
- table := table
46
- clients := preInitialisedClients [i ]
47
- for _ , client := range clients {
48
- client := client
49
- if err := s .scheduler .tableSems [0 ].Acquire (ctx , 1 ); err != nil {
50
- // This means context was cancelled
51
- wg .Wait ()
52
- return
53
- }
54
- wg .Add (1 )
55
- go func () {
56
- defer wg .Done ()
57
- defer s .scheduler .tableSems [0 ].Release (1 )
58
- // not checking for error here as nothing much todo.
59
- // the error is logged and this happens when context is cancelled
60
- s .resolveTableDfs (ctx , table , client , nil , resolvedResources , 1 )
61
- }()
45
+ for _ , client := range preInitialisedClients [i ] {
46
+ tableClients = append (tableClients , tableClient {table : table , client : client })
62
47
}
63
48
}
49
+ tableClients = shardTableClients (tableClients , s .shard )
50
+
51
+ var wg sync.WaitGroup
52
+ for _ , tc := range tableClients {
53
+ table := tc .table
54
+ cl := tc .client
55
+ if err := s .scheduler .tableSems [0 ].Acquire (ctx , 1 ); err != nil {
56
+ // This means context was cancelled
57
+ wg .Wait ()
58
+ return
59
+ }
60
+ wg .Add (1 )
61
+ go func () {
62
+ defer wg .Done ()
63
+ defer s .scheduler .tableSems [0 ].Release (1 )
64
+ // not checking for error here as nothing much to do.
65
+ // the error is logged and this happens when context is cancelled
66
+ // Round Robin currently uses the DFS algorithm to resolve the tables, but this
67
+ // may change in the future.
68
+ s .resolveTableDfs (ctx , table , cl , nil , resolvedResources , 1 )
69
+ }()
70
+ }
64
71
65
72
// Wait for all the worker goroutines to finish
66
73
wg .Wait ()
0 commit comments