mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-18 04:10:22 +00:00
cleanup: use errors.As() in journal.Connection methods
See-also: https://github.com/golang/go/wiki/ErrorValueFAQ#how-should-i-change-my-error-handling-code-to-work-with-the-new-features Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
ad04e0d8c4
commit
91ade42a32
@ -281,13 +281,14 @@ func (conn *Connection) CheckReservation(ctx context.Context,
|
|||||||
values, err := getOMapValues(
|
values, err := getOMapValues(
|
||||||
ctx, conn, journalPool, cj.namespace, cj.csiDirectory,
|
ctx, conn, journalPool, cj.namespace, cj.csiDirectory,
|
||||||
cj.commonPrefix, fetchKeys)
|
cj.commonPrefix, fetchKeys)
|
||||||
switch err.(type) {
|
if err != nil {
|
||||||
case nil:
|
var eknf util.ErrKeyNotFound
|
||||||
case util.ErrKeyNotFound, util.ErrPoolNotFound:
|
var epnf util.ErrPoolNotFound
|
||||||
|
if errors.As(err, &eknf) || errors.As(err, &epnf) {
|
||||||
// pool or omap (oid) was not present
|
// pool or omap (oid) was not present
|
||||||
// stop processing but without an error for no reservation exists
|
// stop processing but without an error for no reservation exists
|
||||||
return nil, nil
|
return nil, nil
|
||||||
default:
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
objUUIDAndPool, found := values[cj.csiNameKeyPrefix+reqName]
|
objUUIDAndPool, found := values[cj.csiNameKeyPrefix+reqName]
|
||||||
@ -315,7 +316,8 @@ func (conn *Connection) CheckReservation(ctx context.Context,
|
|||||||
|
|
||||||
savedImagePool, err = util.GetPoolName(conn.monitors, conn.cr, savedImagePoolID)
|
savedImagePool, err = util.GetPoolName(conn.monitors, conn.cr, savedImagePoolID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(util.ErrPoolNotFound); ok {
|
var epnf util.ErrPoolNotFound
|
||||||
|
if errors.As(err, &epnf) {
|
||||||
err = conn.UndoReservation(ctx, journalPool, "", "", reqName)
|
err = conn.UndoReservation(ctx, journalPool, "", "", reqName)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -327,7 +329,8 @@ func (conn *Connection) CheckReservation(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// error should specifically be not found, for image to be absent, any other error
|
// error should specifically be not found, for image to be absent, any other error
|
||||||
// is not conclusive, and we should not proceed
|
// is not conclusive, and we should not proceed
|
||||||
if _, ok := err.(util.ErrKeyNotFound); ok {
|
var eknf util.ErrKeyNotFound
|
||||||
|
if errors.As(err, &eknf) {
|
||||||
err = conn.UndoReservation(ctx, journalPool, savedImagePool,
|
err = conn.UndoReservation(ctx, journalPool, savedImagePool,
|
||||||
cj.GetNameForUUID(namePrefix, objUUID, snapSource), reqName)
|
cj.GetNameForUUID(namePrefix, objUUID, snapSource), reqName)
|
||||||
}
|
}
|
||||||
@ -409,7 +412,8 @@ func (conn *Connection) UndoReservation(ctx context.Context,
|
|||||||
|
|
||||||
err := util.RemoveObject(ctx, conn.monitors, conn.cr, volJournalPool, cj.namespace, cj.cephUUIDDirectoryPrefix+imageUUID)
|
err := util.RemoveObject(ctx, conn.monitors, conn.cr, volJournalPool, cj.namespace, cj.cephUUIDDirectoryPrefix+imageUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(util.ErrObjectNotFound); !ok {
|
var eonf util.ErrObjectNotFound
|
||||||
|
if !errors.As(err, &eonf) {
|
||||||
klog.Errorf(util.Log(ctx, "failed removing oMap %s (%s)"), cj.cephUUIDDirectoryPrefix+imageUUID, err)
|
klog.Errorf(util.Log(ctx, "failed removing oMap %s (%s)"), cj.cephUUIDDirectoryPrefix+imageUUID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -441,7 +445,8 @@ func reserveOMapName(ctx context.Context, monitors string, cr *util.Credentials,
|
|||||||
|
|
||||||
err := util.CreateObject(ctx, monitors, cr, pool, namespace, oMapNamePrefix+iterUUID)
|
err := util.CreateObject(ctx, monitors, cr, pool, namespace, oMapNamePrefix+iterUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(util.ErrObjectExists); ok {
|
var eoe util.ErrObjectExists
|
||||||
|
if errors.As(err, &eoe) {
|
||||||
attempt++
|
attempt++
|
||||||
// try again with a different uuid, for maxAttempts tries
|
// try again with a different uuid, for maxAttempts tries
|
||||||
klog.V(4).Infof(util.Log(ctx, "uuid (%s) conflict detected, retrying (attempt %d of %d)"),
|
klog.V(4).Infof(util.Log(ctx, "uuid (%s) conflict detected, retrying (attempt %d of %d)"),
|
||||||
@ -608,13 +613,14 @@ func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID
|
|||||||
values, err := getOMapValues(
|
values, err := getOMapValues(
|
||||||
ctx, conn, pool, cj.namespace, cj.cephUUIDDirectoryPrefix+objectUUID,
|
ctx, conn, pool, cj.namespace, cj.cephUUIDDirectoryPrefix+objectUUID,
|
||||||
cj.commonPrefix, fetchKeys)
|
cj.commonPrefix, fetchKeys)
|
||||||
switch err.(type) {
|
if err != nil {
|
||||||
case nil:
|
var eknf util.ErrKeyNotFound
|
||||||
case util.ErrPoolNotFound, util.ErrKeyNotFound:
|
var epnf util.ErrPoolNotFound
|
||||||
klog.Warningf(util.Log(ctx, "unable to read omap keys: pool or key missing: %v"), err)
|
if !errors.As(err, &eknf) && !errors.As(err, &epnf) {
|
||||||
default:
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
klog.Warningf(util.Log(ctx, "unable to read omap keys: pool or key missing: %v"), err)
|
||||||
|
}
|
||||||
|
|
||||||
var found bool
|
var found bool
|
||||||
imageAttributes.RequestName = values[cj.csiNameKey]
|
imageAttributes.RequestName = values[cj.csiNameKey]
|
||||||
|
Loading…
Reference in New Issue
Block a user