marcaurele commented on a change in pull request #2373:
CLOUDSTACK-10202:createSnapshotPolicy API create multiple entries in DB for
same volume.
URL: https://github.com/apache/cloudstack/pull/2373#discussion_r158900038
##########
File path: server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
##########
@@ -854,33 +856,39 @@ public SnapshotPolicyVO
createPolicy(CreateSnapshotPolicyCmd cmd, Account policy
throw new InvalidParameterValueException("Max number of
snapshots shouldn't exceed the " + message + " level snapshot limit");
}
}
- SnapshotPolicyVO policy =
_snapshotPolicyDao.findOneByVolumeInterval(volumeId, intvType);
- if (policy == null) {
- policy = new SnapshotPolicyVO(volumeId, cmd.getSchedule(),
timezoneId, intvType, cmd.getMaxSnaps(), display);
- policy = _snapshotPolicyDao.persist(policy);
- _snapSchedMgr.scheduleNextSnapshotJob(policy);
- } else {
+
+ final GlobalLock createSnapshotPolicyLock =
GlobalLock.getInternLock("createSnapshotPolicy_" + volumeId);
+ boolean isLockAcquired = createSnapshotPolicyLock.lock(5);
+ if (isLockAcquired) {
+ s_logger.debug("Acquired lock for creating snapshot policy of
volume : " + volume.getName());
try {
- boolean previousDisplay = policy.isDisplay();
- policy = _snapshotPolicyDao.acquireInLockTable(policy.getId());
- policy.setSchedule(cmd.getSchedule());
- policy.setTimezone(timezoneId);
- policy.setInterval((short)intvType.ordinal());
- policy.setMaxSnaps(cmd.getMaxSnaps());
- policy.setActive(true);
- policy.setDisplay(display);
- _snapshotPolicyDao.update(policy.getId(), policy);
-
_snapSchedMgr.scheduleOrCancelNextSnapshotJobOnDisplayChange(policy,
previousDisplay);
- } finally {
- if (policy != null) {
- _snapshotPolicyDao.releaseFromLockTable(policy.getId());
+ policy = _snapshotPolicyDao.findOneByVolumeInterval(volumeId,
intvType);
+ if (policy == null) {
+ policy = new SnapshotPolicyVO(volumeId, cmd.getSchedule(),
timezoneId, intvType, cmd.getMaxSnaps(), display);
+ policy = _snapshotPolicyDao.persist(policy);
+ _snapSchedMgr.scheduleNextSnapshotJob(policy);
+ } else {
+ boolean previousDisplay = policy.isDisplay();
+ policy.setSchedule(cmd.getSchedule());
+ policy.setTimezone(timezoneId);
+ policy.setInterval((short)intvType.ordinal());
+ policy.setMaxSnaps(cmd.getMaxSnaps());
+ policy.setActive(true);
+ policy.setDisplay(display);
+ _snapshotPolicyDao.update(policy.getId(), policy);
+
_snapSchedMgr.scheduleOrCancelNextSnapshotJobOnDisplayChange(policy,
previousDisplay);
}
+ } finally {
+ createSnapshotPolicyLock.unlock();
}
+ // TODO - Make createSnapshotPolicy - BaseAsyncCreate and remove
this.
+ CallContext.current().putContextParameter(SnapshotPolicy.class,
policy.getUuid());
+ return policy;
+ } else {
+ s_logger.debug("Unable to acquire lock for creating snapshot
policy of volume : " + volume.getName());
Review comment:
This log should be move to the `warn` level
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services