Skip to content

Commit 04b58ac

Browse files
Merge branch '4.22'
2 parents 8b2f1f1 + 3828a3b commit 04b58ac

File tree

22 files changed

+162
-104
lines changed

22 files changed

+162
-104
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
@@ -265,6 +265,13 @@ public List<SnapshotVO> listAllByStatus(Snapshot.State... status) {
265265
return listBy(sc, null);
266266
}
267267

268+
@Override
269+
public List<SnapshotVO> listAllByStatusIncludingRemoved(Snapshot.State... status) {
270+
SearchCriteria<SnapshotVO> sc = StatusSearch.create();
271+
sc.setParameters("status", (Object[])status);
272+
return listIncludingRemovedBy(sc, null);
273+
}
274+
268275
@Override
269276
public List<SnapshotVO> listByIds(Object... ids) {
270277
SearchCriteria<SnapshotVO> sc = snapshotIdsSearch.create();

engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage
5252
private static final String DELETE_ALL = "DELETE FROM cloud_usage";
5353
private static final String DELETE_ALL_BY_ACCOUNTID = "DELETE FROM cloud_usage WHERE account_id = ?";
5454
private static final String DELETE_ALL_BY_INTERVAL = "DELETE FROM cloud_usage WHERE end_date < DATE_SUB(CURRENT_DATE(), INTERVAL ? DAY)";
55-
private static final String INSERT_ACCOUNT = "INSERT INTO cloud_usage.account (id, account_name, type, role_id, domain_id, removed, cleanup_needed) VALUES (?,?,?,?,?,?,?)";
55+
private static final String INSERT_ACCOUNT = "INSERT INTO cloud_usage.account (id, account_name, uuid, type, role_id, domain_id, removed, cleanup_needed) VALUES (?,?,?,?,?,?,?,?)";
5656
private static final String INSERT_USER_STATS = "INSERT INTO cloud_usage.user_statistics (id, data_center_id, account_id, public_ip_address, device_id, device_type, network_id, net_bytes_received,"
5757
+ " net_bytes_sent, current_bytes_received, current_bytes_sent, agg_bytes_received, agg_bytes_sent) VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?)";
5858

@@ -129,25 +129,26 @@ public void saveAccounts(List<AccountVO> accounts) {
129129
for (AccountVO acct : accounts) {
130130
pstmt.setLong(1, acct.getId());
131131
pstmt.setString(2, acct.getAccountName());
132-
pstmt.setInt(3, acct.getType().ordinal());
132+
pstmt.setString(3, acct.getUuid());
133+
pstmt.setInt(4, acct.getType().ordinal());
133134

134135
//prevent autoboxing NPE by defaulting to User role
135136
if(acct.getRoleId() == null){
136-
pstmt.setLong(4, RoleType.User.getId());
137+
pstmt.setLong(5, RoleType.User.getId());
137138
}else{
138-
pstmt.setLong(4, acct.getRoleId());
139+
pstmt.setLong(5, acct.getRoleId());
139140
}
140141

141-
pstmt.setLong(5, acct.getDomainId());
142+
pstmt.setLong(6, acct.getDomainId());
142143

143144
Date removed = acct.getRemoved();
144145
if (removed == null) {
145-
pstmt.setString(6, null);
146+
pstmt.setString(7, null);
146147
} else {
147-
pstmt.setString(6, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), acct.getRemoved()));
148+
pstmt.setString(7, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), acct.getRemoved()));
148149
}
149150

150-
pstmt.setBoolean(7, acct.getNeedsCleanup());
151+
pstmt.setBoolean(8, acct.getNeedsCleanup());
151152

152153
pstmt.addBatch();
153154
}

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

465465
@Override
466466
public List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId) {
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) {
467474
SearchCriteria<SnapshotDataStoreVO> sc = idStateNinSearch.create();
468475
sc.setParameters(SNAPSHOT_ID, snapshotId);
469476
sc.setParameters(STATE, State.Destroyed.name());

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
@@ -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;

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) {

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,14 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
474474
if (res.isFailed()) {
475475
throw new CloudRuntimeException(res.getResult());
476476
}
477-
SnapshotInfo destSnapshot = res.getSnapshot();
478-
return destSnapshot;
477+
return res.getSnapshot();
479478
} catch (InterruptedException e) {
480479
logger.debug("failed copy snapshot", e);
481480
throw new CloudRuntimeException("Failed to copy snapshot", e);
482481
} catch (ExecutionException e) {
483482
logger.debug("Failed to copy snapshot", e);
484483
throw new CloudRuntimeException("Failed to copy snapshot", e);
485484
}
486-
487485
}
488486

489487
protected Void copySnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, CopySnapshotContext<CommandResult> context) {
@@ -571,7 +569,6 @@ protected Void prepareCopySnapshotZoneAsyncCallback(AsyncCallbackDispatcher<Snap
571569
}
572570

573571
protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, DeleteSnapshotContext<CommandResult> context) {
574-
575572
CommandResult result = callback.getResult();
576573
AsyncCallFuture<SnapshotResult> future = context.future;
577574
SnapshotInfo snapshot = context.snapshot;
@@ -729,7 +726,7 @@ public void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) {
729726

730727
if (snapshot != null) {
731728
if (snapshot.getState() != Snapshot.State.BackedUp) {
732-
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId);
729+
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
733730
for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) {
734731
logger.debug("Remove snapshot {}, status {} on snapshot_store_ref table with id: {}", snapshot, snapshotDataStoreVO.getState(), snapshotDataStoreVO.getId());
735732

@@ -834,7 +831,6 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
834831
SnapshotObject srcSnapshot = (SnapshotObject)snapshot;
835832
srcSnapshot.processEvent(Event.DestroyRequested);
836833
srcSnapshot.processEvent(Event.OperationSucceeded);
837-
838834
srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
839835

840836
_snapshotDetailsDao.removeDetail(srcSnapshot.getId(), AsyncJob.Constants.MS_ID);
@@ -845,7 +841,6 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
845841
}
846842
}
847843
});
848-
849844
}
850845

851846
@Override

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ public void postSnapshotCreation(SnapshotInfo snapshot) {
541541
logger.warn("Failed to clean up snapshot '" + snapshot.getId() + "' on primary storage: " + e.getMessage());
542542
}
543543
}
544-
545544
}
546545

547546
private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) {

0 commit comments

Comments
 (0)