Skip to content
Open
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
61 changes: 37 additions & 24 deletions storage/src/main/java/org/zstack/storage/volume/VolumeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3408,7 +3408,16 @@ public void run(FlowTrigger trigger, Map data) {
VolumeEncryptionConversionContext ctx = conversionContext.get();
updateVolumeEncryptionConversionInDb(targetEncrypted, ctx.snapshots, ctx.oldAndNewInstallPaths,
(Map<String, Long>) data.get("actualSizes"));
refreshVO();
try {
refreshVO();
} catch (RuntimeException e) {
logger.warn(String.format("failed to refresh volume[uuid:%s] after encryption conversion DB update: %s",
self.getUuid(), e.getMessage()), e);
VolumeVO latest = dbf.findByUuid(self.getUuid(), VolumeVO.class);
if (latest != null) {
self = latest;
}
}
trigger.next();
}

Expand Down Expand Up @@ -3741,34 +3750,38 @@ private void deleteConvertedVolumeEncryptionBits(List<ConvertVolumeEncryptionOnP
}
}

@Transactional
private void updateVolumeEncryptionConversionInDb(boolean targetEncrypted, List<VolumeSnapshotVO> snapshots,
Map<String, String> oldAndNewInstallPaths,
Map<String, Long> actualSizes) {
VolumeSnapshotReferenceUtils.handleVolumeInstallUrlChange(self.getUuid(), oldAndNewInstallPaths);

UpdateQuery q = SQL.New(VolumeVO.class)
.eq(VolumeVO_.uuid, self.getUuid())
.set(VolumeVO_.installPath, oldAndNewInstallPaths.get(self.getInstallPath()))
.set(VolumeVO_.encrypted, targetEncrypted);
if (actualSizes != null && actualSizes.get(self.getUuid()) != null) {
q.set(VolumeVO_.actualSize, actualSizes.get(self.getUuid()));
}
q.update();
new SQLBatch() {
@Override
protected void scripts() {
VolumeSnapshotReferenceUtils.handleVolumeInstallUrlChange(self.getUuid(), oldAndNewInstallPaths);

UpdateQuery q = SQL.New(VolumeVO.class)
.eq(VolumeVO_.uuid, self.getUuid())
.set(VolumeVO_.installPath, oldAndNewInstallPaths.get(self.getInstallPath()))
.set(VolumeVO_.encrypted, targetEncrypted);
if (actualSizes != null && actualSizes.get(self.getUuid()) != null) {
q.set(VolumeVO_.actualSize, actualSizes.get(self.getUuid()));
}
q.update();

Map<String, String> convertedSnapshotInstallPaths = new LinkedHashMap<>();
for (VolumeSnapshotVO snapshot : snapshots) {
String newPath = oldAndNewInstallPaths.get(snapshot.getPrimaryStorageInstallPath());
if (StringUtils.isBlank(newPath)) {
continue;
}
convertedSnapshotInstallPaths.put(snapshot.getUuid(), newPath);
}
Map<String, String> convertedSnapshotInstallPaths = new LinkedHashMap<>();
for (VolumeSnapshotVO snapshot : snapshots) {
String newPath = oldAndNewInstallPaths.get(snapshot.getPrimaryStorageInstallPath());
if (StringUtils.isBlank(newPath)) {
continue;
}
convertedSnapshotInstallPaths.put(snapshot.getUuid(), newPath);
}

updateConvertedSnapshotPaths(convertedSnapshotInstallPaths, targetEncrypted);
if (targetEncrypted && !convertedSnapshotInstallPaths.isEmpty()) {
volumeEncryptedResourceKeyBackend.copyVolumeKeyRefToSnapshots(self.getUuid(), convertedSnapshotInstallPaths.keySet());
}
updateConvertedSnapshotPaths(convertedSnapshotInstallPaths, targetEncrypted);
if (targetEncrypted && !convertedSnapshotInstallPaths.isEmpty()) {
volumeEncryptedResourceKeyBackend.copyVolumeKeyRefToSnapshots(self.getUuid(), convertedSnapshotInstallPaths.keySet());
}
}
}.execute();
}

private void updateConvertedSnapshotPaths(Map<String, String> snapshotInstallPaths, boolean targetEncrypted) {
Expand Down