Skip to content

Commit 79c00ba

Browse files
committed
cleanup
1 parent 3935803 commit 79c00ba

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,12 +2308,12 @@ protected void cleanupSnapshotRecordsInPrimaryStorageOnly(VolumeVO volume) {
23082308
if (Snapshot.State.Destroyed.equals(snapshot.getState())) {
23092309
continue;
23102310
}
2311-
List<SnapshotDataStoreVO> primaryRefs = _snapshotStoreDao.listBySnapshotAndDataStoreRole(snapshot.getId(), DataStoreRole.Primary);
2312-
List<SnapshotDataStoreVO> secondaryRefs = _snapshotStoreDao.listBySnapshotAndDataStoreRole(snapshot.getId(), DataStoreRole.Image);
2313-
if (CollectionUtils.isNotEmpty(primaryRefs) && CollectionUtils.isEmpty(secondaryRefs)) {
2311+
List<SnapshotDataStoreVO> snapshotsOnPrimaryStorage = _snapshotStoreDao.listBySnapshotAndDataStoreRole(snapshot.getId(), DataStoreRole.Primary);
2312+
List<SnapshotDataStoreVO> snapshotsOnSecondaryStorage = _snapshotStoreDao.listBySnapshotAndDataStoreRole(snapshot.getId(), DataStoreRole.Image);
2313+
if (CollectionUtils.isNotEmpty(snapshotsOnPrimaryStorage) && CollectionUtils.isEmpty(snapshotsOnSecondaryStorage)) {
23142314
logger.info("Cleaning up snapshot {} (primary-only, no secondary copy) as volume {} is being deleted", snapshot, volume);
2315-
for (SnapshotDataStoreVO ref : primaryRefs) {
2316-
_snapshotStoreDao.expunge(ref.getId());
2315+
for (SnapshotDataStoreVO snapshotOnPrimaryStorage : snapshotsOnPrimaryStorage) {
2316+
_snapshotStoreDao.expunge(snapshotOnPrimaryStorage.getId());
23172317
}
23182318
snapshot.setState(Snapshot.State.Destroyed);
23192319
_snapshotDao.update(snapshot.getId(), snapshot);

server/src/test/java/com/cloud/storage/StorageManagerImplTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,9 +1735,9 @@ public void testCleanupSnapshotRecordsInPrimaryStorageOnly() {
17351735
Mockito.when(snapshot.getState()).thenReturn(Snapshot.State.BackedUp);
17361736
Mockito.when(snapshotDao.listByVolumeId(1L)).thenReturn(List.of(snapshot));
17371737

1738-
SnapshotDataStoreVO primaryRef = Mockito.mock(SnapshotDataStoreVO.class);
1739-
Mockito.when(primaryRef.getId()).thenReturn(100L);
1740-
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Primary)).thenReturn(List.of(primaryRef));
1738+
SnapshotDataStoreVO snapshotOnPrimaryStorage = Mockito.mock(SnapshotDataStoreVO.class);
1739+
Mockito.when(snapshotOnPrimaryStorage.getId()).thenReturn(100L);
1740+
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Primary)).thenReturn(List.of(snapshotOnPrimaryStorage));
17411741
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Image)).thenReturn(Collections.emptyList());
17421742

17431743
storageManagerImpl.cleanupSnapshotRecordsInPrimaryStorageOnly(volume);
@@ -1757,10 +1757,10 @@ public void testCleanupSnapshotRecordsInPrimaryStorageOnlySkipsWhenSecondaryExis
17571757
Mockito.when(snapshot.getState()).thenReturn(Snapshot.State.BackedUp);
17581758
Mockito.when(snapshotDao.listByVolumeId(1L)).thenReturn(List.of(snapshot));
17591759

1760-
SnapshotDataStoreVO primaryRef = Mockito.mock(SnapshotDataStoreVO.class);
1761-
SnapshotDataStoreVO secondaryRef = Mockito.mock(SnapshotDataStoreVO.class);
1762-
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Primary)).thenReturn(List.of(primaryRef));
1763-
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Image)).thenReturn(List.of(secondaryRef));
1760+
SnapshotDataStoreVO snapshotOnPrimaryStorage = Mockito.mock(SnapshotDataStoreVO.class);
1761+
SnapshotDataStoreVO snapshotOnSecondaryStorage = Mockito.mock(SnapshotDataStoreVO.class);
1762+
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Primary)).thenReturn(List.of(snapshotOnPrimaryStorage));
1763+
Mockito.when(snapshotStoreDao.listBySnapshotAndDataStoreRole(10L, DataStoreRole.Image)).thenReturn(List.of(snapshotOnSecondaryStorage));
17641764

17651765
storageManagerImpl.cleanupSnapshotRecordsInPrimaryStorageOnly(volume);
17661766

0 commit comments

Comments
 (0)