Skip to content

Commit 3671957

Browse files
Pearl1594Daan Hoogland
authored andcommitted
Use Physical size to evaluate if migration is possible
1 parent 8bc69e9 commit 3671957

6 files changed

Lines changed: 31 additions & 6 deletions

File tree

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public interface DataObject {
3333

3434
Long getSize();
3535

36+
long getPhysicalSize();
37+
3638
DataObjectType getType();
3739

3840
String getUuid();

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected void checkIfCompleteMigrationPossible(ImageStoreService.MigrationPolic
114114
}
115115

116116
protected Long getFileSize(DataObject file, Map<DataObject, Pair<List<SnapshotInfo>, Long>> snapshotChain) {
117-
Long size = file.getSize();
117+
Long size = file.getPhysicalSize();
118118
Pair<List<SnapshotInfo>, Long> chain = snapshotChain.get(file);
119119
if (file instanceof SnapshotInfo && chain.first() != null && !chain.first().isEmpty()) {
120120
size = chain.second();
@@ -159,8 +159,8 @@ protected List<DataObject> sortFilesOnSize(List<DataObject> files, Map<DataObjec
159159
Collections.sort(files, new Comparator<DataObject>() {
160160
@Override
161161
public int compare(DataObject o1, DataObject o2) {
162-
Long size1 = o1.getSize();
163-
Long size2 = o2.getSize();
162+
Long size1 = o1.getPhysicalSize();
163+
Long size2 = o2.getPhysicalSize();
164164
if (o1 instanceof SnapshotInfo) {
165165
size1 = snapshotChains.get(o1).second();
166166
}
@@ -226,7 +226,7 @@ protected List<DataObject> getAllReadySnapshotsAndChains(DataStore srcDataStore,
226226
protected Long getSizeForChain(List<SnapshotInfo> chain) {
227227
Long size = 0L;
228228
for (SnapshotInfo snapshot : chain) {
229-
size += snapshot.getSize();
229+
size += snapshot.getPhysicalSize();
230230
}
231231
return size;
232232
}

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ public MigrationResponse migrateData(Long srcDataStoreId, List<Long> destDatasto
194194
destDatastoreId = orderedDS.get(1);
195195
}
196196

197-
if (chosenFileForMigration.getSize() > storageCapacities.get(destDatastoreId).first()) {
198-
s_logger.debug("file: " + chosenFileForMigration.getId() + " too large to be migrated to " + destDatastoreId);
197+
if (chosenFileForMigration.getPhysicalSize() > storageCapacities.get(destDatastoreId).first()) {
198+
s_logger.debug("file: " + chosenFileForMigration.getUuid() + " too large to be migrated to " + destDatastoreId);
199199
continue;
200200
}
201201

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ public Long getSize() {
141141
return image.getSize();
142142
}
143143

144+
@Override
145+
public long getPhysicalSize() {
146+
TemplateDataStoreVO templateDataStoreVO = templateStoreDao.findByTemplate(imageVO.getId(), DataStoreRole.Image);
147+
if (templateDataStoreVO != null) {
148+
return templateDataStoreVO.getPhysicalSize();
149+
}
150+
return imageVO.getSize();
151+
}
152+
144153
@Override
145154
public DataObjectType getType() {
146155
return DataObjectType.TEMPLATE;

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ protected DiskOfferingVO getDiskOfferingVO() {
231231
return diskOfferingId == null ? null : diskOfferingDao.findById(diskOfferingId);
232232
}
233233

234+
@Override
235+
public long getPhysicalSize() {
236+
VolumeDataStoreVO volumeDataStoreVO = volumeStoreDao.findByVolume(volumeVO.getId());
237+
if (volumeDataStoreVO != null) {
238+
return volumeDataStoreVO.getPhysicalSize();
239+
}
240+
return volumeVO.getSize();
241+
}
242+
234243
@Override
235244
public Long getBytesReadRate() {
236245
return getLongValueFromDiskOfferingVoMethod(DiskOfferingVO::getBytesReadRate);

server/src/main/java/org/apache/cloudstack/diagnostics/to/DiagnosticsDataObject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public Long getSize() {
5959
return null;
6060
}
6161

62+
@Override
63+
public long getPhysicalSize() {
64+
return 0;
65+
}
66+
6267
@Override
6368
public DataObjectType getType() {
6469
return dataTO.getObjectType();

0 commit comments

Comments
 (0)