Skip to content

Commit f1f779a

Browse files
Cleanup snapshot files in datastores for Error-ed snapshots, and some code improvements (#12347)
1 parent aba3285 commit f1f779a

File tree

19 files changed

+122
-87
lines changed

19 files changed

+122
-87
lines changed

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
@@ -252,6 +252,13 @@ public List<SnapshotVO> listAllByStatus(Snapshot.State... status) {
252252
return listBy(sc, null);
253253
}
254254

255+
@Override
256+
public List<SnapshotVO> listAllByStatusIncludingRemoved(Snapshot.State... status) {
257+
SearchCriteria<SnapshotVO> sc = StatusSearch.create();
258+
sc.setParameters("status", (Object[])status);
259+
return listIncludingRemovedBy(sc, null);
260+
}
261+
255262
@Override
256263
public List<SnapshotVO> listByIds(Object... ids) {
257264
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
@@ -56,6 +56,8 @@ public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Lo
5656

5757
List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId);
5858

59+
List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId);
60+
5961
void duplicateCacheRecordsOnRegionStore(long storeId);
6062

6163
// 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ public List<SnapshotDataStoreVO> findByVolume(long snapshotId, long volumeId, Da
340340

341341
@Override
342342
public List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId) {
343+
SearchCriteria<SnapshotDataStoreVO> sc = searchFilteringStoreIdEqStateEqStoreRoleEqIdEqUpdateCountEqSnapshotIdEqVolumeIdEq.create();
344+
sc.setParameters(SNAPSHOT_ID, snapshotId);
345+
return listBy(sc);
346+
}
347+
348+
@Override
349+
public List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId) {
343350
SearchCriteria<SnapshotDataStoreVO> sc = idStateNeqSearch.create();
344351
sc.setParameters(SNAPSHOT_ID, snapshotId);
345352
sc.setParameters(STATE, State.Destroyed);

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
@@ -268,7 +268,7 @@ public void setUp() {
268268
to.setSize(1000L);
269269
CopyCmdAnswer answer = new CopyCmdAnswer(to);
270270
templateOnStore.processEvent(Event.CreateOnlyRequested);
271-
templateOnStore.processEvent(Event.OperationSuccessed, answer);
271+
templateOnStore.processEvent(Event.OperationSucceeded, answer);
272272

273273
}
274274

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
@@ -246,7 +246,7 @@ public void setUp() {
246246
to.setPath(this.getImageInstallPath());
247247
CopyCmdAnswer answer = new CopyCmdAnswer(to);
248248
templateOnStore.processEvent(Event.CreateOnlyRequested);
249-
templateOnStore.processEvent(Event.OperationSuccessed, answer);
249+
templateOnStore.processEvent(Event.OperationSucceeded, answer);
250250

251251
}
252252

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public boolean deleteSnapshot(Long snapshotId, Long zoneId) {
270270
}
271271

272272
if (Snapshot.State.Error.equals(snapshotVO.getState())) {
273-
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
273+
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
274274
List<Long> deletedRefs = new ArrayList<>();
275275
for (SnapshotDataStoreVO ref : storeRefs) {
276276
boolean refZoneIdMatch = false;
@@ -351,7 +351,7 @@ protected boolean deleteSnapshotInfos(SnapshotVO snapshotVo, Long zoneId) {
351351
protected Boolean deleteSnapshotInfo(SnapshotInfo snapshotInfo, SnapshotVO snapshotVo) {
352352
DataStore dataStore = snapshotInfo.getDataStore();
353353
String storageToString = String.format("%s {uuid: \"%s\", name: \"%s\"}", dataStore.getRole().name(), dataStore.getUuid(), dataStore.getName());
354-
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotId(snapshotVo.getId());
354+
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotVo.getId());
355355
boolean isLastSnapshotRef = CollectionUtils.isEmpty(snapshotStoreRefs) || snapshotStoreRefs.size() == 1;
356356
try {
357357
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)