Skip to content
Open
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 @@ -884,8 +884,8 @@ private void stepDelete(Completion completion) {
return;
}

VolumeTree.VolumeSnapshotLeaf onlineChild = children.stream()
.filter(child -> volumeTree.isOnline(current, currentRoot.getUuid(), child.getUuid(), vmState))
VolumeTree.VolumeSnapshotLeaf aliveChild = children.stream()
.filter(child -> volumeTree.isOnAliveChain(child.getUuid()))
.findFirst().orElse(null);

Completion comp = new Completion(completion) {
Expand All @@ -910,7 +910,7 @@ public void fail(ErrorCode errorCode) {
pull(child, volumeTree, online, comp);
}
} else {
if (onlineChild != null && Objects.equals(child.getUuid(), onlineChild.getUuid())) {
if (aliveChild != null && Objects.equals(child.getUuid(), aliveChild.getUuid())) {
child = children.get(1);
}
boolean online = volumeTree.isOnline(current, currentRoot.getUuid(), child.getUuid(), vmState);
Expand Down
21 changes: 15 additions & 6 deletions storage/src/main/java/org/zstack/storage/snapshot/VolumeTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,19 @@ public List<String> getAliveChainSnapshotUuids() {
return aliveChain.stream().map(VolumeSnapshotInventory::getUuid).collect(Collectors.toList());
}

public boolean isOnAliveChain(String snapshotUuid) {
return current && getAliveChainSnapshotUuids().contains(snapshotUuid);
}

public static boolean isHypervisorOperation(VmInstanceState vmState) {
return vmState == VmInstanceState.Running || vmState == VmInstanceState.Paused;
}

public DeleteVolumeSnapshotDirection resolveDirection(String targetSnapshotUuid, String childSnapshotUuid, String initialDirection,
boolean targetSnapshotIsLatest, VmInstanceState vmState) {
boolean online = (vmState == VmInstanceState.Running || vmState == VmInstanceState.Paused)
&& getAliveChainSnapshotUuids().contains(targetSnapshotUuid) && getAliveChainSnapshotUuids().contains(childSnapshotUuid);

boolean shouldUseCommitStrategy = current && !targetSnapshotIsLatest && online;
boolean targetOnAliveChain = isOnAliveChain(targetSnapshotUuid);
boolean childOnAliveChain = isOnAliveChain(childSnapshotUuid);
boolean shouldUseCommitStrategy = current && !targetSnapshotIsLatest && targetOnAliveChain && childOnAliveChain;

if (Objects.equals(initialDirection, DeleteVolumeSnapshotDirection.Pull.toString()) && shouldUseCommitStrategy) {
throw new IllegalArgumentException("the snapshot will be deleted by block 'commit', but the direction is 'pull', " +
Expand All @@ -387,8 +394,10 @@ public DeleteVolumeSnapshotDirection resolveDirection(String targetSnapshotUuid,
}

public boolean isOnline(boolean treeIsCurrent, String targetSnapshotUuid, String childSnapshotUuid, VmInstanceState vmState) {
return treeIsCurrent && (vmState == VmInstanceState.Running || vmState == VmInstanceState.Paused)
&& getAliveChainSnapshotUuids().contains(targetSnapshotUuid) && getAliveChainSnapshotUuids().contains(childSnapshotUuid);
return treeIsCurrent
&& isHypervisorOperation(vmState)
&& getAliveChainSnapshotUuids().contains(targetSnapshotUuid)
&& getAliveChainSnapshotUuids().contains(childSnapshotUuid);
}

// TODO(clone) : When both chain cloning and single-node snapshot deletion are enabled,
Expand Down