Skip to content

Commit 5a67fe7

Browse files
CLOUDSTACK-7842: wrong size column is getting updated with snapshot physical size in snapshot_store_ref table.
Also fixed the issue that snapshot size with hypervisor XS >= 6.2.5 is not getting updated in snapshot_store_ref table.
1 parent 6490694 commit 5a67fe7

5 files changed

Lines changed: 17 additions & 12 deletions

File tree

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answe
288288
snapshotStore.setInstallPath(snapshotTO.getPath());
289289
if (snapshotTO.getPhysicalSize() != null) {
290290
// For S3 delta snapshot, physical size is currently not set
291-
snapshotStore.setSize(snapshotTO.getPhysicalSize());
291+
snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize());
292292
}
293293
if (snapshotTO.getParentSnapshotPath() == null) {
294294
snapshotStore.setParentSnapshotId(0L);

engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public DataObject create(DataObject obj, DataStore dataStore) {
116116
ss.setRole(dataStore.getRole());
117117
ss.setVolumeId(snapshotInfo.getVolumeId());
118118
ss.setSize(snapshotInfo.getSize()); // this is the virtual size of snapshot in primary storage.
119+
ss.setPhysicalSize(snapshotInfo.getSize()); // this physical size will get updated with actual size once the snapshot backup is done.
119120
SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
120121
if (snapshotDataStoreVO != null) {
121122
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
@@ -156,7 +157,7 @@ public DataObject create(DataObject obj, DataStore dataStore) {
156157
ss.setSnapshotId(obj.getId());
157158
ss.setDataStoreId(dataStore.getId());
158159
ss.setRole(dataStore.getRole());
159-
ss.setRole(dataStore.getRole());
160+
ss.setSize(snapshot.getSize());
160161
ss.setVolumeId(snapshot.getVolumeId());
161162
SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshot.getVolumeId());
162163
if (snapshotDataStoreVO != null) {

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, St
329329
}
330330
}
331331
}
332-
String backupUuid = dvdi.getUuid(conn);
333-
return backupUuid;
332+
String result = dvdi.getUuid(conn).concat("#").concat(dvdi.getPhysicalUtilisation(conn).toString());
333+
return result;
334334
} catch (Exception e) {
335335
String msg = "Exception in backupsnapshot stage due to " + e.toString();
336336
s_logger.debug(msg);
@@ -392,6 +392,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
392392
String details = null;
393393
String snapshotBackupUuid = null;
394394
boolean fullbackup = Boolean.parseBoolean(options.get("fullSnapshot"));
395+
Long physicalSize = null;
395396
try {
396397
SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
397398
if (primaryStorageSR == null) {
@@ -431,6 +432,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
431432
hypervisorResource.checkForSuccess(conn, task);
432433
VDI backedVdi = Types.toVDI(task, conn);
433434
snapshotBackupUuid = backedVdi.getUuid(conn);
435+
physicalSize = backedVdi.getPhysicalUtilisation(conn);
434436

435437
if( destStore instanceof SwiftTO) {
436438
try {
@@ -488,9 +490,11 @@ public Answer backupSnapshot(CopyCommand cmd) {
488490
throw new CloudRuntimeException("S3 upload of snapshots " + snapshotPaUuid + " failed");
489491
}
490492
} else {
491-
snapshotBackupUuid = backupSnapshot(conn, primaryStorageSRUuid, localMountPoint, folder,
493+
String result = backupSnapshot(conn, primaryStorageSRUuid, localMountPoint, folder,
492494
secondaryStorageMountPath, snapshotUuid, prevBackupUuid, prevSnapshotUuid, isISCSI, wait);
493-
495+
String[] tmp = result.split("#");
496+
snapshotBackupUuid = tmp[0];
497+
physicalSize = Long.parseLong(tmp[1]);
494498
finalPath = folder + File.separator + snapshotBackupUuid;
495499
}
496500
}
@@ -499,6 +503,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
499503

500504
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
501505
newSnapshot.setPath(finalPath);
506+
newSnapshot.setPhysicalSize(physicalSize);
502507
if (fullbackup) {
503508
newSnapshot.setParentSnapshotPath(null);
504509
} else {

server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
198198
templateSizeSearch.done();
199199

200200
snapshotSizeSearch = _snapshotDataStoreDao.createSearchBuilder(SumCount.class);
201-
snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getSize());
201+
snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getPhysicalSize());
202202
snapshotSizeSearch.and("state", snapshotSizeSearch.entity().getState(), Op.EQ);
203203
snapshotSizeSearch.and("storeRole", snapshotSizeSearch.entity().getRole(), Op.EQ);
204204
SearchBuilder<SnapshotVO> join2 = _snapshotDao.createSearchBuilder();

server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public boolean deleteSnapshot(long snapshotId) {
434434
if (snapshotCheck.getState() != Snapshot.State.Error && snapshotCheck.getState() != Snapshot.State.Destroyed)
435435
_resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.snapshot);
436436
if (snapshotCheck.getState() == Snapshot.State.BackedUp)
437-
_resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize()));
437+
_resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getPhysicalSize()));
438438
}
439439
return result;
440440
} catch (Exception e) {
@@ -624,7 +624,7 @@ public boolean deleteSnapshotDirsForAccount(long accountId) {
624624
if (Type.MANUAL == snapshot.getRecurringType()) {
625625
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.snapshot);
626626
if (snapshotStoreRef != null) {
627-
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize()));
627+
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshotStoreRef.getPhysicalSize()));
628628
}
629629
}
630630

@@ -973,11 +973,10 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
973973
try {
974974
postCreateSnapshot(volume.getId(), snapshotId, payload.getSnapshotPolicyId());
975975
SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image);
976-
// FIXME - snapshotStoreRef.getSize() refers to physical size, correct that
977976
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(),
978-
null, null, snapshotStoreRef.getSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
977+
null, null, snapshotStoreRef.getPhysicalSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
979978
// Correct the resource count of snapshot in case of delta snapshots.
980-
_resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getSize()));
979+
_resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getPhysicalSize()));
981980
} catch (Exception e) {
982981
s_logger.debug("post process snapshot failed", e);
983982
}

0 commit comments

Comments
 (0)