CS-15823 Failed snapshot should be marked as Error and cleanup asynchronously

This commit is contained in:
Mice Xia 2012-08-15 11:06:25 +08:00 committed by Alex Huang
parent 7d285a4ac9
commit 66ea5ed4fb
4 changed files with 21 additions and 7 deletions

View File

@ -2260,6 +2260,17 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
s_logger.warn("Unable to destroy " + vol.getId(), e);
}
}
// remove snapshots in Error state
List<SnapshotVO> snapshots = _snapshotDao.listAllByStatus(Snapshot.Status.Error);
for (SnapshotVO snapshotVO : snapshots) {
try{
_snapshotDao.expunge(snapshotVO.getId());
}catch (Exception e) {
s_logger.warn("Unable to destroy " + snapshotVO.getId(), e);
}
}
} finally {
scanLock.unlock();
}

View File

@ -41,4 +41,5 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long> {
public Long countSnapshotsForAccount(long accountId);
List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.Status... status);
List<SnapshotVO> listByStatus(long volumeId, Snapshot.Status... status);
List<SnapshotVO> listAllByStatus(Snapshot.Status... status);
}

View File

@ -307,4 +307,11 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
txn.commit();
return result;
}
@Override
public List<SnapshotVO> listAllByStatus(Snapshot.Status... status) {
SearchCriteria<SnapshotVO> sc = this.StatusSearch.create();
sc.setParameters("status", (Object[])status);
return listBy(sc, null);
}
}

View File

@ -372,9 +372,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (answer != null) {
s_logger.error(answer.getDetails());
}
// delete from the snapshots table
_snapshotDao.expunge(snapshotId);
throw new CloudRuntimeException("Creating snapshot for volume " + volumeId + " on primary storage failed.");
}
@ -424,7 +421,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
if (hosts != null && !hosts.isEmpty()) {
HostVO host = hosts.get(0);
if (!hostSupportSnapsthot(host)) {
_snapshotDao.expunge(snapshotId);
throw new CloudRuntimeException("KVM Snapshot is not supported on cluster: " + host.getId());
}
}
@ -435,14 +431,13 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
UserVmVO userVm = _vmDao.findById(volume.getInstanceId());
if (userVm != null) {
if (userVm.getState().equals(State.Destroyed) || userVm.getState().equals(State.Expunging)) {
_snapshotDao.expunge(snapshotId);
throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " is associated with vm:" + userVm.getInstanceName() + " is in "
+ userVm.getState().toString() + " state");
}
if(userVm.getHypervisorType() == HypervisorType.VMware || userVm.getHypervisorType() == HypervisorType.KVM) {
List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.Status.Creating, Snapshot.Status.CreatedOnPrimary, Snapshot.Status.BackingUp);
if(activeSnapshots.size() > 1)
List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.Status.Creating, Snapshot.Status.CreatedOnPrimary, Snapshot.Status.BackingUp);
if(activeSnapshots.size() > 1)
throw new CloudRuntimeException("There is other active snapshot tasks on the instance to which the volume is attached, please try again later");
}
}