Use a cleaner worker pattern (#18422)

This commit is contained in:
Scott Miller 2022-12-16 11:35:24 -06:00 committed by GitHub
parent 51b1b6d446
commit 53e73ceba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 10 deletions

View File

@ -2398,25 +2398,22 @@ func (c *Core) postUnseal(ctx context.Context, ctxCancelFunc context.CancelFunc,
v()
}
} else {
workerChans := make([]chan func(), postUnsealFuncConcurrency)
jobs := make(chan func())
var wg sync.WaitGroup
for i := 0; i < postUnsealFuncConcurrency; i++ {
workerChans[i] = make(chan func())
go func(i int) {
for v := range workerChans[i] {
go func() {
for v := range jobs {
v()
wg.Done()
}
}(i)
}()
}
for i, v := range c.postUnsealFuncs {
for _, v := range c.postUnsealFuncs {
wg.Add(1)
workerChans[i%postUnsealFuncConcurrency] <- v
}
for i := 0; i < postUnsealFuncConcurrency; i++ {
close(workerChans[i])
jobs <- v
}
wg.Wait()
close(jobs)
}
if atomic.LoadUint32(c.sealMigrationDone) == 1 {