@DB
private boolean deleteSnapshotInternal(Long snapshotId) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Calling deleteSnapshot for snapshotId: " + snapshotId);
}
SnapshotVO lastSnapshot = null;
SnapshotVO snapshot = _snapshotDao.findById(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);
}
}
Transaction txn = Transaction.currentTxn();
txn.start();
_snapshotDao.remove(snapshotId);
if (snapshot.getStatus() == Snapshot.Status.BackedUp) {
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(), null, null, 0L);
_usageEventDao.persist(usageEvent);
}
_resourceLimitMgr.decrementResourceCount(snapshot.getAccountId(), ResourceType.snapshot);
txn.commit();
long lastId = snapshotId;
boolean destroy = false;
while (true) {