Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@ public interface SnapshotApiService {
Snapshot backupSnapshotFromVmSnapshot(Long snapshotId, Long vmId, Long volumeId, Long vmSnapshotId);

SnapshotPolicy updateSnapshotPolicy(UpdateSnapshotPolicyCmd updateSnapshotPolicyCmd);

void markVolumeSnapshotsAsDestroyed(Volume volume);
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import com.cloud.storage.dao.VMTemplatePoolDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.dao.VolumeDetailsDao;
import com.cloud.storage.snapshot.SnapshotApiService;
import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.storage.template.TemplateProp;
import com.cloud.user.AccountManager;
Expand Down Expand Up @@ -194,6 +195,8 @@ public class VolumeServiceImpl implements VolumeService {
private StorageManager _storageMgr;
@Inject
private AnnotationDao annotationDao;
@Inject
private SnapshotApiService snapshotApiService;

private final static String SNAPSHOT_ID = "SNAPSHOT_ID";

Expand Down Expand Up @@ -448,9 +451,9 @@ public Void deleteVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, Comm
volDao.remove(vo.getId());
}

SnapshotDataStoreVO snapStoreVo = _snapshotStoreDao.findByVolume(vo.getId(), DataStoreRole.Primary);
List<SnapshotDataStoreVO> snapStoreVOs = _snapshotStoreDao.listAllByVolumeAndDataStore(vo.getId(), DataStoreRole.Primary);

if (snapStoreVo != null) {
for (SnapshotDataStoreVO snapStoreVo : snapStoreVOs) {
Comment thread
slavkap marked this conversation as resolved.
Resolved
long storagePoolId = snapStoreVo.getDataStoreId();
StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);

Expand All @@ -468,6 +471,7 @@ public Void deleteVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, Comm
_snapshotStoreDao.remove(snapStoreVo.getId());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @weizhouapache, isn't it better to keep the info in the DB for the snapshots and update the State as Destroyed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavkap
is there any benifit ?
the records will be cleaned up by storage garbage collector.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavkap
thanks for testing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weizhouapache, to keep it as history, nothing more

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavkap ah ok, thanks for reply.
the records will be finally cleaned up by storage garbage collector (by default run once every day). They will be kept for only 1 day.
The behaviour is not changed by this PR. It was introduced by 336df84 and ccb68e1

}
}
snapshotApiService.markVolumeSnapshotsAsDestroyed(vo);
} else {
vo.processEvent(Event.OperationFailed);
apiResult.setResult(result.getResult());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -1543,4 +1544,16 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName,
_resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize()));
return snapshot;
}

@Override
public void markVolumeSnapshotsAsDestroyed(Volume volume) {
List<SnapshotVO> snapshots = _snapshotDao.listByVolumeId(volume.getId());
for (SnapshotVO snapshot: snapshots) {
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshot.getId());
if (CollectionUtils.isEmpty(snapshotDataStoreVOs)) {
snapshot.setState(Snapshot.State.Destroyed);
_snapshotDao.update(snapshot.getId(), snapshot);
}
}
}
}