Skip to content

Commit 74bd9ed

Browse files
sureshanapartidhslove
authored andcommitted
Cleanup snapshot files in datastores for Error-ed snapshots, and some code improvements (apache#12347)
1 parent 8592426 commit 74bd9ed

19 files changed

Lines changed: 124 additions & 78 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public interface SnapshotDataFactory {
3030

3131
SnapshotInfo getSnapshot(long snapshotId, long storeId, DataStoreRole role);
3232

33+
SnapshotInfo getSnapshotIncludingRemoved(long snapshotId, long storeId, DataStoreRole role);
34+
3335
SnapshotInfo getSnapshotWithRoleAndZone(long snapshotId, DataStoreRole role, long zoneId);
3436

3537
SnapshotInfo getSnapshotOnPrimaryStore(long snapshotId);

engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snap
4747

4848
List<SnapshotVO> listAllByStatus(Snapshot.State... status);
4949

50+
List<SnapshotVO> listAllByStatusIncludingRemoved(Snapshot.State... status);
51+
5052
void updateVolumeIds(long oldVolId, long newVolId);
5153

5254
List<SnapshotVO> listByStatusNotIn(long volumeId, Snapshot.State... status);

engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDaoImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ public List<SnapshotVO> listAllByStatus(Snapshot.State... status) {
272272
return listBy(sc, null);
273273
}
274274

275+
@Override
276+
public List<SnapshotVO> listAllByStatusIncludingRemoved(Snapshot.State... status) {
277+
SearchCriteria<SnapshotVO> sc = StatusSearch.create();
278+
sc.setParameters("status", (Object[])status);
279+
return listIncludingRemovedBy(sc, null);
280+
}
281+
275282
@Override
276283
public List<SnapshotVO> listByIds(Object... ids) {
277284
SearchCriteria<SnapshotVO> sc = snapshotIdsSearch.create();

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Lo
7676

7777
List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId);
7878

79+
List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId);
80+
7981
void duplicateCacheRecordsOnRegionStore(long storeId);
8082

8183
// delete the snapshot entry on primary data store to make sure that next snapshot will be full snapshot

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,14 @@ public List<SnapshotDataStoreVO> findByVolume(long snapshotId, long volumeId, Da
464464

465465
@Override
466466
public List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId) {
467-
SearchCriteria<SnapshotDataStoreVO> sc = idStateNinSearch.create();
467+
SearchCriteria<SnapshotDataStoreVO> sc = searchFilteringStoreIdEqStateEqStoreRoleEqIdEqUpdateCountEqSnapshotIdEqVolumeIdEq.create();
468+
sc.setParameters(SNAPSHOT_ID, snapshotId);
469+
return listBy(sc);
470+
}
471+
472+
@Override
473+
public List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId) {
474+
SearchCriteria<SnapshotDataStoreVO> sc = idStateNeqSearch.create();
468475
sc.setParameters(SNAPSHOT_ID, snapshotId);
469476
sc.setParameters(STATE, State.Destroyed.name());
470477
return listBy(sc);

engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/SnapshotTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void setUp() {
269269
to.setSize(1000L);
270270
CopyCmdAnswer answer = new CopyCmdAnswer(to);
271271
templateOnStore.processEvent(Event.CreateOnlyRequested);
272-
templateOnStore.processEvent(Event.OperationSuccessed, answer);
272+
templateOnStore.processEvent(Event.OperationSucceeded, answer);
273273

274274
}
275275

engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void setUp() {
244244
to.setSize(100L);
245245
CopyCmdAnswer answer = new CopyCmdAnswer(to);
246246
templateOnStore.processEvent(Event.CreateOnlyRequested);
247-
templateOnStore.processEvent(Event.OperationSuccessed, answer);
247+
templateOnStore.processEvent(Event.OperationSucceeded, answer);
248248

249249
}
250250

engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeTestVmware.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void setUp() {
247247
to.setPath(this.getImageInstallPath());
248248
CopyCmdAnswer answer = new CopyCmdAnswer(to);
249249
templateOnStore.processEvent(Event.CreateOnlyRequested);
250-
templateOnStore.processEvent(Event.OperationSuccessed, answer);
250+
templateOnStore.processEvent(Event.OperationSucceeded, answer);
251251

252252
}
253253

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public boolean deleteSnapshot(Long snapshotId, Long zoneId) {
303303
}
304304

305305
if (Snapshot.State.Error.equals(snapshotVO.getState())) {
306-
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
306+
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
307307
List<Long> deletedRefs = new ArrayList<>();
308308
for (SnapshotDataStoreVO ref : storeRefs) {
309309
boolean refZoneIdMatch = false;
@@ -436,6 +436,9 @@ protected Boolean deleteSnapshotInfo(SnapshotInfo snapshotInfo, SnapshotVO snaps
436436
DataStore dataStore = snapshotInfo.getDataStore();
437437
String storageToString = String.format("%s {uuid: \"%s\", name: \"%s\"}", dataStore.getRole().name(), dataStore.getUuid(), dataStore.getName());
438438
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotIdAndNotInDestroyedHiddenState(snapshotVo.getId());
439+
if (CollectionUtils.isEmpty(snapshotStoreRefs)) {
440+
snapshotStoreRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotVo.getId());
441+
}
439442
boolean isLastSnapshotRef = CollectionUtils.isEmpty(snapshotStoreRefs) || snapshotStoreRefs.size() == 1;
440443
try {
441444
SnapshotObject snapshotObject = castSnapshotInfoToSnapshotObject(snapshotInfo);

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public List<SnapshotInfo> getSnapshots(long snapshotId, Long zoneId) {
9494
if (snapshot == null) { //snapshot may have been removed;
9595
return new ArrayList<>();
9696
}
97-
List<SnapshotDataStoreVO> allSnapshotsAndDataStore = snapshotStoreDao.findBySnapshotId(snapshotId);
97+
List<SnapshotDataStoreVO> allSnapshotsAndDataStore = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
9898
if (CollectionUtils.isEmpty(allSnapshotsAndDataStore)) {
9999
return new ArrayList<>();
100100
}
@@ -118,7 +118,23 @@ public SnapshotInfo getSnapshot(long snapshotId, long storeId, DataStoreRole rol
118118
if (snapshot == null) {
119119
return null;
120120
}
121-
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(role, storeId, snapshotId);
121+
return getSnapshotOnStore(snapshot, storeId, role);
122+
}
123+
124+
@Override
125+
public SnapshotInfo getSnapshotIncludingRemoved(long snapshotId, long storeId, DataStoreRole role) {
126+
SnapshotVO snapshot = snapshotDao.findByIdIncludingRemoved(snapshotId);
127+
if (snapshot == null) {
128+
return null;
129+
}
130+
return getSnapshotOnStore(snapshot, storeId, role);
131+
}
132+
133+
private SnapshotInfo getSnapshotOnStore(SnapshotVO snapshot, long storeId, DataStoreRole role) {
134+
if (snapshot == null) {
135+
return null;
136+
}
137+
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(role, storeId, snapshot.getId());
122138
if (snapshotStore == null) {
123139
return null;
124140
}
@@ -207,7 +223,7 @@ public List<SnapshotInfo> listSnapshotOnCache(long snapshotId) {
207223

208224
@Override
209225
public void updateOperationFailed(long snapshotId) throws NoTransitionException {
210-
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
226+
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
211227
for (SnapshotDataStoreVO snapshotStoreRef : snapshotStoreRefs) {
212228
SnapshotInfo snapshotInfo = getSnapshot(snapshotStoreRef.getSnapshotId(), snapshotStoreRef.getDataStoreId(), snapshotStoreRef.getRole());
213229
if (snapshotInfo != null) {

0 commit comments

Comments
 (0)