Skip to content

Commit

Permalink
feat: support custom timeout for blot open
Browse files Browse the repository at this point in the history
Signed-off-by: haoyun <yun.hao@daocloud.io>
  • Loading branch information
jonyhy96 committed Dec 13, 2021
1 parent 7020719 commit dd26d3d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ import (
"google.golang.org/grpc/credentials"
)

const (
boltOpenTimeout = "io.containerd.timeout.bolt.open"
)

func init() {
timeout.Set(boltOpenTimeout, 0) // set to 0 means to wait indefinitely for bolt.Open
}

// CreateTopLevelDirectories creates the top-level root and state directories.
func CreateTopLevelDirectories(config *srvconfig.Config) error {
switch {
Expand Down Expand Up @@ -418,8 +426,21 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis

path := filepath.Join(ic.Root, "meta.db")
ic.Meta.Exports["path"] = path

db, err := bolt.Open(path, 0644, nil)
options := *bolt.DefaultOptions
options.Timeout = timeout.Get(boltOpenTimeout)
doneCh := make(chan struct{})
go func() {
t := time.NewTimer(10 * time.Second)
defer t.Stop()
select {
case <-t.C:
log.G(ctx).WithField("plugin", "bolt").Warn("waiting for response from boltdb open")
case <-doneCh:
return
}
}()
db, err := bolt.Open(path, 0644, &options)
close(doneCh)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit dd26d3d

Please sign in to comment.