Skip to content

Commit ea63455

Browse files
committed
CLOUDSTACK-8101: volume sync not working as expected - MS restart during upload volume leaves volume in hung state.
1 parent 4cb9505 commit ea63455

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@ public void handleVolumeSync(DataStore store) {
13821382
return;
13831383
}
13841384

1385+
// we can only resume those uploaded volume with a URL specified
13851386
List<VolumeDataStoreVO> dbVolumes = _volumeStoreDao.listUploadedVolumesByStoreId(storeId);
13861387
List<VolumeDataStoreVO> toBeDownloaded = new ArrayList<VolumeDataStoreVO>(dbVolumes);
13871388
for (VolumeDataStoreVO volumeStore : dbVolumes) {
@@ -1405,7 +1406,7 @@ public void handleVolumeSync(DataStore store) {
14051406
volumeStore.setDownloadState(Status.DOWNLOAD_ERROR);
14061407
String msg = "Volume " + volume.getUuid() + " is corrupted on image store ";
14071408
volumeStore.setErrorString(msg);
1408-
s_logger.info("msg");
1409+
s_logger.info(msg);
14091410
if (volumeStore.getDownloadUrl() == null) {
14101411
msg =
14111412
"Volume (" + volume.getUuid() + ") with install path " + volInfo.getInstallPath() +
@@ -1454,7 +1455,6 @@ public void handleVolumeSync(DataStore store) {
14541455
if (volumeStore.getDownloadState() != Status.DOWNLOADED) {
14551456
s_logger.info("Volume Sync did not find " + volume.getName() + " ready on image store " + storeId +
14561457
", will request download to start/resume shortly");
1457-
toBeDownloaded.add(volumeStore);
14581458
}
14591459
}
14601460

@@ -1477,8 +1477,13 @@ public void handleVolumeSync(DataStore store) {
14771477
}
14781478

14791479
s_logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + store.getName());
1480-
// TODO: pass a callback later
1481-
VolumeInfo vol = volFactory.getVolume(volumeHost.getVolumeId());
1480+
// reset volume status back to Allocated
1481+
VolumeObject vol = (VolumeObject)volFactory.getVolume(volumeHost.getVolumeId());
1482+
vol.processEvent(Event.OperationFailed); // reset back volume status
1483+
// remove leftover volume_store_ref entry since re-download will create it again
1484+
_volumeStoreDao.remove(volumeHost.getId());
1485+
// get an updated volumeVO
1486+
vol = (VolumeObject)volFactory.getVolume(volumeHost.getVolumeId());
14821487
RegisterVolumePayload payload = new RegisterVolumePayload(volumeHost.getDownloadUrl(), volumeHost.getChecksum(), vol.getFormat().toString());
14831488
vol.addPayload(payload);
14841489
createVolumeAsync(vol, store);

‎server/src/com/cloud/storage/download/DownloadMonitorImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ public void downloadVolumeToStorage(DataObject volume, AsyncCompletionCallback<D
219219
_volumeStoreDao.persist(volumeHost);
220220
} else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
221221
downloadJobExists = true;
222+
} else {
223+
// persit url and checksum
224+
volumeHost.setDownloadUrl(url);
225+
volumeHost.setChecksum(checkSum);
226+
_volumeStoreDao.update(volumeHost.getId(), volumeHost);
222227
}
223228

224229
Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();

0 commit comments

Comments
 (0)