Source:
<code>private void cleanupLeftOverJobs(final long msid) { try { Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { _queueMgr.cleanupActiveQueueItems(msid, true); List<AsyncJobVO> jobs = _jobDao.getResetJobs(msid); for (AsyncJobVO job : jobs) { if (s_logger.isDebugEnabled()) { s_logger.debug("Cancel left-over job-" + job.getId()); } job.setStatus(JobInfo.Status.FAILED); job.setResultCode(ApiErrorCode.INTERNAL_ERROR.getHttpCode()); job.setResult("job cancelled because of management server restart or shutdown"); job.setCompleteMsid(msid); _jobDao.update(job.getId(), job); if (s_logger.isDebugEnabled()) { s_logger.debug("Purge queue item for cancelled job-" + job.getId()); } <START> List<SnapshotVO> snapshotList = _snapshotDao.listAllByStatus(Snapshot.State.BackingUp); <END> for (SnapshotVO snapshotVO : snapshotList) { SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotVO.getId(), DataStoreRole.Primary); snapshotSrv.processEventOnSnapshotObject(snapshot, Snapshot.Event.OperationFailed); } _queueMgr.purgeAsyncJobQueueItemId(job.getId()); } } }); } catch (Throwable e) { s_logger.warn("Unexpected exception in cleaning up left over jobs for mamagement server node " + msid, e); } }</code><technical_language>cleanupLeftOverJobs() takes msid input, of while cleaning snapshots in 'backing up' state. current logic of handling snapshots issues in a setup more 1 MS</technical_language>

Target:
private void cleanupLeftOverJobs(final long msid) { try { Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { _queueMgr.cleanupActiveQueueItems(msid, true); List<AsyncJobVO> jobs = _jobDao.getResetJobs(msid); for (AsyncJobVO job : jobs) { if (s_logger.isDebugEnabled()) { s_logger.debug("Cancel left-over job-" + job.getId()); } job.setStatus(JobInfo.Status.FAILED); job.setResultCode(ApiErrorCode.INTERNAL_ERROR.getHttpCode()); job.setResult("job cancelled because of management server restart or shutdown"); job.setCompleteMsid(msid); _jobDao.update(job.getId(), job); if (s_logger.isDebugEnabled()) { s_logger.debug("Purge queue item for cancelled job-" + job.getId()); } _queueMgr.purgeAsyncJobQueueItemId(job.getId()); if (job.getInstanceType().equals(ApiCommandJobType.Volume.toString())) { try { _volumeDetailsDao.removeDetail(job.getInstanceId(), "SNAPSHOT_ID"); _volsDao.remove(job.getInstanceId()); } catch (Exception e) { s_logger.error("Unexpected exception while removing concurrent request meta data :" + e.getLocalizedMessage()); } } } List<SnapshotDetailsVO> snapshotList = _snapshotDetailsDao.findDetails(AsyncJob.Constants.MS_ID, Long.toString(msid), false); for (SnapshotDetailsVO snapshotDetailsVO : snapshotList) { SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotDetailsVO.getResourceId(), DataStoreRole.Primary); snapshotSrv.processEventOnSnapshotObject(snapshot, Snapshot.Event.OperationFailed); _snapshotDetailsDao.removeDetail(snapshotDetailsVO.getResourceId(), AsyncJob.Constants.MS_ID); } } }); } catch (Throwable e) { s_logger.warn("Unexpected exception in cleaning up left over jobs for mamagement server node " + msid, e); } }