mirror of https://github.com/apache/cloudstack.git
bug 6516: didn't consider it last snapshot is deleted but the new snapshot is empty
status 6516: resolved fixed
This commit is contained in:
parent
eb60dc690c
commit
b69d7d443a
|
|
@ -68,17 +68,21 @@ public class CreateSnapshotExecutor extends BaseAsyncJobExecutor {
|
|||
|
||||
try {
|
||||
SnapshotVO snapshot = snapshotManager.createSnapshot(userId, param.getVolumeId(), param.getPolicyIds());
|
||||
|
||||
if (snapshot != null && snapshot.getStatus() == Snapshot.Status.CreatedOnPrimary) {
|
||||
Snapshot.Status status = snapshot.getStatus();
|
||||
if (snapshot != null && ( status == Snapshot.Status.CreatedOnPrimary
|
||||
|| status == Snapshot.Status.BackedUp) ) {
|
||||
snapshotId = snapshot.getId();
|
||||
asyncMgr.updateAsyncJobStatus(jobId, BaseCmd.PROGRESS_INSTANCE_CREATED, snapshotId);
|
||||
backedUp = snapshotManager.backupSnapshotToSecondaryStorage(userId, snapshot);
|
||||
if( status == Snapshot.Status.CreatedOnPrimary ) {
|
||||
asyncMgr.updateAsyncJobStatus(jobId, BaseCmd.PROGRESS_INSTANCE_CREATED, snapshotId);
|
||||
backedUp = snapshotManager.backupSnapshotToSecondaryStorage(userId, snapshot);
|
||||
} else {
|
||||
backedUp = true;
|
||||
}
|
||||
if (backedUp) {
|
||||
result = AsyncJobResult.STATUS_SUCCEEDED;
|
||||
errorCode = 0; // Success
|
||||
resultObject = composeResultObject(snapshot);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// More specific error
|
||||
resultObject = "Created snapshot: " + snapshotId + " on primary but failed to backup on secondary";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -387,12 +387,19 @@ public class SnapshotManagerImpl implements SnapshotManager {
|
|||
if ((answer != null) && answer.getResult()) {
|
||||
// The snapshot was successfully created
|
||||
if (preSnapshotPath != null && preSnapshotPath == answer.getSnapshotPath()) {
|
||||
// empty snapshot
|
||||
s_logger.debug("CreateSnapshot: this is empty snapshot, remove it ");
|
||||
// delete from the snapshots table
|
||||
_snapshotDao.delete(id);
|
||||
throw new CloudRuntimeException(
|
||||
|
||||
if( preSnapshotVO.getRemoved() != null ) {
|
||||
String backupPath = preSnapshotVO.getBackupSnapshotId();
|
||||
_snapshotDao.delete(preId);
|
||||
createdSnapshot = updateDBOnCreateDuplicate(id, answer.getSnapshotPath(), backupPath);
|
||||
} else {
|
||||
// empty snapshot
|
||||
s_logger.debug("CreateSnapshot: this is empty snapshot, remove it ");
|
||||
// delete from the snapshots table
|
||||
_snapshotDao.delete(id);
|
||||
throw new CloudRuntimeException(
|
||||
" There is no change since last snapshot, please use last snapshot " + preSnapshotPath);
|
||||
}
|
||||
|
||||
} else {
|
||||
createdSnapshot = updateDBOnCreate(id, answer.getSnapshotPath());
|
||||
|
|
@ -436,6 +443,17 @@ public class SnapshotManagerImpl implements SnapshotManager {
|
|||
return createdSnapshot;
|
||||
}
|
||||
|
||||
private SnapshotVO updateDBOnCreateDuplicate(Long id, String snapshotPath, String backUpSnapshotPath) {
|
||||
SnapshotVO createdSnapshot = _snapshotDao.findById(id);
|
||||
Long volumeId = createdSnapshot.getVolumeId();
|
||||
createdSnapshot.setPath(snapshotPath);
|
||||
createdSnapshot.setBackupSnapshotId(backUpSnapshotPath);
|
||||
createdSnapshot.setStatus(Snapshot.Status.BackedUp);
|
||||
createdSnapshot.setPrevSnapshotId(_snapshotDao.getLastSnapshot(volumeId, id));
|
||||
_snapshotDao.update(id, createdSnapshot);
|
||||
return createdSnapshot;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@SuppressWarnings("fallthrough")
|
||||
|
|
|
|||
Loading…
Reference in New Issue