Skip to content

Commit 5db5dd9

Browse files
committed
fix snapshot chain and merge regression
1 parent b869913 commit 5db5dd9

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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
@@ -51,6 +51,8 @@ public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Lo
5151

5252
SnapshotDataStoreVO findBySnapshotIdAndDataStoreRoleAndState(long snapshotId, DataStoreRole role, ObjectInDataStoreStateMachine.State state);
5353

54+
List<SnapshotDataStoreVO> findBySnapshotIdAndDataStoreRoleAndStateIn(long snapshotId, DataStoreRole role, ObjectInDataStoreStateMachine.State... state);
55+
5456
List<SnapshotDataStoreVO> listReadyByVolumeIdAndCheckpointPathNotNull(long volumeId);
5557

5658
SnapshotDataStoreVO findOneBySnapshotId(long snapshotId, long zoneId);

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
6868
protected SearchBuilder<SnapshotDataStoreVO> searchFilteringStoreIdEqStateEqStoreRoleEqIdEqUpdateCountEqSnapshotIdEqVolumeIdEq;
6969
private SearchBuilder<SnapshotDataStoreVO> stateSearch;
7070
private SearchBuilder<SnapshotDataStoreVO> idStateNeqSearch;
71+
72+
private SearchBuilder<SnapshotDataStoreVO> idStateNinSearch;
73+
private SearchBuilder<SnapshotDataStoreVO> idEqRoleEqStateInSearch;
7174
protected SearchBuilder<SnapshotVO> snapshotVOSearch;
7275
private SearchBuilder<SnapshotDataStoreVO> snapshotCreatedSearch;
7376
private SearchBuilder<SnapshotDataStoreVO> dataStoreAndInstallPathSearch;
@@ -151,6 +154,16 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
151154
idStateNeqSearch.and(STATE, idStateNeqSearch.entity().getState(), SearchCriteria.Op.NEQ);
152155
idStateNeqSearch.done();
153156

157+
idStateNinSearch = createSearchBuilder();
158+
idStateNinSearch.and(SNAPSHOT_ID, idStateNinSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
159+
idStateNinSearch.and(STATE, idStateNinSearch.entity().getState(), SearchCriteria.Op.NOTIN);
160+
idStateNinSearch.done();
161+
162+
idEqRoleEqStateInSearch = createSearchBuilder();
163+
idEqRoleEqStateInSearch.and(SNAPSHOT_ID, idEqRoleEqStateInSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
164+
idEqRoleEqStateInSearch.and(STORE_ROLE, idEqRoleEqStateInSearch.entity().getRole(), SearchCriteria.Op.EQ);
165+
idEqRoleEqStateInSearch.and(STATE, idEqRoleEqStateInSearch.entity().getState(), SearchCriteria.Op.IN);
166+
154167
snapshotVOSearch = snapshotDao.createSearchBuilder();
155168
snapshotVOSearch.and(VOLUME_ID, snapshotVOSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
156169
snapshotVOSearch.done();
@@ -387,6 +400,15 @@ public SnapshotDataStoreVO findBySnapshotIdAndDataStoreRoleAndState(long snapsho
387400
return findOneBy(sc);
388401
}
389402

403+
@Override
404+
public List<SnapshotDataStoreVO> findBySnapshotIdAndDataStoreRoleAndStateIn(long snapshotId, DataStoreRole role, State... state) {
405+
SearchCriteria<SnapshotDataStoreVO> sc = idEqRoleEqStateInSearch.create();
406+
sc.setParameters(SNAPSHOT_ID, snapshotId);
407+
sc.setParameters(STORE_ROLE, role);
408+
sc.setParameters(STATE, (Object[])state);
409+
return listBy(sc);
410+
}
411+
390412
@Override
391413
public SnapshotDataStoreVO findOneBySnapshotId(long snapshotId, long zoneId) {
392414
try (TransactionLegacy transactionLegacy = TransactionLegacy.currentTxn()) {
@@ -488,7 +510,7 @@ public List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snap
488510

489511
@Override
490512
public List<SnapshotDataStoreVO> findBySnapshotIdAndNotInDestroyedHiddenState(long snapshotId) {
491-
SearchCriteria<SnapshotDataStoreVO> sc = idStateNeqSearch.create();
513+
SearchCriteria<SnapshotDataStoreVO> sc = idStateNinSearch.create();
492514
sc.setParameters(SNAPSHOT_ID, snapshotId);
493515
sc.setParameters(STATE, State.Destroyed.name(), State.Hidden.name());
494516
return listBy(sc);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase {
120120
private final List<Snapshot.State> snapshotStatesAbleToDeleteSnapshot = Arrays.asList(Snapshot.State.Destroying, Snapshot.State.Destroyed, Snapshot.State.Error, Snapshot.State.Hidden);
121121

122122
public SnapshotDataStoreVO getSnapshotImageStoreRef(long snapshotId, long zoneId) {
123-
List<SnapshotDataStoreVO> snaps = snapshotStoreDao.listReadyBySnapshot(snapshotId, DataStoreRole.Image);
123+
List<SnapshotDataStoreVO> snaps = snapshotStoreDao.findBySnapshotIdAndDataStoreRoleAndStateIn(snapshotId, DataStoreRole.Image, State.Ready, State.Hidden);
124124
for (SnapshotDataStoreVO ref : snaps) {
125125
if (zoneId == dataStoreMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole())) {
126126
return ref;

0 commit comments

Comments
 (0)