Liron Ar has uploaded a new change for review. Change subject: core: CompensationContext - add support for updated entity only. ......................................................................
core: CompensationContext - add support for updated entity only. In some cases when we update an entity we would like to use the compensation context to attempt to only update the entity to it's previous state rather than possibly re-insert it as we perform only updates and there might be operations that removed it intentionally without consideration of other running operations. Change-Id: I527d8b95b82f76fb4ce0db7e6ec967c23b759524 Signed-off-by: Liron Aravot <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/DefaultCompensationContext.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/NoOpCompensationContext.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntitySnapshot.java 5 files changed, 23 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/31/25231/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java index ceeaefe..e710392 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java @@ -458,6 +458,9 @@ daoForEntity.update(entitySnapshot); } break; + case UPDATED_ENTITY: + daoForEntity.update((BusinessEntity<Serializable>)snapshotData); + break; case NEW_ENTITY_ID: daoForEntity.remove(snapshotData); break; diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java index 2e70d39..ea842ae 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/CompensationContext.java @@ -20,6 +20,15 @@ public void snapshotEntity(BusinessEntity<?> entity); /** + * Save a snapshot of the entire entity before it was changed in the DB, so that it can be restored later on + * in case of compensation. + * + * @param entity + * The entity state before the change. + */ + public void snapshotEntityUpdated(BusinessEntity<?> entity); + + /** * For each entity in the collection saves a snapshot of the entire data before it is changed/deleted in the DB, so * it can be restored later on in case of compensation * diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/DefaultCompensationContext.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/DefaultCompensationContext.java index f27e6b8..81ebac1 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/DefaultCompensationContext.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/DefaultCompensationContext.java @@ -92,6 +92,11 @@ } @Override + public void snapshotEntityUpdated(BusinessEntity<?> entity) { + snapshotEntityInMemory(entity, entity, SnapshotType.UPDATED_ENTITY); + } + + @Override public void snapshotNewEntity(BusinessEntity<?> entity) { snapshotEntityInMemory(entity, entity.getId(), SnapshotType.NEW_ENTITY_ID); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/NoOpCompensationContext.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/NoOpCompensationContext.java index 1f33a3e..330cf84 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/NoOpCompensationContext.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/context/NoOpCompensationContext.java @@ -21,6 +21,10 @@ } @Override + public void snapshotEntityUpdated(BusinessEntity<?> entity) { + } + + @Override public void snapshotNewEntity(BusinessEntity<?> entity) { } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntitySnapshot.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntitySnapshot.java index 5bd9ffd..43cbf31 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntitySnapshot.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntitySnapshot.java @@ -16,7 +16,8 @@ public enum SnapshotType { CHANGED_ENTITY, NEW_ENTITY_ID, - CHANGED_STATUS_ONLY + CHANGED_STATUS_ONLY, + UPDATED_ENTITY } /** -- To view, visit http://gerrit.ovirt.org/25231 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I527d8b95b82f76fb4ce0db7e6ec967c23b759524 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liron Ar <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
