mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
server: fix orphan db transaction issue (#11095)
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
3b54194aef
commit
c24e4eea85
@ -89,6 +89,10 @@ import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallbackNoReturn;
|
||||
import com.cloud.utils.db.TransactionStatus;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable {
|
||||
@ -290,8 +294,13 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
|
||||
Math.min(CapacityManager.CapacityCalculateWorkers.value(), hostIds.size())));
|
||||
for (Long hostId : hostIds) {
|
||||
futures.put(hostId, executorService.submit(() -> {
|
||||
final HostVO host = hostDao.findById(hostId);
|
||||
_capacityMgr.updateCapacityForHost(host);
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
@Override
|
||||
public void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
final HostVO host = hostDao.findById(hostId);
|
||||
_capacityMgr.updateCapacityForHost(host);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
@ -316,13 +325,18 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
|
||||
Math.min(CapacityManager.CapacityCalculateWorkers.value(), storagePoolIds.size())));
|
||||
for (Long poolId: storagePoolIds) {
|
||||
futures.put(poolId, executorService.submit(() -> {
|
||||
final StoragePoolVO pool = _storagePoolDao.findById(poolId);
|
||||
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
|
||||
if (pool.isShared()) {
|
||||
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
|
||||
} else {
|
||||
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
|
||||
}
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
@Override
|
||||
public void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
final StoragePoolVO pool = _storagePoolDao.findById(poolId);
|
||||
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
|
||||
if (pool.isShared()) {
|
||||
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
|
||||
} else {
|
||||
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
@ -257,6 +257,7 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallbackNoReturn;
|
||||
import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.utils.db.TransactionStatus;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
@ -1591,22 +1592,27 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
if (exceptionOccurred.get()) {
|
||||
return null;
|
||||
}
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
try {
|
||||
connectHostToSharedPool(host, primaryStore.getId());
|
||||
poolHostIds.add(hostId);
|
||||
} catch (Exception e) {
|
||||
if (handleExceptionsPartially && e.getCause() instanceof StorageConflictException) {
|
||||
exceptionOccurred.set(true);
|
||||
throw e;
|
||||
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<Exception>() {
|
||||
@Override
|
||||
public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
try {
|
||||
connectHostToSharedPool(host, primaryStore.getId());
|
||||
poolHostIds.add(hostId);
|
||||
} catch (Exception e) {
|
||||
if (handleExceptionsPartially && e.getCause() instanceof StorageConflictException) {
|
||||
exceptionOccurred.set(true);
|
||||
throw e;
|
||||
}
|
||||
logger.warn("Unable to establish a connection between {} and {}", host, primaryStore, e);
|
||||
String reason = getStoragePoolMountFailureReason(e.getMessage());
|
||||
if (handleExceptionsPartially && reason != null) {
|
||||
exceptionOccurred.set(true);
|
||||
throw new CloudRuntimeException(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.warn("Unable to establish a connection between {} and {}", host, primaryStore, e);
|
||||
String reason = getStoragePoolMountFailureReason(e.getMessage());
|
||||
if (handleExceptionsPartially && reason != null) {
|
||||
exceptionOccurred.set(true);
|
||||
throw new CloudRuntimeException(reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user