Arik Hadas has uploaded a new change for review.

Change subject: core: fix for memory being removed from stateless snapshot
......................................................................

core: fix for memory being removed from stateless snapshot

This patch changes the memory removal on RunVmCommand so that it will be
removed from the active snapshot instead of removing it from the
stateless snapshot for a VM that runs in stateless mode.

Change-Id: Ib4d2db4a5a21217b7ffce9a634524e196064276e
Bug-Url: https://bugzilla.redhat.com/960931
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M backend/manager/dbscripts/snapshots_sp.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/SnapshotDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
6 files changed, 30 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/16017/1

diff --git a/backend/manager/dbscripts/snapshots_sp.sql 
b/backend/manager/dbscripts/snapshots_sp.sql
index 6a5878b..5701229 100644
--- a/backend/manager/dbscripts/snapshots_sp.sql
+++ b/backend/manager/dbscripts/snapshots_sp.sql
@@ -327,15 +327,16 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
-Create or replace FUNCTION UpdateMemoryOfSnapshot(
-    v_snapshot_id UUID,
-    v_memory_volume VARCHAR(255))
+Create or replace FUNCTION RemoveMemoryFromSnapshot(
+    v_vm_id UUID,
+    v_snapshot_type VARCHAR(32))
 RETURNS VOID
 AS $procedure$
 BEGIN
     UPDATE snapshots
-    SET    memory_volume = v_memory_volume
-    WHERE  snapshot_id = v_snapshot_id;
+    SET    memory_volume = NULL
+    WHERE  vm_id = v_vm_id
+    AND    snapshot_type = v_snapshot_type;
 END; $procedure$
 LANGUAGE plpgsql;
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index 3c97d10..45a84ea 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -147,18 +147,13 @@
             if (getVm().getStatus() != VMStatus.Suspended) {
                 memorySnapshotSupported = 
FeatureSupported.memorySnapshot(getVm().getVdsGroupCompatibilityVersion());
                 // If the VM is not hibernated, save the hibernation volume 
from the baseline snapshot
-                memoryVolumeFromSnapshot = 
getBaselineSnapshot().getMemoryVolume();
+                memoryVolumeFromSnapshot = 
getActiveSnapshot().getMemoryVolume();
             }
         }
     }
 
-    /**
-     * Returns the snapshot the vm is based on - either the active snapshot 
(usually) or
-     * the stateless snapshot in case the VM is running in stateless mode
-     */
-    private Snapshot getBaselineSnapshot() {
-        return getSnapshotDao().get(getVm().getId(),
-                isVmRunningStateless() ? SnapshotType.STATELESS : 
SnapshotType.ACTIVE);
+    private Snapshot getActiveSnapshot() {
+        return getSnapshotDao().get(getVm().getId(), SnapshotType.ACTIVE);
     }
 
     private SnapshotDao getSnapshotDao() {
@@ -831,7 +826,7 @@
 
             setSucceeded(vdcReturnValue.getSucceeded());
             // we are not running the VM, of course,
-            // since we couldn't create a snpashot.
+            // since we couldn't create a snapshot.
         }
 
         else {
@@ -841,19 +836,19 @@
 
     @Override
     public void runningSucceded() {
-        removeMemoryFromSnapshot();
+        removeMemoryFromActiveSnapshot();
         super.runningSucceded();
     }
 
     @Override
     protected void failedToRunVm() {
         if (memoryFromSnapshotIrrelevant) {
-            removeMemoryFromSnapshot();
+            removeMemoryFromActiveSnapshot();
         }
         super.failedToRunVm();
     }
 
-    private void removeMemoryFromSnapshot() {
+    private void removeMemoryFromActiveSnapshot() {
         if (memoryVolumeFromSnapshot.isEmpty()) {
             return;
         }
@@ -862,7 +857,7 @@
         if 
(getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolumeFromSnapshot) == 1) {
             removeMemoryVolumes(memoryVolumeFromSnapshot, getActionType(), 
true);
         }
-        
getSnapshotDao().removeMemoryFromSnapshot(getBaselineSnapshot().getId());
+        getSnapshotDao().removeMemoryFromActiveSnapshot(getVmId());
     }
 
     private boolean isVmRunningStateless() {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java
index 74ece58..708b77f 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDao.java
@@ -173,10 +173,16 @@
     int getNumOfSnapshotsByMemory(String memoryVolume);
 
     /**
-     * Clear the memory from the snapshot with the given id
+     * Clear the memory from the active snapshot of the VM with the given id
      *
      * @param snapshotId
      *          The id of the snapshot that its memory should be cleared
      */
-    void removeMemoryFromSnapshot(Guid snapshotId);
+    /**
+     * Clear the memory from the active snapshot of the VM with the given id
+     *
+     * @param vmId
+     *          The ID of the VM to remove the memory from.
+     */
+    void removeMemoryFromActiveSnapshot(Guid vmId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java
index 96b9987..d2a3596 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/SnapshotDaoDbFacadeImpl.java
@@ -224,12 +224,12 @@
     }
 
     @Override
-    public void removeMemoryFromSnapshot(Guid snapshotId) {
+    public void removeMemoryFromActiveSnapshot(Guid vmId) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
-                .addValue("snapshot_id", snapshotId)
-                .addValue("memory_volume", null);
+                .addValue("vm_id", vmId)
+                .addValue("snapshot_type", SnapshotType.ACTIVE.name());
 
-        getCallsHandler().executeModification("UpdateMemoryOfSnapshot",
+        getCallsHandler().executeModification("RemoveMemoryFromSnapshot",
                 parameterSource);
     }
 
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/SnapshotDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/SnapshotDaoTest.java
index bc2f6fb..c26555f 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/SnapshotDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/SnapshotDaoTest.java
@@ -23,6 +23,7 @@
 public class SnapshotDaoTest extends BaseGenericDaoTestCase<Guid, Snapshot, 
SnapshotDao> {
 
     private static final Guid EXISTING_VM_ID = new 
Guid("77296e00-0cad-4e5a-9299-008a7b6f4355");
+    private static final Guid EXISTING_VM_ID2 = new 
Guid("77296e00-0cad-4e5a-9299-008a7b6f4354");
     private static final Guid EXISTING_SNAPSHOT_ID = new 
Guid("a7bb24df-9fdf-4bd6-b7a9-f5ce52da0f89");
     private static final Guid EXISTING_SNAPSHOT_ID2 = new 
Guid("a7bb24df-9fdf-4bd6-b7a9-f5ce52da0f11");
     private static final String EXISTING_MEMORY_VOLUME =
@@ -290,11 +291,11 @@
     }
 
     @Test
-    public void removeMemoryFromSnapshot() throws Exception {
+    public void removeMemoryFromActiveSnapshot() throws Exception {
         Snapshot snapshot = dao.get(EXISTING_SNAPSHOT_ID2);
         assertEquals(EXISTING_MEMORY_VOLUME, snapshot.getMemoryVolume());
 
-        dao.removeMemoryFromSnapshot(EXISTING_SNAPSHOT_ID2);
+        dao.removeMemoryFromActiveSnapshot(EXISTING_VM_ID2);
 
         snapshot = dao.get(EXISTING_SNAPSHOT_ID2);
         assertEquals(StringUtils.EMPTY, snapshot.getMemoryVolume());
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 8dadfc2..60ad37a 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -2553,7 +2553,7 @@
         <row>
             <value>a7bb24df-9fdf-4bd6-b7a9-f5ce52da0f11</value>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4354</value>
-            <value>REGULAR</value>
+            <value>ACTIVE</value>
             <value>OK</value>
             <value>Test snapshot!</value>
             <value>2010-11-18 11:11:35</value>


-- 
To view, visit http://gerrit.ovirt.org/16017
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4d2db4a5a21217b7ffce9a634524e196064276e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <aha...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to