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 @@ -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 @@
Mockito.verify(defaultEndPointSelectorSpy, Mockito.times(1)).select(volumeInfoMock, false);
}

private void mockClvmVolumeOfStoppedVm(Long lockHostId) {
Mockito.doReturn(STORE_ID).when(volumeInfoMock).getPoolId();

Check warning on line 177 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bK&open=AaHSLmEtussJYe4A13bK&pullRequest=14484
Mockito.when(_storagePoolDao.findById(STORE_ID)).thenReturn(storagePoolVOMock);

Check warning on line 178 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bL&open=AaHSLmEtussJYe4A13bL&pullRequest=14484
Mockito.when(storagePoolVOMock.getPoolType()).thenReturn(StoragePoolType.CLVM_NG);

Check warning on line 179 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bM&open=AaHSLmEtussJYe4A13bM&pullRequest=14484
Mockito.doReturn(lockHostId).when(defaultEndPointSelectorSpy).getClvmLockHostId(volumeInfoMock);

Check warning on line 180 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bN&open=AaHSLmEtussJYe4A13bN&pullRequest=14484
Mockito.doReturn(true).when(volumeInfoMock).isAttachedVM();

Check warning on line 181 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bO&open=AaHSLmEtussJYe4A13bO&pullRequest=14484
Mockito.doReturn(virtualMachineMock).when(volumeInfoMock).getAttachedVM();

Check warning on line 182 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bP&open=AaHSLmEtussJYe4A13bP&pullRequest=14484
Mockito.doReturn(null).when(virtualMachineMock).getHostId();

Check warning on line 183 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bQ&open=AaHSLmEtussJYe4A13bQ&pullRequest=14484
Mockito.doReturn(HOST_ID).when(virtualMachineMock).getLastHostId();

Check warning on line 184 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bR&open=AaHSLmEtussJYe4A13bR&pullRequest=14484
}

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

Check warning on line 190 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bS&open=AaHSLmEtussJYe4A13bS&pullRequest=14484

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

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

Check warning on line 195 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "verify".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bT&open=AaHSLmEtussJYe4A13bT&pullRequest=14484

Check warning on line 195 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "never".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bU&open=AaHSLmEtussJYe4A13bU&pullRequest=14484
}

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

Check warning on line 201 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bV&open=AaHSLmEtussJYe4A13bV&pullRequest=14484

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

assertEquals(endPointMock, result);
}

@Test
public void getEndPointForBitmapRemovalTestClvmVolumeOfRunningVmUsesVmHostWithoutLockLookup() {
Mockito.doReturn(true).when(volumeInfoMock).isAttachedVM();

Check warning on line 210 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bW&open=AaHSLmEtussJYe4A13bW&pullRequest=14484
Mockito.doReturn(virtualMachineMock).when(volumeInfoMock).getAttachedVM();

Check warning on line 211 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bX&open=AaHSLmEtussJYe4A13bX&pullRequest=14484
Mockito.doReturn(HOST_ID).when(virtualMachineMock).getHostId();

Check warning on line 212 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bY&open=AaHSLmEtussJYe4A13bY&pullRequest=14484
Mockito.doReturn(endPointMock).when(defaultEndPointSelectorSpy).getEndPointFromHostId(HOST_ID);

Check warning on line 213 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "doReturn".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bZ&open=AaHSLmEtussJYe4A13bZ&pullRequest=14484

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

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

Check warning on line 218 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "never".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13bb&open=AaHSLmEtussJYe4A13bb&pullRequest=14484

Check warning on line 218 in engine/storage/src/test/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelectorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "verify".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaHSLmEtussJYe4A13ba&open=AaHSLmEtussJYe4A13ba&pullRequest=14484
}

@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()) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@
boolean backupSnapToSecondary = isBackupSnapshotToSecondaryForZone(volume.getDataCenterId());

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

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

Expand All @@ -1658,7 +1659,7 @@
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 @@
SnapshotInfo snapshotOnPrimary = snapshotStrategy.takeSnapshot(snapshot);

if (archiveSnapshotToSecondary) {
if (!isKvmAndFileBasedStorage) {
if (!isKvmAndFileBasedStorage && !isClvmNgIncrementalCandidate) {
backupSnapshotToSecondary(payload.getAsyncBackup(), snapshotStrategy, snapshotOnPrimary, payload.getZoneIds(), payload.getStoragePoolIds());
Comment on lines +1685 to 1686
if (!payload.getAsyncBackup() && ClvmPoolManager.isClvmPoolType(storagePool.getPoolType())) {
_snapshotStoreDao.removeBySnapshotStore(snapshotId, snapshotOnPrimary.getDataStore().getId(), snapshotOnPrimary.getDataStore().getRole());
Expand Down Expand Up @@ -1926,7 +1927,7 @@
payload.setLocationType(null);
}

if (isKvmAndFileBasedStorage && kvmIncrementalSnapshot.valueIn(clusterId)) {
if ((isKvmAndFileBasedStorage || StoragePoolType.CLVM_NG == poolType) && kvmIncrementalSnapshot.valueIn(clusterId)) {

Check warning on line 1930 in server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a primitive boolean expression here.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGZOLqtDeJydjxQUXnA&open=AaGZOLqtDeJydjxQUXnA&pullRequest=14484
payload.setKvmIncrementalSnapshot(true);
}
}
Expand Down
Loading