rafaelweingartner commented on a change in pull request #2927: server: fix 
unwanted txn commit warning messages
URL: https://github.com/apache/cloudstack/pull/2927#discussion_r228140668
 
 

 ##########
 File path: server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
 ##########
 @@ -886,60 +887,62 @@ public Long doInTransaction(TransactionStatus status) {
 
     @DB
     protected long recalculateAccountResourceCount(final long accountId, final 
ResourceType type) {
-        Long newCount = Transaction.execute(new TransactionCallback<Long>() {
+        final Long newCount;
+        if (type == Resource.ResourceType.user_vm) {
+            newCount = _userVmDao.countAllocatedVMsForAccount(accountId);
+        } else if (type == Resource.ResourceType.volume) {
+            long virtualRouterCount = 
_vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId).size();
+            newCount = _volumeDao.countAllocatedVolumesForAccount(accountId) - 
virtualRouterCount; // don't count the volumes of virtual router
+        } else if (type == Resource.ResourceType.snapshot) {
+            newCount = _snapshotDao.countSnapshotsForAccount(accountId);
+        } else if (type == Resource.ResourceType.public_ip) {
+            newCount = calculatePublicIpForAccount(accountId);
+        } else if (type == Resource.ResourceType.template) {
+            newCount = _vmTemplateDao.countTemplatesForAccount(accountId);
+        } else if (type == Resource.ResourceType.project) {
+            newCount = _projectAccountDao.countByAccountIdAndRole(accountId, 
Role.Admin);
+        } else if (type == Resource.ResourceType.network) {
+            newCount = _networkDao.countNetworksUserCanCreate(accountId);
+        } else if (type == Resource.ResourceType.vpc) {
+            newCount = _vpcDao.countByAccountId(accountId);
+        } else if (type == Resource.ResourceType.cpu) {
+            newCount = countCpusForAccount(accountId);
+        } else if (type == Resource.ResourceType.memory) {
+            newCount = calculateMemoryForAccount(accountId);
+        } else if (type == Resource.ResourceType.primary_storage) {
+            List<Long> virtualRouters = 
_vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId);
+            newCount = _volumeDao.primaryStorageUsedForAccount(accountId, 
virtualRouters);
+        } else if (type == Resource.ResourceType.secondary_storage) {
+            newCount = calculateSecondaryStorageForAccount(accountId);
+        } else {
+            throw new InvalidParameterValueException("Unsupported resource 
type " + type);
+        }
+
+        long oldCount = 0;
+        final ResourceCountVO accountRC = 
_resourceCountDao.findByOwnerAndType(accountId, ResourceOwnerType.Account, 
type);
+        if (accountRC != null) {
+            oldCount = accountRC.getCount();
+        }
+
+        if (newCount == null || !newCount.equals(oldCount)) {
+            Transaction.execute(new TransactionCallbackNoReturn() {
                 @Override
-                public Long doInTransaction(TransactionStatus status) {
-                    Long newCount = null;
+                public void doInTransactionWithoutResult(TransactionStatus 
status) {
                     lockAccountAndOwnerDomainRows(accountId, type);
-                    ResourceCountVO accountRC = 
_resourceCountDao.findByOwnerAndType(accountId, ResourceOwnerType.Account, 
type);
 
 Review comment:
   are you talking about this ` lockAccountAndOwnerDomainRows(accountId, 
type);` line?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to