Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ public boolean deleteBackup(Backup backup, boolean forced) {
} else {
host = resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM, backup.getZoneId());
}
if (host == null) {
throw new CloudRuntimeException(String.format("Unable to find a running KVM host in zone %d to delete backup %s", backup.getZoneId(), backup.getUuid()));
}

DeleteBackupCommand command = new DeleteBackupCommand(backup.getExternalId(), backupRepository.getType(),
backupRepository.getAddress(), backupRepository.getMountOptions());
Expand Down Expand Up @@ -564,7 +567,14 @@ public Pair<Long, Long> getBackupStorageStats(Long zoneId) {
@Override
public void syncBackupStorageStats(Long zoneId) {
final List<BackupRepository> repositories = backupRepositoryDao.listByZoneAndProvider(zoneId, getName());
if (CollectionUtils.isEmpty(repositories)) {
return;
}
Comment on lines +570 to +572
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty repositories check is placed after the method starts processing but before the host lookup. If repositories are empty, the host lookup at line 573 becomes unnecessary. Consider moving this check before the host lookup, or better yet, to the beginning of the method to avoid any unnecessary operations when there are no repositories to process.

Copilot uses AI. Check for mistakes.
final Host host = resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM, zoneId);
if (host == null) {
logger.warn("Unable to find a running KVM host in zone {} to sync backup storage stats", zoneId);
return;
}
for (final BackupRepository repository : repositories) {
GetBackupStorageStatsCommand command = new GetBackupStorageStatsCommand(repository.getType(), repository.getAddress(), repository.getMountOptions());
BackupStorageStatsAnswer answer;
Expand Down
Loading