You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/11/02 18:34:49 UTC

[5/6] git commit: CS-16499: releaseNic - lock the nic row in the DB before checking its state. Hold the lock till the nics attributes + nicCount is updated

CS-16499: releaseNic - lock the nic row in the DB before checking its state. Hold the lock till the nics attributes + nicCount is updated

Conflicts:

	server/src/com/cloud/network/NetworkManagerImpl.java

Conflicts:

	server/src/com/cloud/network/NetworkManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7bd7884f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7bd7884f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7bd7884f

Branch: refs/heads/master
Commit: 7bd7884f57cf6ee2dd88f7c1779f27397fba3f50
Parents: 49919bc
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Thu Oct 18 18:45:00 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Fri Nov 2 09:59:36 2012 -0700

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManagerImpl.java  |   31 ++++++++++++--
 1 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7bd7884f/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 7506985..4f72a80 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -2094,7 +2094,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
         List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
 
         // we have to implement default nics first - to ensure that default network elements start up first in multiple
-        // nics case)(need for setting DNS on Dhcp to domR's Ip4 address)
+        //nics case
+        // (need for setting DNS on Dhcp to domR's Ip4 address)
         Collections.sort(nics, new Comparator<NicVO>() {
 
             @Override
@@ -2193,6 +2194,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
     }
 
     @Override
+    @DB
     public void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boolean forced) throws
             ConcurrentOperationException, ResourceUnavailableException {
         List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
@@ -2200,6 +2202,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
             releaseNic(vmProfile, nic);
         }
     }
+
+
     @Override
     public void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic) 
             throws ConcurrentOperationException, ResourceUnavailableException {
@@ -2208,11 +2212,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
     }
 
 
-    protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic) 
+    protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nicVO) 
             throws ConcurrentOperationException, ResourceUnavailableException {
-        NetworkVO network = _networksDao.findById(nic.getNetworkId());
-        if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
-            Nic.State originalState = nic.getState();
+        //lock the nic
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        
+        NicVO nic = _nicDao.lockRow(nicVO.getId(), true);
+        if (nic == null) {
+            throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
+        }
+        
+        Nic.State originalState = nic.getState();
+        NetworkVO network = _networksDao.findById(nicVO.getNetworkId());
+        
+        if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
             if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
                 NetworkGuru guru = _networkGurus.get(network.getGuruName());
                 nic.setState(Nic.State.Releasing);
@@ -2228,6 +2242,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
                         _nicDao.update(nic.getId(), nic);
                     }
                 }
+                //commit the transaction before proceeding releasing nic profile on the network elements
+                txn.commit();
+                
                 // Perform release on network elements
                 for (NetworkElement element : _networkElements) {
                     if (s_logger.isDebugEnabled()) {
@@ -2241,7 +2258,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
             } else {
                 nic.setState(Nic.State.Allocated);
                 updateNic(nic, network.getId(), -1);
+                txn.commit();
             }
+        } else {
+            //commiting the empty transaction here as we have to release the lock we've held
+            txn.commit();
         }
     }