JoaoJandre commented on code in PR #12086:
URL: https://github.com/apache/cloudstack/pull/12086#discussion_r2571547124
##########
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java:
##########
@@ -346,20 +370,102 @@ protected Map<Long, Pair<Long, Long>> migrateAway(
executor.setCorePoolSize((int) (totalJobs));
}
- MigrateDataTask task = new MigrateDataTask(chosenFileForMigration,
srcDatastore, dataStoreManager.getDataStore(destDatastoreId,
DataStoreRole.Image));
- if (chosenFileForMigration instanceof SnapshotInfo ) {
+ DataStore destDataStore =
dataStoreManager.getDataStore(destDatastoreId, DataStoreRole.Image);
+
+ boolean isKvmIncrementalSnapshot = chosenFileForMigration instanceof
SnapshotInfo && ((SnapshotInfo)
chosenFileForMigration).isKvmIncrementalSnapshot() &&
snapshotChains.containsKey(chosenFileForMigration);
+
+ if (isKvmIncrementalSnapshot) {
+ MigrateKvmIncrementalSnapshotTask task = new
MigrateKvmIncrementalSnapshotTask(chosenFileForMigration, snapshotChains,
srcDatastore, destDataStore, snapshotIdsToMigrate);
+
futures.add(submitKvmIncrementalMigration(srcDatastore.getScope().getScopeId(),
task));
+ logger.debug("Incremental snapshot migration {} submitted to
incremental pool.", chosenFileForMigration.getUuid());
+ } else {
+ createMigrateDataTask(chosenFileForMigration, snapshotChains,
templateChains, srcDatastore, destDataStore, executor, futures);
+ }
+
+ return storageCapacities;
+ }
+
+ private AsyncCallFuture<DataObjectResult>
migrateKvmIncrementalSnapshotChain(DataObject chosenFileForMigration,
Map<DataObject, Pair<List<SnapshotInfo>, Long>> snapshotChains, DataStore
srcDatastore, DataStore destDataStore, Set<Long> snapshotIdsToMigrate) {
+ return
Transaction.execute((TransactionCallback<AsyncCallFuture<DataObjectResult>>)
status -> {
+ MigrateBetweenSecondaryStoragesCommandAnswer answer = null;
+ AsyncCallFuture<DataObjectResult> future = new AsyncCallFuture<>();
+ DataObjectResult result = new
DataObjectResult(chosenFileForMigration);
+
+ try {
+ List<SnapshotInfo> snapshotChain =
snapshotChains.get(chosenFileForMigration).first();
+ MigrateSnapshotsBetweenSecondaryStoragesCommand
migrateBetweenSecondaryStoragesCmd = new
MigrateSnapshotsBetweenSecondaryStoragesCommand(snapshotChain.stream().map(DataObject::getTO).collect(Collectors.toList()),
srcDatastore.getTO(), destDataStore.getTO(), snapshotIdsToMigrate);
+
+ HostVO host = getAvailableHost(((SnapshotInfo)
chosenFileForMigration).getDataCenterId());
+ if (host == null) {
+ throw new CloudRuntimeException("No suitable hosts found
to send migrate command.");
+ }
+
+
migrateBetweenSecondaryStoragesCmd.setWait(StorageManager.AgentMaxDataMigrationWaitTime.valueIn(host.getClusterId()));
+ answer = (MigrateBetweenSecondaryStoragesCommandAnswer)
agentManager.send(host.getId(), migrateBetweenSecondaryStoragesCmd);
+ if (answer == null || !answer.getResult()) {
+ logger.warn("Unable to migrate snapshots [{}].",
snapshotChain);
+ throw new CloudRuntimeException("Unable to migrate KVM
incremental snapshots to another secondary storage");
+ }
+ } catch (final OperationTimedoutException |
AgentUnavailableException e) {
+ throw new CloudRuntimeException("Error while migrating KVM
incremental snapshot chain. Check the logs for more information.", e);
Review Comment:
We could inform which snapshot failed.
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateSnapshotsBetweenSecondaryStoragesCommandWrapper.java:
##########
@@ -0,0 +1,182 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.hypervisor.kvm.resource.wrapper;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.MigrateSnapshotsBetweenSecondaryStoragesCommand;
+import com.cloud.agent.api.MigrateBetweenSecondaryStoragesCommandAnswer;
+import com.cloud.agent.api.to.DataStoreTO;
+import com.cloud.agent.api.to.DataTO;
+import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
+import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
+import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+import org.apache.cloudstack.utils.qemu.QemuImageOptions;
+import org.apache.cloudstack.utils.qemu.QemuImg;
+import org.apache.cloudstack.utils.qemu.QemuImgException;
+import org.apache.cloudstack.utils.qemu.QemuImgFile;
+import org.libvirt.LibvirtException;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@ResourceWrapper(handles =
MigrateSnapshotsBetweenSecondaryStoragesCommand.class)
+public class LibvirtMigrateSnapshotsBetweenSecondaryStoragesCommandWrapper
extends CommandWrapper<MigrateSnapshotsBetweenSecondaryStoragesCommand, Answer,
LibvirtComputingResource> {
+
+ protected Set<String> filesToRemove;
+ protected List<Pair<Long, String>> resourcesToUpdate;
+ protected String resourceType;
+ protected int wait;
+
+ @Override
+ public Answer execute(MigrateSnapshotsBetweenSecondaryStoragesCommand
command, LibvirtComputingResource serverResource) {
+ filesToRemove = new HashSet<>();
+ resourcesToUpdate = new ArrayList<>();
+ wait = command.getWait() * 1000;
+
+ DataStoreTO srcDataStore = command.getSrcDataStore();
+ DataStoreTO destDataStore = command.getDestDataStore();
+ KVMStoragePoolManager storagePoolManager =
serverResource.getStoragePoolMgr();
+
+ Set<KVMStoragePool> imagePools = new HashSet<>();
+ KVMStoragePool destImagePool =
storagePoolManager.getStoragePoolByURI(destDataStore.getUrl());
+ imagePools.add(destImagePool);
+
+ String imagePoolUrl;
+ KVMStoragePool imagePool = null;
+
+ String parentSnapshotPath = null;
+ boolean parentSnapshotWasMigrated = false;
+ Set<Long> snapshotsIdToMigrate = command.getSnapshotsIdToMigrate();
+
+ try {
+ for (DataTO snapshot : command.getSnapshotChain()) {
+ imagePoolUrl = snapshot.getDataStore().getUrl();
+ imagePool =
storagePoolManager.getStoragePoolByURI(imagePoolUrl);
+ imagePools.add(imagePool);
+
+ String resourceCurrentPath =
imagePool.getLocalPathFor(snapshot.getPath());
+
+ if (imagePoolUrl.equals(srcDataStore.getUrl()) &&
snapshotsIdToMigrate.contains(snapshot.getId())) {
+ parentSnapshotPath = copyResourceToDestDataStore(snapshot,
resourceCurrentPath, destImagePool, parentSnapshotPath);
+ parentSnapshotWasMigrated = true;
+ } else {
+ if (parentSnapshotWasMigrated) {
+ parentSnapshotPath =
rebaseResourceToNewParentPath(resourceCurrentPath, parentSnapshotPath);
+ } else {
+ parentSnapshotPath = resourceCurrentPath;
+ }
+ parentSnapshotWasMigrated = false;
Review Comment:
we could add some logging for these decisions
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]