Liron Aravot has uploaded a new change for review.

Change subject: core:WIP: disable compensation in reconstruct/recovery commands
......................................................................

core:WIP: disable compensation in reconstruct/recovery commands

Related to bug 845838
https://bugzilla.redhat.com/845838

The compensation mechanism can recover the engine DB to previous state in case 
of using it
in the following way : acquire memory lock on object -> perform
compensation snapshot of the object -> update object status to locked
in DB, in that way we are guaranteed that no other command will modify
the same object until the compensation procedure is done after a
possible failure (as the object is locked in the DB).

The reconstruct/recovery commands don't rely on any locks, which means
that using the compensation in this commands can leave us in
inconsistent state that we won't be able to recover from like having two
master domains in the DB.

This patch removes the use of compensation from reconstruct/recovery
commands (as we don't want to add locks to this flows) and perform the
DB update only in case that the full reconstruct flow succeeded.

The last updated time/master version are updated in the beginning of the
reconstruct operations execution to avoid selecting the same domain over
and over as the master.

Change-Id: Ice5618125fd494219c4018e60863404d58d02d1a
Signed-off-by: Liron Aravot <lara...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ReconstructMasterDomainCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RecoveryStoragePoolCommand.java
3 files changed, 39 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/19/8619/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
index df59089..0a8b9ce 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
@@ -250,23 +250,23 @@
                         // We do not need to compensate storage pool, it will 
be committed if run during reconstruct
                         
getStoragePool().setmaster_domain_version(getStoragePool().getmaster_domain_version()
 + 1);
                         
newMaster.getStorageStaticData().setLastTimeUsedAsMaster(System.currentTimeMillis());
-                        
getCompensationContext().snapshotEntity(newMaster.getStorageStaticData());
-                        
newMaster.setstorage_domain_type(StorageDomainType.Master);
                         _newMasterStorageDomainId = newMaster.getId();
                         if (!duringReconstruct) {
+                            
getCompensationContext().snapshotEntity(newMaster.getStorageStaticData());
                             
getCompensationContext().snapshotEntityStatus(newMasterMap, 
newMasterMap.getstatus());
+                            
getCompensationContext().snapshotEntity(getStorageDomain().getStorageStaticData());
+                            getCompensationContext().stateChanged();
+
                             newMaster.setstatus(StorageDomainStatus.Locked);
                             
getStoragePoolIsoMapDAO().updateStatus(newMasterMap.getId(), 
newMasterMap.getstatus());
+                            changeToNewMasterDomainInDB();
+                        } else {
+                            // in case of reconstruct we need to update the 
version/last time used as master
+                            // right away because there is no compensation.
+                            DbFacade.getInstance()
+                            .getStorageDomainStaticDao()
+                            .update(newMaster.getStorageStaticData());
                         }
-                        DbFacade.getInstance()
-                                .getStorageDomainStaticDao()
-                                .update(newMaster.getStorageStaticData());
-                        
getCompensationContext().snapshotEntity(getStorageDomain().getStorageStaticData());
-                        
getStorageDomain().setstorage_domain_type(StorageDomainType.Data);
-                        DbFacade.getInstance()
-                                .getStorageDomainStaticDao()
-                                
.update(getStorageDomain().getStorageStaticData());
-                        getCompensationContext().stateChanged();
                         return null;
                     }
                 });
@@ -277,6 +277,17 @@
         }
     }
 
+    protected void changeToNewMasterDomainInDB() {
+        _newMaster.setstorage_domain_type(StorageDomainType.Master);
+        DbFacade.getInstance()
+        .getStorageDomainStaticDao()
+        .update(_newMaster.getStorageStaticData());
+        getStorageDomain().setstorage_domain_type(StorageDomainType.Data);
+        DbFacade.getInstance()
+                .getStorageDomainStaticDao()
+                .update(getStorageDomain().getStorageStaticData());
+    }
+
     protected AsyncTaskDAO getAsyncTaskDao() {
         return DbFacade.getInstance().getAsyncTaskDao();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ReconstructMasterDomainCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ReconstructMasterDomainCommand.java
index 597f41e..6b76f5b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ReconstructMasterDomainCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ReconstructMasterDomainCommand.java
@@ -80,18 +80,6 @@
     protected boolean reconstructMaster() {
         ProceedStorageDomainTreatmentByDomainType(true);
 
-        // To issue a reconstructMaster you need to set the domain inactive
-        if (getParameters().isInactive()) {
-            executeInNewTransaction(new TransactionMethod<Void>() {
-                public Void runInTransaction() {
-                    setStorageDomainStatus(StorageDomainStatus.InActive, 
getCompensationContext());
-                    calcStoragePoolStatusByDomainsStatus();
-                    getCompensationContext().stateChanged();
-                    return null;
-                }
-            });
-        }
-
         if (_isLastMaster) {
             return stopSpm();
         }
@@ -146,6 +134,7 @@
                      .runInternalQuery(VdcQueryType.Search, 
p).getReturnValue();
 
                 VmCommand.updateVmInSpm(getStoragePool().getId(), vmsInPool);
+                performPostReconstructDbOps();
             }
 
             setSucceeded(reconstructOpSucceeded);
@@ -160,6 +149,21 @@
         }
     }
 
+    private void performPostReconstructDbOps() {
+        changeToNewMasterDomainInDB();
+
+        if (getParameters().isInactive()) {
+            executeInNewTransaction(new TransactionMethod<Void>() {
+                public Void runInTransaction() {
+                    setStorageDomainStatus(StorageDomainStatus.InActive, 
getCompensationContext());
+                    calcStoragePoolStatusByDomainsStatus();
+                    //getCompensationContext().stateChanged();
+                    return null;
+                }
+            });
+        }
+    }
+
     protected boolean stopSpm() {
         boolean commandSucceeded = true;
         if (getStoragePool().getspm_vds_id() != null) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RecoveryStoragePoolCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RecoveryStoragePoolCommand.java
index 1f3c6ac..af8d7e0 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RecoveryStoragePoolCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RecoveryStoragePoolCommand.java
@@ -19,7 +19,7 @@
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
-@NonTransactiveCommandAttribute(forceCompensation = true)
+@NonTransactiveCommandAttribute
 public class RecoveryStoragePoolCommand extends ReconstructMasterDomainCommand 
{
 
     /**


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

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

Reply via email to