Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 020a7f7

Browse files
committed
Using exponential backoff instead of linear
1 parent c951ada commit 020a7f7

2 files changed

Lines changed: 38 additions & 29 deletions

File tree

pkg/volume/cinder/attacher.go

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ var _ volume.Attacher = &cinderDiskAttacher{}
4444
var _ volume.AttachableVolumePlugin = &cinderPlugin{}
4545

4646
const (
47-
checkSleepDuration = 5 * time.Second
47+
probeVolumeInitDealy = 1 * time.Second
48+
probeVolumeFactor = 2.0
49+
probeVolumeSteps = 10
4850
operationFinishInitDealy = 1 * time.Second
4951
operationFinishFactor = 1.1
5052
operationFinishSteps = 10
@@ -221,6 +223,38 @@ func (attacher *cinderDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nod
221223
return volumesAttachedCheck, nil
222224
}
223225

226+
func (attacher *cinderDiskAttacher) waitProbeVolume(devicePath, volumeID string) (string, error) {
227+
backoff := wait.Backoff{
228+
Duration: probeVolumeInitDealy,
229+
Factor: probeVolumeFactor,
230+
Steps: probeVolumeSteps,
231+
}
232+
233+
err := wait.ExponentialBackoff(backoff, func() (string, error) {
234+
glog.V(5).Infof("Checking Cinder disk %q is attached.", volumeID)
235+
probeAttachedVolume()
236+
if !attacher.cinderProvider.ShouldTrustDevicePath() {
237+
// Using the Cinder volume ID, find the real device path (See Issue #33128)
238+
devicePath = attacher.cinderProvider.GetDevicePath(volumeID)
239+
}
240+
exists, err := volumeutil.PathExists(devicePath)
241+
if exists && err == nil {
242+
glog.Infof("Successfully found attached Cinder disk %q at %v.", volumeID, devicePath)
243+
return devicePath, nil
244+
}
245+
else {
246+
// Log an error, and continue checking periodically
247+
glog.Errorf("Error: could not find attached Cinder disk %q (path: %q): %v", volumeID, devicePath, err)
248+
}
249+
})
250+
251+
if err == wait.ErrWaitTimeout {
252+
err = fmt.Errorf("Volume %q failed to be probed within the alloted time", volumeID)
253+
}
254+
255+
return "", err
256+
}
257+
224258
func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string, _ *v1.Pod, timeout time.Duration) (string, error) {
225259
// NOTE: devicePath is is path as reported by Cinder, which may be incorrect and should not be used. See Issue #33128
226260
volumeSource, _, err := getVolumeSource(spec)
@@ -234,32 +268,8 @@ func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath
234268
return "", fmt.Errorf("WaitForAttach failed for Cinder disk %q: devicePath is empty.", volumeID)
235269
}
236270

237-
ticker := time.NewTicker(checkSleepDuration)
238-
defer ticker.Stop()
239-
timer := time.NewTimer(timeout)
240-
defer timer.Stop()
241-
242-
for {
243-
select {
244-
case <-ticker.C:
245-
glog.V(5).Infof("Checking Cinder disk %q is attached.", volumeID)
246-
probeAttachedVolume()
247-
if !attacher.cinderProvider.ShouldTrustDevicePath() {
248-
// Using the Cinder volume ID, find the real device path (See Issue #33128)
249-
devicePath = attacher.cinderProvider.GetDevicePath(volumeID)
250-
}
251-
exists, err := volumeutil.PathExists(devicePath)
252-
if exists && err == nil {
253-
glog.Infof("Successfully found attached Cinder disk %q at %v.", volumeID, devicePath)
254-
return devicePath, nil
255-
} else {
256-
// Log an error, and continue checking periodically
257-
glog.Errorf("Error: could not find attached Cinder disk %q (path: %q): %v", volumeID, devicePath, err)
258-
}
259-
case <-timer.C:
260-
return "", fmt.Errorf("Could not find attached Cinder disk %q. Timeout waiting for mount paths to be created.", volumeID)
261-
}
262-
}
271+
// Using exponential backoff instead of linear
272+
return attacher.waitProbeVolume(devicePath, volumeID)
263273
}
264274

265275
func (attacher *cinderDiskAttacher) GetDeviceMountPath(

pkg/volume/cinder/cinder_util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,11 @@ func probeAttachedVolume() error {
228228
// udevadm settle waits for udevd to process the device creation
229229
// events for all hardware devices, thus ensuring that any device
230230
// nodes have been created successfully before proceeding.
231-
argsSettle := []string{"settle", "--timeout=1"}
231+
argsSettle := []string{"settle"}
232232
cmdSettle := executor.Command("udevadm", argsSettle...)
233233
_, errSettle := cmdSettle.CombinedOutput()
234234
if errSettle != nil {
235235
glog.Errorf("error running udevadm settle %v\n", errSettle)
236-
return errSettle
237236
}
238237

239238
args := []string{"trigger"}

0 commit comments

Comments
 (0)