cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mike-tutkowski <...@git.apache.org>
Subject [GitHub] cloudstack pull request: Taking fast and efficient volume snapshot...
Date Sat, 09 Apr 2016 05:19:14 GMT
Github user mike-tutkowski commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1403#discussion_r59110681
  
    --- Diff: engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
---
    @@ -255,99 +448,153 @@ private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(SnapshotInfo
snap
     
                 VolumeApiResult result = future.get();
     
    +            if (volumeDetail != null) {
    +                _volumeDetailsDao.remove(volumeDetail.getId());
    +            }
    +
                 if (result.isFailed()) {
                     s_logger.debug("Failed to create a volume: " + result.getResult());
     
                     throw new CloudRuntimeException(result.getResult());
                 }
    -        }
    -        catch (Exception ex) {
    -            throw new CloudRuntimeException(ex.getMessage());
    -        }
     
    -        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    +            volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
     
    -        volumeInfo.processEvent(Event.MigrationRequested);
    +            volumeInfo.processEvent(Event.MigrationRequested);
     
    -        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    +            volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
     
    -        HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    +            if (useCloning) {
    +                copyCmdAnswer = performResignature(volumeInfo, hostVO);
    +            }
    +            else {
    +                // asking for a XenServer host here so we don't always prefer to use
XenServer hosts that support resigning
    +                // even when we don't need those hosts to do this kind of copy work
    +                hostVO = getHost(snapshotInfo.getDataCenterId(), false);
     
    -        String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    -        int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    -        CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(),
primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    +                copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
    +            }
     
    -        CopyCmdAnswer copyCmdAnswer = null;
    +            if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
    +                if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails()))
{
    +                    errMsg = copyCmdAnswer.getDetails();
    +                }
    +                else {
    +                    errMsg = "Unable to perform host-side operation";
    +                }
    +            }
    +        }
    +        catch (Exception ex) {
    +            errMsg = ex.getMessage() != null ? ex.getMessage() : "Copy operation failed";
    +        }
     
    -        try {
    -            _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
    -            _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
    +        CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
     
    -            Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()),
snapshotInfo);
    +        result.setResult(errMsg);
     
    -            copyCommand.setOptions(srcDetails);
    +        callback.complete(result);
    +    }
     
    -            Map<String, String> destDetails = getVolumeDetails(volumeInfo);
    +    /**
    +     * If the underlying storage system is making use of read-only snapshots, this gives
the storage system the opportunity to
    +     * create a volume from the snapshot so that we can copy the VHD file that should
be inside of the snapshot to secondary storage.
    +     *
    +     * The resultant volume must be writable because we need to resign the SR and the
VDI that should be inside of it before we copy
    +     * the VHD file to secondary storage.
    +     *
    +     * If the storage system is using writable snapshots, then nothing need be done by
that storage system here because we can just
    +     * resign the SR and the VDI that should be inside of the snapshot before copying
the VHD file to secondary storage.
    +     */
    +    private void createVolumeFromSnapshot(HostVO hostVO, SnapshotInfo snapshotInfo, boolean
keepGrantedAccess) {
    +        SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(),
"tempVolume", "create");
     
    -            copyCommand.setOptions2(destDetails);
    -
    -            copyCmdAnswer = (CopyCmdAnswer)_agentMgr.send(hostVO.getId(), copyCommand);
    -        }
    -        catch (Exception ex) {
    -            throw new CloudRuntimeException(ex.getMessage());
    +        try {
    +            snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(),
snapshotInfo, null);
             }
             finally {
    -            try {
    -                _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
    -            }
    -            catch (Exception ex) {
    -                s_logger.debug(ex.getMessage(), ex);
    -            }
    -
    -            try {
    -                _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
    -            }
    -            catch (Exception ex) {
    -                s_logger.debug(ex.getMessage(), ex);
    -            }
    +            _snapshotDetailsDao.remove(snapshotDetails.getId());
             }
     
    -        String errMsg = null;
    +        CopyCmdAnswer copyCmdAnswer = performResignature(snapshotInfo, hostVO, keepGrantedAccess);
     
             if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
    -            if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null &&
!copyCmdAnswer.getDetails().isEmpty()) {
    -                errMsg = copyCmdAnswer.getDetails();
    +            if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails()))
{
    +                throw new CloudRuntimeException(copyCmdAnswer.getDetails());
                 }
                 else {
    -                errMsg = "Unable to perform host-side operation";
    +                throw new CloudRuntimeException("Unable to perform host-side operation");
                 }
             }
    +    }
     
    -        CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    +    /**
    +     * If the underlying storage system needed to create a volume from a snapshot for
createVolumeFromSnapshot(HostVO, SnapshotInfo), then
    +     * this is its opportunity to delete that temporary volume and restore properties
in snapshot_details to the way they were before the
    +     * invocation of createVolumeFromSnapshot(HostVO, SnapshotInfo).
    +     */
    +    private void deleteVolumeFromSnapshot(SnapshotInfo snapshotInfo) {
    +        SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(),
"tempVolume", "delete");
     
    -        result.setResult(errMsg);
    +        try {
    +            snapshotInfo.getDataStore().getDriver().createAsync(snapshotInfo.getDataStore(),
snapshotInfo, null);
    +        }
    +        finally {
    +            _snapshotDetailsDao.remove(snapshotDetails.getId());
    +        }
    +    }
     
    -        callback.complete(result);
    +    private SnapshotDetailsVO handleSnapshotDetails(long csSnapshotId, String name, String
value) {
    +        _snapshotDetailsDao.removeDetail(csSnapshotId, name);
     
    -        return null;
    +        SnapshotDetailsVO snapshotDetails = new SnapshotDetailsVO(csSnapshotId, name,
value, false);
    +
    +        return _snapshotDetailsDao.persist(snapshotDetails);
         }
     
    -    private Map<String, String> getSnapshotDetails(StoragePoolVO storagePoolVO,
SnapshotInfo snapshotInfo) {
    -        Map<String, String> details = new HashMap<String, String>();
    +    private boolean canStorageSystemCreateVolumeFromVolume(SnapshotInfo snapshotInfo)
{
    +        boolean supportsCloningVolumeFromVolume = false;
     
    -        details.put(DiskTO.STORAGE_HOST, storagePoolVO.getHostAddress());
    -        details.put(DiskTO.STORAGE_PORT, String.valueOf(storagePoolVO.getPort()));
    +        DataStore dataStore = _dataStoreMgr.getDataStore(snapshotInfo.getDataStore().getId(),
DataStoreRole.Primary);
     
    -        long snapshotId = snapshotInfo.getId();
    +        Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
     
    -        details.put(DiskTO.IQN, getProperty(snapshotId, DiskTO.IQN));
    +        if (mapCapabilities != null) {
    +            String value = mapCapabilities.get(DataStoreCapabilities.CAN_CREATE_VOLUME_FROM_VOLUME.toString());
     
    -        details.put(DiskTO.CHAP_INITIATOR_USERNAME, getProperty(snapshotId, DiskTO.CHAP_INITIATOR_USERNAME));
    -        details.put(DiskTO.CHAP_INITIATOR_SECRET, getProperty(snapshotId, DiskTO.CHAP_INITIATOR_SECRET));
    -        details.put(DiskTO.CHAP_TARGET_USERNAME, getProperty(snapshotId, DiskTO.CHAP_TARGET_USERNAME));
    -        details.put(DiskTO.CHAP_TARGET_SECRET, getProperty(snapshotId, DiskTO.CHAP_TARGET_SECRET));
    +            supportsCloningVolumeFromVolume = new Boolean(value);
    +        }
     
    -        return details;
    +        return supportsCloningVolumeFromVolume;
    +    }
    +
    +    private boolean computeClusterSupportsResign(long clusterId) {
    +        List<HostVO> hosts = _hostDao.findByClusterId(clusterId);
    +
    +        if (hosts == null) {
    +            return false;
    +        }
    +
    +        for (HostVO host : hosts) {
    +            if (host == null) {
    +                return false;
    +            }
    +
    +            DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "supportsResign");
    +
    +            if (hostDetail == null) {
    +                return false;
    +            }
    +
    +            String value = hostDetail.getValue();
    +
    +            Boolean booleanValue = Boolean.valueOf(value);
    +
    +            if (booleanValue == false) {
    +                return false;
    +            }
    +        }
    --- End diff --
    
    Are you thinking a new SQL statement like this? By the way, it looks like the editor pulls
out the star that is inside of the parenthesis of my count functions.
    
    Select count(*) = (Select count(*) From cloud.host Where cluster_id = 1) 
    From cloud.host_details 
    Where name = "supportsResign" 
      and value = "true" 
      and host_id in (Select id From cloud.host Where cluster_id = 1)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message