Source:
<code>private void addOrUpdateSnapshots(Guid clusterId, List<GlusterVolumeSnapshotEntity> fetchedSnapshots) { Map<Guid, GlusterVolumeSnapshotEntity> fetchedSnapshotsMap = new HashMap<>(); for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) { fetchedSnapshotsMap.put(fetchedSnapshot.getId(), fetchedSnapshot); } List<GlusterVolumeSnapshotEntity> existingSnapshots = getGlusterVolumeSnapshotDao().getAllByClusterId(clusterId); Map<Guid, GlusterVolumeSnapshotEntity> existingSnapshotsMap = new HashMap<>(); for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) { existingSnapshotsMap.put(existingSnapshot.getId(), existingSnapshot); } try { List<GlusterVolumeSnapshotEntity> updatedSnapshots = new ArrayList<>(); List<GlusterVolumeSnapshotEntity> newlyAddedSnapshots = new ArrayList<>(); List<GlusterVolumeSnapshotEntity> deletedSnapshots = new ArrayList<>(); for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) { GlusterVolumeSnapshotEntity correspondingExistingSnapshot = existingSnapshotsMap.get(fetchedSnapshot.getId()); if (correspondingExistingSnapshot == null) { newlyAddedSnapshots.add(fetchedSnapshot); } else if (correspondingExistingSnapshot.getStatus() != fetchedSnapshot.getStatus()) { correspondingExistingSnapshot.setStatus(fetchedSnapshot.getStatus()); updatedSnapshots.add(correspondingExistingSnapshot); } } for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) { GlusterVolumeSnapshotEntity correspondingFetchedSnapshot = fetchedSnapshotsMap.get(existingSnapshot.getId()); if (correspondingFetchedSnapshot == null) { deletedSnapshots.add(existingSnapshot); } } <START> acquireLock(clusterId); <END> try { saveNewSnapshots(newlyAddedSnapshots); updateSnapshots(updatedSnapshots); deleteSnapshots(deletedSnapshots); } finally { releaseLock(clusterId); } } catch (Exception e) { log.error("Exception ocuured while adding/updating snapshots from CLI - '{}'", e.getMessage()); log.debug("Exception", e); throw new VdcBLLException(VdcBllErrors.GlusterSnapshotInfoFailedException, e.getLocalizedMessage()); } }</code><technical_language>a cluster level lock</technical_language>

Target:
private void addOrUpdateSnapshots(Guid clusterId, List<GlusterVolumeSnapshotEntity> fetchedSnapshots) { Map<Guid, GlusterVolumeSnapshotEntity> fetchedSnapshotsMap = new HashMap<>(); for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) { fetchedSnapshotsMap.put(fetchedSnapshot.getId(), fetchedSnapshot); } List<GlusterVolumeSnapshotEntity> existingSnapshots = getGlusterVolumeSnapshotDao().getAllByClusterId(clusterId); Map<Guid, GlusterVolumeSnapshotEntity> existingSnapshotsMap = new HashMap<>(); for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) { existingSnapshotsMap.put(existingSnapshot.getId(), existingSnapshot); } List<GlusterVolumeSnapshotEntity> updatedSnapshots = new ArrayList<>(); List<GlusterVolumeSnapshotEntity> newlyAddedSnapshots = new ArrayList<>(); List<GlusterVolumeSnapshotEntity> deletedSnapshots = new ArrayList<>(); for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) { GlusterVolumeSnapshotEntity correspondingExistingSnapshot = existingSnapshotsMap.get(fetchedSnapshot.getId()); if (correspondingExistingSnapshot == null) { newlyAddedSnapshots.add(fetchedSnapshot); } else if (correspondingExistingSnapshot.getStatus() != fetchedSnapshot.getStatus()) { correspondingExistingSnapshot.setStatus(fetchedSnapshot.getStatus()); updatedSnapshots.add(correspondingExistingSnapshot); } } for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) { GlusterVolumeSnapshotEntity correspondingFetchedSnapshot = fetchedSnapshotsMap.get(existingSnapshot.getId()); if (correspondingFetchedSnapshot == null) { deletedSnapshots.add(existingSnapshot); } } try (EngineLock lock = acquireVolumeSnapshotLock(clusterId)) { saveNewSnapshots(newlyAddedSnapshots); updateSnapshots(updatedSnapshots); deleteSnapshots(deletedSnapshots); } catch (Exception e) { log.error("Exception ocuured while adding/updating snapshots from CLI - '{}'", e.getMessage()); log.debug("Exception", e); throw new VdcBLLException(VdcBllErrors.GlusterSnapshotInfoFailedException, e.getLocalizedMessage()); } }