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_r228130569
##########
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:
Now you removed the aggregation of data out of the transaction, but you
maintained the lock account. It will not make any difference here. Therefore,
right after the data is aggregated, but not updated, some VM/resources can be
allocated/deployed, and then the value is updated here. This means, we will set
an invalid value.
When I suggested to maintain the lock account, was to use it out of the
transaction as this mechanism is used differently. AS far as I have seen, this
lock account/domain is some sort of transaction management that is executed
manually based on resources that ACS does. Therefore, you can execute this
command right at the beginning (at line 889) .
----------------------------------------------------------------
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