Skip to content

Commit

Permalink
Merge pull request #543 from akutz/feature/mount-retry
Browse files Browse the repository at this point in the history
Integration driver mount retry logic
  • Loading branch information
akutz authored May 3, 2017
2 parents 1937a13 + a406c09 commit c3b1dc1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
33 changes: 28 additions & 5 deletions api/registry/registry_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package registry

import (
"sync"
"time"

log "github.com/Sirupsen/logrus"
gofig "github.com/akutz/gofig/types"
Expand All @@ -14,9 +15,11 @@ import (
type idm struct {
types.IntegrationDriver
sync.RWMutex
ctx types.Context
config gofig.Config
used map[string]int
ctx types.Context
config gofig.Config
used map[string]int
retryCount int
retryWait time.Duration
}

// NewIntegrationDriverManager returns a new integration driver manager.
Expand All @@ -37,6 +40,14 @@ func (d *idm) Init(ctx types.Context, config gofig.Config) error {
d.ctx = ctx
d.config = config
d.used = map[string]int{}
d.retryCount = config.GetInt(types.ConfigIgVolOpsMountRetryCount)
if v := config.GetString(types.ConfigIgVolOpsMountRetryWait); v != "" {
var err error
d.retryWait, err = time.ParseDuration(v)
if err != nil {
return err
}
}

d.initPathCache(ctx)

Expand Down Expand Up @@ -143,10 +154,22 @@ func (d *idm) Mount(
"opts": opts}
ctx.WithFields(fields).Debug("mounting volume")

ctx = ctx.Join(d.ctx)

mp, vol, err := d.IntegrationDriver.Mount(
ctx.Join(d.ctx), volumeID, volumeName, opts)
ctx, volumeID, volumeName, opts)
if err != nil {
return "", nil, err
for x := 0; x < d.retryCount; x++ {
time.Sleep(d.retryWait)
mp, vol, err = d.IntegrationDriver.Mount(
ctx, volumeID, volumeName, opts)
if err == nil {
break
}
}
if err != nil {
return "", nil, err
}
}

// if the volume has attachments assign the new mount point to the
Expand Down
6 changes: 6 additions & 0 deletions api/types/types_config_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const (
//ConfigIgVolOpsMountRootPath is a config key.
ConfigIgVolOpsMountRootPath = ConfigIgVolOpsMount + ".rootPath"

//ConfigIgVolOpsMountRetryCount is a config key.
ConfigIgVolOpsMountRetryCount = ConfigIgVolOpsMount + ".retryCount"

//ConfigIgVolOpsMountRetryWait is a config key.
ConfigIgVolOpsMountRetryWait = ConfigIgVolOpsMount + ".retryWait"

//ConfigIgVolOpsUnmount is a config key.
ConfigIgVolOpsUnmount = ConfigIgVolOps + ".unmount"

Expand Down
2 changes: 2 additions & 0 deletions imports/config/imports_config_99_gofig.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func init() {

rk(gofig.Bool, false, "", types.ConfigExecutorNoDownload)
rk(gofig.Bool, false, "", types.ConfigIgVolOpsMountPreempt)
rk(gofig.Int, 0, "", types.ConfigIgVolOpsMountRetryCount)
rk(gofig.String, "5s", "", types.ConfigIgVolOpsMountRetryWait)
rk(gofig.Bool, false, "", types.ConfigIgVolOpsCreateDisable)
rk(gofig.Bool, false, "", types.ConfigIgVolOpsRemoveDisable)
rk(gofig.Bool, false, "", types.ConfigIgVolOpsUnmountIgnoreUsed)
Expand Down

0 comments on commit c3b1dc1

Please sign in to comment.