|
59 | 59 | import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; |
60 | 60 | import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; |
61 | 61 | import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; |
| 62 | +import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; |
62 | 63 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; |
63 | 64 | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; |
64 | 65 | import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; |
|
86 | 87 |
|
87 | 88 | import com.cloud.agent.AgentManager; |
88 | 89 | import com.cloud.agent.api.Answer; |
89 | | -import com.cloud.agent.api.CleanupSnapshotBackupCommand; |
90 | 90 | import com.cloud.agent.api.Command; |
| 91 | +import com.cloud.agent.api.DeleteSnapshotBackupCommand; |
91 | 92 | import com.cloud.agent.api.StoragePoolInfo; |
92 | 93 | import com.cloud.agent.api.storage.DeleteTemplateCommand; |
93 | 94 | import com.cloud.agent.api.storage.DeleteVolumeCommand; |
@@ -1174,49 +1175,47 @@ public void cleanupSecondaryStorage(boolean recurring) { |
1174 | 1175 | } |
1175 | 1176 | } |
1176 | 1177 |
|
1177 | | - // Cleanup snapshot in secondary storage hosts |
| 1178 | + // CleanUp snapshots on Secondary Storage. |
1178 | 1179 | for (DataStore store : imageStores) { |
1179 | 1180 | try { |
1180 | | - List<Long> vIDs = findAllVolumeIdInSnapshotTable(store.getId()); |
1181 | | - if (vIDs == null) { |
1182 | | - continue; |
1183 | | - } |
1184 | | - for (Long volumeId : vIDs) { |
1185 | | - boolean lock = false; |
1186 | | - try { |
1187 | | - VolumeVO volume = _volsDao.findByIdIncludingRemoved(volumeId); |
1188 | | - if (volume.getRemoved() == null) { |
1189 | | - volume = _volsDao.acquireInLockTable(volumeId, 10); |
1190 | | - if (volume == null) { |
1191 | | - continue; |
1192 | | - } |
1193 | | - lock = true; |
1194 | | - } |
1195 | | - List<String> snapshots = findAllSnapshotForVolume(volumeId); |
1196 | | - if (snapshots == null) { |
1197 | | - continue; |
1198 | | - } |
1199 | | - EndPoint ep = _epSelector.select(store); |
1200 | | - CleanupSnapshotBackupCommand cmd = new CleanupSnapshotBackupCommand(store.getUri(), store.getScope().getScopeId(), |
1201 | | - volume.getAccountId(), volumeId, snapshots); |
| 1181 | + List<SnapshotDataStoreVO> destroyedSnapshotStoreVOs = _snapshotStoreDao.listDestroyed(store.getId()); |
| 1182 | + s_logger.debug("Secondary storage garbage collector found " + destroyedSnapshotStoreVOs.size() |
| 1183 | + + " snapshots to cleanup on secondary storage host: " + store.getName()); |
| 1184 | + for (SnapshotDataStoreVO destroyedSnapshotStoreVO : destroyedSnapshotStoreVOs) { |
| 1185 | + // check if this snapshot has child |
| 1186 | + SnapshotInfo snap = snapshotFactory.getSnapshot(destroyedSnapshotStoreVO.getSnapshotId(), store); |
| 1187 | + if ( snap.getChild() != null ){ |
| 1188 | + s_logger.debug("Skip snapshot on store: " + destroyedSnapshotStoreVO + " , because it has child"); |
| 1189 | + continue; |
| 1190 | + } |
| 1191 | + |
| 1192 | + if (s_logger.isDebugEnabled()) { |
| 1193 | + s_logger.debug("Deleting snapshot on store: " + destroyedSnapshotStoreVO); |
| 1194 | + } |
1202 | 1195 |
|
| 1196 | + String installPath = destroyedSnapshotStoreVO.getInstallPath(); |
| 1197 | + |
| 1198 | + if (installPath != null) { |
| 1199 | + EndPoint ep = _epSelector.select(store); |
| 1200 | + DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(store.getTO(), store.getUri(), |
| 1201 | + null, null, null, destroyedSnapshotStoreVO.getInstallPath(), false); |
1203 | 1202 | Answer answer = ep.sendMessage(cmd); |
1204 | | - if ((answer == null) || !answer.getResult()) { |
1205 | | - String details = "Failed to cleanup snapshots for volume " + volumeId + " due to " |
1206 | | - + (answer == null ? "null" : answer.getDetails()); |
1207 | | - s_logger.warn(details); |
1208 | | - } |
1209 | | - } catch (Exception e1) { |
1210 | | - s_logger.warn("problem cleaning up snapshots in secondary storage store " + store.getName(), e1); |
1211 | | - } finally { |
1212 | | - if (lock) { |
1213 | | - _volsDao.releaseFromLockTable(volumeId); |
| 1203 | + if (answer == null || !answer.getResult()) { |
| 1204 | + s_logger.debug("Failed to delete " + destroyedSnapshotStoreVO + " due to " |
| 1205 | + + ((answer == null) ? "answer is null" : answer.getDetails())); |
| 1206 | + } else { |
| 1207 | + _volumeStoreDao.remove(destroyedSnapshotStoreVO.getId()); |
| 1208 | + s_logger.debug("Deleted snapshot at: " + destroyedSnapshotStoreVO.getInstallPath()); |
1214 | 1209 | } |
| 1210 | + } else { |
| 1211 | + _snapshotStoreDao.remove(destroyedSnapshotStoreVO.getId()); |
1215 | 1212 | } |
1216 | 1213 | } |
| 1214 | + |
1217 | 1215 | } catch (Exception e2) { |
1218 | 1216 | s_logger.warn("problem cleaning up snapshots in secondary storage store " + store.getName(), e2); |
1219 | 1217 | } |
| 1218 | + |
1220 | 1219 | } |
1221 | 1220 |
|
1222 | 1221 | // CleanUp volumes on Secondary Storage. |
|
0 commit comments