if it is empty snapshot, set setBackupSnapshotId to null, before remove it

This commit is contained in:
anthony 2011-02-09 14:22:53 -08:00
parent 46c54017d7
commit ce4922cb76
1 changed files with 8 additions and 1 deletions

View File

@ -672,7 +672,14 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
SnapshotVO lastSnapshot = null;
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
_snapshotDao.remove(snapshotId);
if ( snapshot.getBackupSnapshotId() != null ) {
List<SnapshotVO> snaps = _snapshotDao.listByBackupUuid(snapshot.getVolumeId(), snapshot.getBackupSnapshotId());
if ( snaps != null && snaps.size() > 1 ) {
snapshot.setBackupSnapshotId(null);
_snapshotDao.update(snapshot.getId(), snapshot);
}
}
_snapshotDao.remove(snapshotId);
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), 0L, snapshotId, snapshot.getName(), null, null, 0L);
_usageEventDao.persist(usageEvent);
long lastId = snapshotId;