ofri masad has uploaded a new change for review. Change subject: core: Fix charge double quota for move disk ......................................................................
core: Fix charge double quota for move disk When moving disk between quotas both the disk was charged double. While the quota cache counted the disk in the new quota, the DB calculation still count the disk in the old quota (since in the DB the disk is updated to be in the new SD only after the move process is finished). Further more, when updating the cache from DB (for example: when the engine is restarted) the counting of the destination quota was lost (until cache is updated again). To solve this issue two new cache-refresh points were set (only for the quotas of the source and destination of the command): - after the quota was approved and the command started running - after the move process has ended successfully The solution was implemented in the BaseImagesCommand in order to give more generic solution for all commands which involves images. Change-Id: I38aacfad522b27fa88fdf71f3f1356def0fb9540 Bug-Url: https://bugzilla.redhat.com/917382 Bug-Url: https://bugzilla.redhat.com/917387 Signed-off-by: Ofri Masad <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyImageGroupCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskCommand.java 4 files changed, 23 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/59/13559/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java index cbfafee..c086375 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/BaseImagesCommand.java @@ -1,10 +1,12 @@ package org.ovirt.engine.core.bll; +import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.lang.NotImplementedException; import org.ovirt.engine.core.bll.context.CompensationContext; +import org.ovirt.engine.core.bll.quota.QuotaManager; import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator; import org.ovirt.engine.core.bll.storage.StorageDomainCommandBase; import org.ovirt.engine.core.common.action.ImagesActionsParametersBase; @@ -153,6 +155,7 @@ @Override protected void executeCommand() { + refreshQuotas(); checkImageValidity(); } @@ -394,6 +397,7 @@ } unLockImage(); + refreshQuotas(); setSucceeded(true); } @@ -441,4 +445,15 @@ .save(image_storage_domain_map); return image_storage_domain_map; } + + // remove the quotas of the source and destination images + protected void refreshQuotas() { + List<Guid> quotaIds = new ArrayList<Guid>(); + if (getDiskImage() != null) { + quotaIds.add(getDiskImage().getQuotaId()); + } + quotaIds.add(getParameters().getQuotaId()); + + QuotaManager.getInstance().removeQuotaFromCache(getDiskImage().getStoragePoolId().getValue(),quotaIds); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java index cd76631..e215db3 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java @@ -270,6 +270,7 @@ setSucceeded(true); getReturnValue().getTaskIdList().addAll(vdcRetValue.getInternalTaskIdList()); } + refreshQuotas(); } @Override diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyImageGroupCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyImageGroupCommand.java index 91a9170..1683334 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyImageGroupCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyImageGroupCommand.java @@ -115,14 +115,9 @@ (new image_storage_domain_map(getParameters().getImageId(), getParameters().getStorageDomainId())); } - //update quota - if (getParameters().getQuotaId() != null) { - getImageDao().updateQuotaForImageAndSnapshots(getParameters().getDestImageGroupId(), - getParameters().getQuotaId()); - } - setSucceeded(true); } + refreshQuotas(); } private boolean isWipeAfterDelete() { @@ -162,6 +157,11 @@ (new image_storage_domain_map(snapshot.getImageId(), getParameters().getStorageDomainId())); } } + //update quota + if (getParameters().getQuotaId() != null) { + getImageDao().updateQuotaForImageAndSnapshots(getParameters().getDestImageGroupId(), + getParameters().getQuotaId()); + } super.endSuccessfully(); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskCommand.java index 1c0b1dd..faf2d29 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskCommand.java @@ -54,6 +54,7 @@ } else { setSucceeded(false); } + refreshQuotas(); } @Override -- To view, visit http://gerrit.ovirt.org/13559 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I38aacfad522b27fa88fdf71f3f1356def0fb9540 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
