Skip to content

Commit

Permalink
<fix>[xinfini]: try to delete cloned volume which not exist in db
Browse files Browse the repository at this point in the history
Resolves: ZSTAC-70087

Change-Id: I64636a756a6776667067706e7a6e667a796f686d
  • Loading branch information
PandaWuu committed Sep 27, 2024
1 parent 796be69 commit 9b31ef8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Maps;
import org.zstack.core.CoreGlobalProperty;
import org.zstack.core.db.Q;
import org.zstack.core.retry.Retry;
import org.zstack.core.retry.RetryCondition;
import org.zstack.header.core.Completion;
import org.zstack.header.errorcode.OperationFailureException;
import org.zstack.header.volume.VolumeVO;
import org.zstack.header.volume.VolumeVO_;
import org.zstack.header.xinfini.XInfiniConstants;
import org.zstack.utils.CollectionUtils;
import org.zstack.utils.Utils;
Expand Down Expand Up @@ -393,15 +396,38 @@ public void deleteVolume(int volId, boolean force) {
retryUtilResourceDeleted(gReq, GetVolumeResponse.class);
}

public void deleteVolumeAndSnapshot(int volId) {
for (VolumeSnapshotModule mod : queryVolumeSnapshotByVolumeId(volId)) {
deleteVolumeSnapshot(mod.getSpec().getId());
}
deleteVolume(volId, true);
}

public void deleteVolumeSnapshot(int snapShotId) {
// check snapshot cloned volume
QueryVolumeRequest vReq = new QueryVolumeRequest();
vReq.q = String.format("spec.bs_snap_id:%s", snapShotId);
QueryVolumeResponse vRsp = queryErrorOut(vReq, QueryVolumeResponse.class);
if (vRsp.getMetadata().getPagination().getCount() > 0) {
List<String> volNames = vRsp.getItems().stream().map(VolumeModule::getSpec).map(VolumeModule.VolumeSpec::getName).collect(Collectors.toList());
List<String> installPaths = vRsp.getItems().stream()
.map(v -> XInfiniPathHelper.buildXInfiniPath(v.getSpec().getPoolId(), v.getSpec().getId()))
.collect(Collectors.toList());

logger.info(String.format("find cloned volumes paths: %s", installPaths));

throw new OperationFailureException(operr("snapshot %s has %d cloned volumes, volumes names: %s", snapShotId, vRsp.getMetadata().getPagination().getCount(), volNames));
boolean exist = Q.New(VolumeVO.class)
.in(VolumeVO_.installPath, installPaths)
.isExists();

if (exist) {
throw new OperationFailureException(operr("snapshot %s has %d cloned volumes, volumes names: %s", snapShotId, vRsp.getMetadata().getPagination().getCount(), volNames));
}
logger.info("all cloned volumes not exist in database, try to delete them");
// try to delete cloned volumes if not exist in db
for (VolumeModule v : vRsp.getItems()) {
deleteVolumeAndSnapshot(v.getSpec().getId());
}
}

DeleteVolumeSnapshotRequest req = new DeleteVolumeSnapshotRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,7 @@ public void deleteVolume(String installPath, Completion comp) {
@Override
public void deleteVolumeAndSnapshot(String installPath, Completion comp) {
int volId = getVolIdFromPath(installPath);
for (VolumeSnapshotModule mod : apiHelper.queryVolumeSnapshotByVolumeId(volId)) {
apiHelper.deleteVolumeSnapshot(mod.getSpec().getId());
}

apiHelper.deleteVolume(volId, true);
apiHelper.deleteVolumeAndSnapshot(volId);
comp.success();
}

Expand Down

0 comments on commit 9b31ef8

Please sign in to comment.