Skip to content

Commit 112dfdd

Browse files
Reset the pool id when create volume fails on the allocated pool, and update the resize error when no endpoint exists (#10777)
* Reset the pool id when create volume fails on the allocated pool - the pool id is persisted while creating the volume, when it fails the pool id is not reverted. On next create volume attempt, CloudStack couldn't find any suitable primary storage even there are pools available with enough capacity as the pool is already assigned to volume which is in Allocated state (and storage pool compatibility check fails). Ensure volume is not assigned to any pool if create volume fails (so the next creation job would pick the suitable pool). * endpoint check for resize * update the resize error through callback result instead of exception
1 parent c183fc9 commit 112dfdd

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ protected Void createVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, C
324324
} else {
325325
vo.processEvent(Event.OperationFailed);
326326
errMsg = result.getResult();
327+
VolumeVO volume = volDao.findById(vo.getId());
328+
if (volume != null && volume.getState() == State.Allocated && volume.getPodId() != null) {
329+
volume.setPoolId(null);
330+
volDao.update(volume.getId(), volume);
331+
}
327332
}
328333
VolumeApiResult volResult = new VolumeApiResult((VolumeObject)vo);
329334
if (errMsg != null) {
@@ -1238,6 +1243,10 @@ private void destroyAndReallocateManagedVolume(VolumeInfo volumeInfo) {
12381243
}
12391244

12401245
if (volume.getState() == State.Allocated) { // Possible states here: Allocated, Ready & Creating
1246+
if (volume.getPodId() != null) {
1247+
volume.setPoolId(null);
1248+
volDao.update(volume.getId(), volume);
1249+
}
12411250
return;
12421251
}
12431252

@@ -2482,7 +2491,7 @@ public AsyncCallFuture<VolumeApiResult> resize(VolumeInfo volume) {
24822491
try {
24832492
volume.processEvent(Event.ResizeRequested);
24842493
} catch (Exception e) {
2485-
s_logger.debug("Failed to change state to resize", e);
2494+
s_logger.debug("Failed to change volume state to resize", e);
24862495
result.setResult(e.toString());
24872496
future.complete(result);
24882497
return future;
@@ -2494,10 +2503,8 @@ public AsyncCallFuture<VolumeApiResult> resize(VolumeInfo volume) {
24942503
try {
24952504
volume.getDataStore().getDriver().resize(volume, caller);
24962505
} catch (Exception e) {
2497-
s_logger.debug("Failed to change state to resize", e);
2498-
2506+
s_logger.debug("Failed to resize volume", e);
24992507
result.setResult(e.toString());
2500-
25012508
future.complete(result);
25022509
}
25032510

@@ -2541,7 +2548,7 @@ protected Void resizeVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, C
25412548
try {
25422549
volume.processEvent(Event.OperationFailed);
25432550
} catch (Exception e) {
2544-
s_logger.debug("Failed to change state", e);
2551+
s_logger.debug("Failed to change volume state (after resize failure)", e);
25452552
}
25462553
VolumeApiResult res = new VolumeApiResult(volume);
25472554
res.setResult(result.getResult());
@@ -2552,13 +2559,8 @@ protected Void resizeVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, C
25522559
try {
25532560
volume.processEvent(Event.OperationSuccessed);
25542561
} catch (Exception e) {
2555-
s_logger.debug("Failed to change state", e);
2556-
VolumeApiResult res = new VolumeApiResult(volume);
2557-
res.setResult(result.getResult());
2558-
future.complete(res);
2559-
return null;
2562+
s_logger.debug("Failed to change volume state (after resize success)", e);
25602563
}
2561-
25622564
VolumeApiResult res = new VolumeApiResult(volume);
25632565
future.complete(res);
25642566

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,25 @@ public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> cal
429429
boolean encryptionRequired = anyVolumeRequiresEncryption(vol);
430430
long [] endpointsToRunResize = resizeParameter.hosts;
431431

432+
CreateCmdResult result = new CreateCmdResult(null, null);
433+
432434
// if hosts are provided, they are where the VM last ran. We can use that.
433435
if (endpointsToRunResize == null || endpointsToRunResize.length == 0) {
434436
EndPoint ep = epSelector.select(data, encryptionRequired);
437+
if (ep == null) {
438+
String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired);
439+
s_logger.error(errMsg);
440+
result.setResult(errMsg);
441+
callback.complete(result);
442+
return;
443+
}
435444
endpointsToRunResize = new long[] {ep.getId()};
436445
}
437446
ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(),
438447
resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName, vol.getChainInfo(), vol.getPassphrase(), vol.getEncryptFormat());
439448
if (pool.getParent() != 0) {
440449
resizeCmd.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
441450
}
442-
CreateCmdResult result = new CreateCmdResult(null, null);
443451
try {
444452
ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, endpointsToRunResize, resizeCmd);
445453
if (answer != null && answer.getResult()) {
@@ -456,7 +464,6 @@ public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> cal
456464
s_logger.debug("return a null answer, mark it as failed for unknown reason");
457465
result.setResult("return a null answer, mark it as failed for unknown reason");
458466
}
459-
460467
} catch (Exception e) {
461468
s_logger.debug("sending resize command failed", e);
462469
result.setResult(e.toString());

0 commit comments

Comments
 (0)