Merge pull request #5071 from AkihiroSuda/restart-parallel

restart: parallelize reconcile()
This commit is contained in:
Michael Crosby 2021-02-25 11:33:26 -05:00 committed by GitHub
commit 119fe70469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ package monitor
import ( import (
"context" "context"
"fmt" "fmt"
"sync"
"time" "time"
"github.com/containerd/containerd" "github.com/containerd/containerd"
@ -164,19 +165,33 @@ func (m *monitor) reconcile(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
var wgNSLoop sync.WaitGroup
for _, name := range ns { for _, name := range ns {
ctx = namespaces.WithNamespace(ctx, name) name := name
changes, err := m.monitor(ctx) wgNSLoop.Add(1)
if err != nil { go func() {
logrus.WithError(err).Error("monitor for changes") defer wgNSLoop.Done()
continue ctx := namespaces.WithNamespace(ctx, name)
} changes, err := m.monitor(ctx)
for _, c := range changes { if err != nil {
if err := c.apply(ctx, m.client); err != nil { logrus.WithError(err).Error("monitor for changes")
logrus.WithError(err).Error("apply change") return
} }
} var wgChangesLoop sync.WaitGroup
for _, c := range changes {
c := c
wgChangesLoop.Add(1)
go func() {
defer wgChangesLoop.Done()
if err := c.apply(ctx, m.client); err != nil {
logrus.WithError(err).Error("apply change")
}
}()
}
wgChangesLoop.Wait()
}()
} }
wgNSLoop.Wait()
return nil return nil
} }