nagaboinaramgopal commented on code in PR #14348:
URL: https://github.com/apache/cloudstack/pull/14348#discussion_r4223263653


##########
server/src/main/java/com/cloud/network/IpAddressManagerImpl.java:
##########
@@ -420,22 +420,21 @@ private IPAddressVO assignAndAllocateIpAddressEntry(final 
Account owner, final V
     }
 
     private IPAddressVO assignIpAddressWithLock(IPAddressVO possibleAddr) {
-        IPAddressVO finalAddress = null;
-        IPAddressVO userIp = 
_ipAddressDao.acquireInLockTable(possibleAddr.getId());
-        if (userIp != null) {
-            logger.debug("locked row for ip address {} (id: {})", 
possibleAddr.getAddress(), possibleAddr.getUuid());
-            if (userIp.getState() == State.Free) {
-                possibleAddr.setState(State.Allocating);
-                if (_ipAddressDao.update(possibleAddr.getId(), possibleAddr)) {
-                    logger.info("successfully allocated ip address {}", 
possibleAddr.getAddress());
-                    finalAddress = possibleAddr;
-                }
-            } else {
-                logger.debug("locked ip address {} is not free {}", 
possibleAddr.getAddress(), userIp.getState());
-            }
-            _ipAddressDao.releaseFromLockTable(possibleAddr.getId());
+        IPAddressVO userIp = _ipAddressDao.lockRow(possibleAddr.getId(), true);
+        if (userIp == null) {
+            return null;
+        }
+        logger.debug("locked row for ip address {} (id: {})", 
possibleAddr.getAddress(), possibleAddr.getUuid());
+        if (userIp.getState() != State.Free) {
+            logger.debug("locked ip address {} is not free {}", 
possibleAddr.getAddress(), userIp.getState());
+            return null;

Review Comment:
   Fixed in 85aba61c24. assignAndAllocateIpAddressEntry now returns null 
instead of failing when its candidate was taken concurrently, and 
fetchNewPublicIp re-selects a different free IP and retries (bounded to a few 
attempts). listAvailablePublicIps filters on the Free state, so the retry skips 
the address the winner already moved to Allocating and picks another; the 
no-free-IP error is now only raised once the pool is genuinely exhausted.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to