From b69d7d443ae8428b3c55cb910177f3554ee25c18 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 12 Oct 2010 16:53:56 -0700 Subject: [PATCH] bug 6516: didn't consider it last snapshot is deleted but the new snapshot is empty status 6516: resolved fixed --- .../executor/CreateSnapshotExecutor.java | 16 +++++++---- .../storage/snapshot/SnapshotManagerImpl.java | 28 +++++++++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/async/executor/CreateSnapshotExecutor.java b/server/src/com/cloud/async/executor/CreateSnapshotExecutor.java index d32aada79e4..4fa8b75d26b 100644 --- a/server/src/com/cloud/async/executor/CreateSnapshotExecutor.java +++ b/server/src/com/cloud/async/executor/CreateSnapshotExecutor.java @@ -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"; } diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 4e9eb137894..fb1078bb3f7 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -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")