rbd: add minsnapshotsonimage flag

An rbd image can have a maximum number of
snapshots defined by maxsnapshotsonimage
On the limit is reached the cephcsi will
start flattening the older snapshots and
returns the ABORT error message, The Request
comes after this as to wait till all the
images are flattened (this will increase the
PVC creation time.  Instead of waiting till
the maximum snapshots on an RBD image, we can
have a soft limit, once the limit reached
cephcsi will start flattening the task to
break the chain. With this PVC  creation time
will only be affected when the hard limit
(minsnapshotsonimage) reached.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2020-11-17 09:04:29 +05:30
committed by mergify[bot]
parent 880b5bb427
commit 8d3a44d0c4
7 changed files with 44 additions and 8 deletions

View File

@ -342,10 +342,12 @@ func flattenParentImage(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent
return nil
}
// check snapshots on the rbd image, as we have limit from krbd that
// an image cannot have more than 510 snapshot at a given point of time.
// If the snapshots are more than the `maxSnapshotsOnImage` Add a task to
// flatten all the temporary cloned images.
// check snapshots on the rbd image, as we have limit from krbd that an image
// cannot have more than 510 snapshot at a given point of time. If the
// snapshots are more than the `maxSnapshotsOnImage` Add a task to flatten all
// the temporary cloned images and return ABORT error message. If the snapshots
// are more than the `minSnapshotOnImage` Add a task to flatten all the
// temporary cloned images.
func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
snaps, err := rbdVol.listSnapshots()
if err != nil {
@ -356,6 +358,7 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut
}
if len(snaps) > int(maxSnapshotsOnImage) {
util.DebugLog(ctx, "snapshots count %d on image: %s reached configured hard limit %d", len(snaps), rbdVol, maxSnapshotsOnImage)
err = flattenClonedRbdImages(
ctx,
snaps,
@ -368,6 +371,24 @@ func flattenTemporaryClonedImages(ctx context.Context, rbdVol *rbdVolume, cr *ut
}
return status.Errorf(codes.ResourceExhausted, "rbd image %s has %d snapshots", rbdVol, len(snaps))
}
if len(snaps) > int(minSnapshotsOnImageToStartFlatten) {
util.DebugLog(ctx, "snapshots count %d on image: %s reached configured soft limit %d", len(snaps), rbdVol, minSnapshotsOnImageToStartFlatten)
// If we start flattening all the snapshots at one shot the volume
// creation time will be affected,so we will flatten only the extra
// snapshots.
snaps = snaps[minSnapshotsOnImageToStartFlatten-1:]
err = flattenClonedRbdImages(
ctx,
snaps,
rbdVol.Pool,
rbdVol.Monitors,
rbdVol.RbdImageName,
cr)
if err != nil {
return status.Error(codes.Internal, err.Error())
}
}
return nil
}

View File

@ -53,9 +53,10 @@ var (
rbdHardMaxCloneDepth uint
// rbdSoftMaxCloneDepth is the soft limit for maximum number of nested volume clones that are taken before a flatten occurs
rbdSoftMaxCloneDepth uint
maxSnapshotsOnImage uint
skipForceFlatten bool
rbdSoftMaxCloneDepth uint
maxSnapshotsOnImage uint
minSnapshotsOnImageToStartFlatten uint
skipForceFlatten bool
)
// NewDriver returns new rbd driver.
@ -111,6 +112,7 @@ func (r *Driver) Run(conf *util.Config) {
rbdSoftMaxCloneDepth = conf.RbdSoftMaxCloneDepth
skipForceFlatten = conf.SkipForceFlatten
maxSnapshotsOnImage = conf.MaxSnapshotsOnImage
minSnapshotsOnImageToStartFlatten = conf.MinSnapshotsOnImage
// Create instances of the volume and snapshot journal
volJournal = journal.NewCSIVolumeJournal(CSIInstanceID)
snapJournal = journal.NewCSISnapshotJournal(CSIInstanceID)