Skip to content

server: fix orphan db transaction issue #11095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions server/src/main/java/com/cloud/alert/AlertManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
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 {
Expand Down Expand Up @@ -290,8 +294,13 @@ protected void recalculateHostCapacities() {
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;
}));
}
Expand All @@ -316,13 +325,18 @@ protected void recalculateStorageCapacities() {
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;
}));
}
Expand Down
36 changes: 21 additions & 15 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
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;
Expand Down Expand Up @@ -1591,22 +1592,27 @@
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;
}
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);
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<Exception>() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {

Check warning on line 1597 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1597

Added line #L1597 was not covered by tests
HostVO host = _hostDao.findById(hostId);
try {

Check warning on line 1599 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1599

Added line #L1599 was not covered by tests
connectHostToSharedPool(host, primaryStore.getId());
poolHostIds.add(hostId);
} catch (Exception e) {

Check warning on line 1602 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1602

Added line #L1602 was not covered by tests
if (handleExceptionsPartially && e.getCause() instanceof StorageConflictException) {
exceptionOccurred.set(true);
throw e;

Check warning on line 1605 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1604-L1605

Added lines #L1604 - L1605 were not covered by tests
}
logger.warn("Unable to establish a connection between {} and {}", host, primaryStore, e);
String reason = getStoragePoolMountFailureReason(e.getMessage());

Check warning on line 1608 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1607-L1608

Added lines #L1607 - L1608 were not covered by tests
if (handleExceptionsPartially && reason != null) {
exceptionOccurred.set(true);
throw new CloudRuntimeException(reason);

Check warning on line 1611 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1610-L1611

Added lines #L1610 - L1611 were not covered by tests
}
}
}
}
});
return null;
}));
}
Expand Down
Loading