Skip to content
Draft
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 @@ -2384,7 +2384,7 @@ public Pair<List<String>, Set<String>> getVolumeCheckpointPathsAndImageStoreUrls
Set<Long> imageStoreIds = new HashSet<>();
Set<String> imageStoreUrls = new HashSet<>();
if (HypervisorType.KVM.equals(hypervisorType)) {
List<SnapshotDataStoreVO> snapshotDataStoreVos = _snapshotDataStoreDao.listReadyByVolumeIdAndCheckpointPathNotNull(volumeId);
List<SnapshotDataStoreVO> snapshotDataStoreVos = _snapshotDataStoreDao.listReadyOrHiddenByVolumeIdAndCheckpointPathNotNull(volumeId);
snapshotDataStoreVos.forEach(snapshotDataStoreVO -> {
checkpointPaths.add(snapshotDataStoreVO.getKvmCheckpointPath());
if (DataStoreRole.Image.equals(snapshotDataStoreVO.getRole())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public void getVolumeCheckpointPathsAndImageStoreUrlsTestReturnCheckpointIfKVM()
snapshotDataStoreVO.setKvmCheckpointPath("Test");
snapshotDataStoreVO.setRole(DataStoreRole.Primary);

Mockito.doReturn(List.of(snapshotDataStoreVO)).when(snapshotDataStoreDaoMock).listReadyByVolumeIdAndCheckpointPathNotNull(Mockito.anyLong());
Mockito.doReturn(List.of(snapshotDataStoreVO)).when(snapshotDataStoreDaoMock).listReadyOrHiddenByVolumeIdAndCheckpointPathNotNull(Mockito.anyLong());

Pair<List<String>, Set<String>> result = volumeOrchestrator.getVolumeCheckpointPathsAndImageStoreUrls(0, Hypervisor.HypervisorType.KVM);

Expand All @@ -656,7 +656,7 @@ public void getVolumeCheckpointPathsAndImageStoreUrlsTestReturnCheckpointIfKVMAn
snapshotDataStoreVO.setRole(DataStoreRole.Image);
snapshotDataStoreVO.setDataStoreId(13);

Mockito.doReturn(List.of(snapshotDataStoreVO)).when(snapshotDataStoreDaoMock).listReadyByVolumeIdAndCheckpointPathNotNull(Mockito.anyLong());
Mockito.doReturn(List.of(snapshotDataStoreVO)).when(snapshotDataStoreDaoMock).listReadyOrHiddenByVolumeIdAndCheckpointPathNotNull(Mockito.anyLong());

ImageStoreVO imageStoreVO = new ImageStoreVO();
imageStoreVO.setUrl("URL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Lo

List<SnapshotDataStoreVO> listBySnapshotIdAndDataStoreRoleAndStateIn(long snapshotId, DataStoreRole role, ObjectInDataStoreStateMachine.State... state);

List<SnapshotDataStoreVO> listReadyByVolumeIdAndCheckpointPathNotNull(long volumeId);
List<SnapshotDataStoreVO> listReadyOrHiddenByVolumeIdAndCheckpointPathNotNull(long volumeId);

SnapshotDataStoreVO findOneBySnapshotId(long snapshotId, long zoneId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
private SearchBuilder<SnapshotDataStoreVO> storeAndSnapshotIdsSearch;
private SearchBuilder<SnapshotDataStoreVO> storeSnapshotDownloadStatusSearch;
private SearchBuilder<SnapshotDataStoreVO> searchFilteringStoreIdInVolumeIdEqStoreRoleEqStateEqKVMCheckpointNotNull;
private SearchBuilder<SnapshotDataStoreVO> searchVolumeIdEqStateInKVMCheckpointNotNull;
private SearchBuilder<SnapshotDataStoreVO> searchFilterStateAndDownloadUrlNotNullAndDownloadUrlCreatedBefore;
private SearchBuilder<SnapshotDataStoreVO> searchFilteringStoreIdInVolumeIdEqStoreRoleEqStateEqPathEq;

Expand Down Expand Up @@ -207,6 +208,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
searchFilteringStoreIdInVolumeIdEqStoreRoleEqStateEqKVMCheckpointNotNull.and(STORE_ID, searchFilteringStoreIdInVolumeIdEqStoreRoleEqStateEqKVMCheckpointNotNull.entity().getDataStoreId(), SearchCriteria.Op.IN);
searchFilteringStoreIdInVolumeIdEqStoreRoleEqStateEqKVMCheckpointNotNull.done();

searchVolumeIdEqStateInKVMCheckpointNotNull = createSearchBuilder();
searchVolumeIdEqStateInKVMCheckpointNotNull.and(VOLUME_ID, searchVolumeIdEqStateInKVMCheckpointNotNull.entity().getVolumeId(), SearchCriteria.Op.EQ);
searchVolumeIdEqStateInKVMCheckpointNotNull.and(STATE, searchVolumeIdEqStateInKVMCheckpointNotNull.entity().getState(), SearchCriteria.Op.IN);
searchVolumeIdEqStateInKVMCheckpointNotNull.and(KVM_CHECKPOINT_PATH, searchVolumeIdEqStateInKVMCheckpointNotNull.entity().getKvmCheckpointPath(), SearchCriteria.Op.NNULL);
searchVolumeIdEqStateInKVMCheckpointNotNull.done();

searchFilterStateAndDownloadUrlNotNullAndDownloadUrlCreatedBefore = createSearchBuilder();
searchFilterStateAndDownloadUrlNotNullAndDownloadUrlCreatedBefore.and(STATE, searchFilterStateAndDownloadUrlNotNullAndDownloadUrlCreatedBefore.entity().getState(), SearchCriteria.Op.EQ);
searchFilterStateAndDownloadUrlNotNullAndDownloadUrlCreatedBefore.and(DOWNLOAD_URL, searchFilterStateAndDownloadUrlNotNullAndDownloadUrlCreatedBefore.entity().getExtractUrl(), SearchCriteria.Op.NNULL);
Expand Down Expand Up @@ -714,11 +721,11 @@ protected boolean isSnapshotChainingRequired(long volumeId, boolean kvmIncrement
}

@Override
public List<SnapshotDataStoreVO> listReadyByVolumeIdAndCheckpointPathNotNull(long volumeId) {
SearchCriteria<SnapshotDataStoreVO> sc = searchFilteringStoreIdInVolumeIdEqStoreRoleEqStateEqKVMCheckpointNotNull.create();
public List<SnapshotDataStoreVO> listReadyOrHiddenByVolumeIdAndCheckpointPathNotNull(long volumeId) {
SearchCriteria<SnapshotDataStoreVO> sc = searchVolumeIdEqStateInKVMCheckpointNotNull.create();
sc.setParameters(VOLUME_ID, volumeId);
sc.setParameters(STATE, State.Ready);
return listBy(sc);
sc.setParameters(STATE, State.Ready, State.Hidden);
return listBy(sc, new Filter(SnapshotDataStoreVO.class, "id", true, null, null));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public StrategyPriority canHandle(Long vmId, Long rootPoolId, boolean snapshotMe
}

for (VolumeVO volume : volumeDao.findByInstance(vmId)) {
List<SnapshotDataStoreVO> snapshots = snapshotDataStoreDao.listReadyByVolumeIdAndCheckpointPathNotNull(volume.getId());
List<SnapshotDataStoreVO> snapshots = snapshotDataStoreDao.listReadyOrHiddenByVolumeIdAndCheckpointPathNotNull(volume.getId());
if (CollectionUtils.isNotEmpty(snapshots)) {
logger.debug(
"{} as VM has a volume with incremental snapshots {}. Incremental volume snapshots and StorageVmSnapshotStrategy are not compatible," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,12 @@ protected EndPoint getEndPointForBitmapRemoval(DataObject object, boolean encryp
VirtualMachine attachedVM = volumeInfo.getAttachedVM();
if (attachedVM.getHostId() != null) {
return getEndPointFromHostId(attachedVM.getHostId());
} else if (attachedVM.getLastHostId() != null) {
}
EndPoint clvmEp = tryRouteToClvmLockHolder(volumeInfo, _storagePoolDao.findById(volumeInfo.getPoolId()), "bitmap removal");
if (clvmEp != null) {
return clvmEp;
}
if (attachedVM.getLastHostId() != null) {
return getEndPointFromHostId(attachedVM.getLastHostId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,51 @@ public void getEndPointForBitmapRemovalTestVolumeIsAttachedNoHostIsSet() {
Mockito.verify(defaultEndPointSelectorSpy, Mockito.times(1)).select(volumeInfoMock, false);
}

private void mockClvmVolumeOfStoppedVm(Long lockHostId) {
Mockito.doReturn(STORE_ID).when(volumeInfoMock).getPoolId();
Mockito.when(_storagePoolDao.findById(STORE_ID)).thenReturn(storagePoolVOMock);
Mockito.when(storagePoolVOMock.getPoolType()).thenReturn(StoragePoolType.CLVM_NG);
Mockito.doReturn(lockHostId).when(defaultEndPointSelectorSpy).getClvmLockHostId(volumeInfoMock);
Mockito.doReturn(true).when(volumeInfoMock).isAttachedVM();
Mockito.doReturn(virtualMachineMock).when(volumeInfoMock).getAttachedVM();
Mockito.doReturn(null).when(virtualMachineMock).getHostId();
Mockito.doReturn(HOST_ID).when(virtualMachineMock).getLastHostId();
}

@Test
public void getEndPointForBitmapRemovalTestClvmVolumeOfStoppedVmRoutesToLockHolderInsteadOfLastHost() {
mockClvmVolumeOfStoppedVm(DEST_HOST_ID);
Mockito.doReturn(endPointMock).when(defaultEndPointSelectorSpy).getEndPointFromHostId(DEST_HOST_ID);

EndPoint result = defaultEndPointSelectorSpy.getEndPointForBitmapRemoval(snapshotInfoMock, false);

assertEquals(endPointMock, result);
Mockito.verify(defaultEndPointSelectorSpy, Mockito.never()).getEndPointFromHostId(HOST_ID);
}

@Test
public void getEndPointForBitmapRemovalTestClvmVolumeOfStoppedVmWithoutLockHolderFallsBackToLastHost() {
mockClvmVolumeOfStoppedVm(null);
Mockito.doReturn(endPointMock).when(defaultEndPointSelectorSpy).getEndPointFromHostId(HOST_ID);

EndPoint result = defaultEndPointSelectorSpy.getEndPointForBitmapRemoval(snapshotInfoMock, false);

assertEquals(endPointMock, result);
}

@Test
public void getEndPointForBitmapRemovalTestClvmVolumeOfRunningVmUsesVmHostWithoutLockLookup() {
Mockito.doReturn(true).when(volumeInfoMock).isAttachedVM();
Mockito.doReturn(virtualMachineMock).when(volumeInfoMock).getAttachedVM();
Mockito.doReturn(HOST_ID).when(virtualMachineMock).getHostId();
Mockito.doReturn(endPointMock).when(defaultEndPointSelectorSpy).getEndPointFromHostId(HOST_ID);

EndPoint result = defaultEndPointSelectorSpy.getEndPointForBitmapRemoval(snapshotInfoMock, false);

assertEquals(endPointMock, result);
Mockito.verify(defaultEndPointSelectorSpy, Mockito.never()).getClvmLockHostId(volumeInfoMock);
}

@Test
public void getEndPointForSnapshotOperationsInKvmTestVolumeIsNotAttachedToVMAndSnapshotOnPrimary() {
Mockito.doReturn(null).when(volumeInfoMock).getAttachedVM();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,15 @@ public Answer createSnapshot(final CreateObjectCommand cmd) {
String diskPath = disk.getPath();
String snapshotPath = diskPath + File.separator + snapshotName;
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
if (DomainInfo.DomainState.VIR_DOMAIN_RUNNING.equals(state) && !primaryPool.isExternalSnapshot()) {
boolean isClvmNgIncremental = primaryPool.getType() == StoragePoolType.CLVM_NG && snapshotTO.isKvmIncrementalSnapshot();
if (isClvmNgIncremental && secondaryPool == null) {
String errorMsg = String.format("Incremental snapshots for CLVM_NG require secondary storage. " +
"Please configure secondary storage or disable incremental snapshots for volume [%s].", volume.getName());
logger.error(errorMsg);
return new CreateObjectAnswer(errorMsg);
}
boolean isLiveClvmNgIncremental = isClvmNgIncremental && (DomainInfo.DomainState.VIR_DOMAIN_RUNNING.equals(state) || DomainInfo.DomainState.VIR_DOMAIN_PAUSED.equals(state));
if ((DomainInfo.DomainState.VIR_DOMAIN_RUNNING.equals(state) && !primaryPool.isExternalSnapshot()) || isLiveClvmNgIncremental) {
if (snapshotTO.isKvmIncrementalSnapshot()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not required.

newSnapshot = takeIncrementalVolumeSnapshotOfRunningVm(snapshotTO, primaryPool, secondaryPool, imageStoreTo != null ? imageStoreTo.getUrl() : null, snapshotName, volume, vm, conn, cmd.getWait());
} else {
Expand All @@ -2111,13 +2119,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) {
newSnapshot.setPhysicalSize(snapshotSize);
}
} else if (primaryPool.getType() == StoragePoolType.CLVM || primaryPool.getType() == StoragePoolType.CLVM_NG) {
if (primaryPool.getType() == StoragePoolType.CLVM_NG && snapshotTO.isKvmIncrementalSnapshot()) {
if (secondaryPool == null) {
String errorMsg = String.format("Incremental snapshots for CLVM_NG require secondary storage. " +
"Please configure secondary storage or disable incremental snapshots for volume [%s].", volume.getName());
logger.error(errorMsg);
return new CreateObjectAnswer(errorMsg);
}
if (isClvmNgIncremental) {
logger.info("Taking incremental snapshot of CLVM_NG volume [{}] using QCOW2 backup to secondary storage.", volume.getName());
newSnapshot = takeIncrementalVolumeSnapshotOfStoppedVm(snapshotTO, primaryPool, secondaryPool,
imageStoreTo.getUrl(), snapshotName, volume, conn, cmd.getWait());
Comment on lines +2122 to 2125

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is a false positive - there's a guard before. So no NPE.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,16 +1649,17 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
boolean backupSnapToSecondary = isBackupSnapshotToSecondaryForZone(volume.getDataCenterId());

StoragePoolType poolType = volume.getStoragePoolType();
boolean isClvmNgIncrementalCandidate = StoragePoolType.CLVM_NG == poolType && backupSnapToSecondary && kvmIncrementalSnapshot.valueIn(clusterId);

updateSnapshotPayload(volume.getPoolId(), payload, isKvmAndFileBasedStorage, poolType, clusterId);
updateSnapshotPayload(volume.getPoolId(), payload, isKvmAndFileBasedStorage, isClvmNgIncrementalCandidate, clusterId);

// NetApp ONTAP managed PRIMARY snapshots remain on primary/array storage (FlexVol).
// They must not use secondary archive bookkeeping (postSnapshotDirectlyToSecondary) or a physical
// secondary copy — delete is handled via StorageSystemSnapshotStrategy → driver deleteAsync.
boolean archiveSnapshotToSecondary = backupSnapToSecondary
&& !isOntapManagedPrimaryLocationSnapshot(storagePool, payload);

if (isKvmAndFileBasedStorage && archiveSnapshotToSecondary) {
if ((isKvmAndFileBasedStorage || isClvmNgIncrementalCandidate) && archiveSnapshotToSecondary) {
DataStore imageStore = snapshotSrv.findSnapshotImageStore(snapshot);
if (imageStore == null) {
throw new CloudRuntimeException(String.format("Could not find any secondary storage to allocate snapshot [%s].", snapshot));
Expand All @@ -1681,7 +1682,7 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
SnapshotInfo snapshotOnPrimary = snapshotStrategy.takeSnapshot(snapshot);

if (archiveSnapshotToSecondary) {
if (!isKvmAndFileBasedStorage) {
if (!isKvmAndFileBasedStorage && !isClvmNgIncrementalCandidate) {
Comment thread
Pearl1594 marked this conversation as resolved.
Resolved
backupSnapshotToSecondary(payload.getAsyncBackup(), snapshotStrategy, snapshotOnPrimary, payload.getZoneIds(), payload.getStoragePoolIds());
Comment thread
Pearl1594 marked this conversation as resolved.
Resolved
if (!payload.getAsyncBackup() && ClvmPoolManager.isClvmPoolType(storagePool.getPoolType())) {
_snapshotStoreDao.removeBySnapshotStore(snapshotId, snapshotOnPrimary.getDataStore().getId(), snapshotOnPrimary.getDataStore().getRole());
Expand Down Expand Up @@ -1714,7 +1715,7 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
snapshotZoneDao.addSnapshotToZone(snapshotId, snapshot.getDataCenterId());

DataStoreRole dataStoreRole;
if (payload.getAsyncBackup() && archiveSnapshotToSecondary && !isKvmAndFileBasedStorage) {
if (payload.getAsyncBackup() && archiveSnapshotToSecondary && !isKvmAndFileBasedStorage && !isClvmNgIncrementalCandidate) {
dataStoreRole = DataStoreRole.Primary;
} else {
dataStoreRole = archiveSnapshotToSecondary ? snapshotHelper.getDataStoreRole(snapshot) : DataStoreRole.Primary;
Expand All @@ -1739,6 +1740,8 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
if (CollectionUtils.isNotEmpty(payload.getStoragePoolIds())) {
copyNewSnapshotToZonesOnPrimary(payload, snapshot);
}
} else if (isClvmNgIncrementalCandidate && archiveSnapshotToSecondary) {
copyNewSnapshotToZones(snapshotId, snapshot.getDataCenterId(), payload.getZoneIds());
}
} catch (Exception e) {
logger.debug("post process snapshot failed", e);
Expand Down Expand Up @@ -1913,7 +1916,7 @@ void removeClvmPrimarySnapshotStoreRefIfNeeded(SnapshotInfo snapshotOnPrimary) {
}
}

private void updateSnapshotPayload(long storagePoolId, CreateSnapshotPayload payload, boolean isKvmAndFileBasedStorage, StoragePoolType poolType, Long clusterId) {
private void updateSnapshotPayload(long storagePoolId, CreateSnapshotPayload payload, boolean isKvmAndFileBasedStorage, boolean isClvmNgIncrementalCandidate, Long clusterId) {
StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);

if (storagePoolVO.isManaged()) {
Expand All @@ -1926,7 +1929,7 @@ private void updateSnapshotPayload(long storagePoolId, CreateSnapshotPayload pay
payload.setLocationType(null);
}

if (isKvmAndFileBasedStorage && kvmIncrementalSnapshot.valueIn(clusterId)) {
if ((isKvmAndFileBasedStorage && kvmIncrementalSnapshot.valueIn(clusterId)) || isClvmNgIncrementalCandidate) {
payload.setKvmIncrementalSnapshot(true);
}
}
Expand Down
Loading