mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Replace synchronized with the use of database locking
This commit is contained in:
parent
a696947eaf
commit
c2330f48dd
@ -200,10 +200,8 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
|
|||||||
volumeInfo.stateTransit(Volume.Event.OperationFailed);
|
volumeInfo.stateTransit(Volume.Event.OperationFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snapshotVO != null) {
|
|
||||||
_snapshotDao.releaseFromLockTable(snapshotInfo.getId());
|
_snapshotDao.releaseFromLockTable(snapshotInfo.getId());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return snapshotInfo;
|
return snapshotInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,10 +71,12 @@ import com.cloud.user.AccountDetailVO;
|
|||||||
import com.cloud.user.AccountDetailsDao;
|
import com.cloud.user.AccountDetailsDao;
|
||||||
import com.cloud.user.AccountVO;
|
import com.cloud.user.AccountVO;
|
||||||
import com.cloud.user.dao.AccountDao;
|
import com.cloud.user.dao.AccountDao;
|
||||||
|
import com.cloud.utils.db.GlobalLock;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
|
||||||
public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
||||||
private static final Logger s_logger = Logger.getLogger(SolidFirePrimaryDataStoreDriver.class);
|
private static final Logger s_logger = Logger.getLogger(SolidFirePrimaryDataStoreDriver.class);
|
||||||
|
private static final int s_lockTimeInSeconds = 300;
|
||||||
|
|
||||||
@Inject private AccountDao _accountDao;
|
@Inject private AccountDao _accountDao;
|
||||||
@Inject private AccountDetailsDao _accountDetailsDao;
|
@Inject private AccountDetailsDao _accountDetailsDao;
|
||||||
@ -124,7 +126,7 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||||||
// if the ID of volumeInfo in not in the VAG, add it (ModifyVolumeAccessGroup)
|
// if the ID of volumeInfo in not in the VAG, add it (ModifyVolumeAccessGroup)
|
||||||
// if the VAG doesn't exist, create it with the IQNs of the hosts and the ID of volumeInfo (CreateVolumeAccessGroup)
|
// if the VAG doesn't exist, create it with the IQNs of the hosts and the ID of volumeInfo (CreateVolumeAccessGroup)
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore)
|
public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore)
|
||||||
{
|
{
|
||||||
if (dataObject == null || host == null || dataStore == null) {
|
if (dataObject == null || host == null || dataStore == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -134,6 +136,15 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||||||
long clusterId = host.getClusterId();
|
long clusterId = host.getClusterId();
|
||||||
long storagePoolId = dataStore.getId();
|
long storagePoolId = dataStore.getId();
|
||||||
|
|
||||||
|
ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||||
|
|
||||||
|
GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
|
||||||
|
|
||||||
|
if (!lock.lock(s_lockTimeInSeconds)) {
|
||||||
|
s_logger.debug("Couldn't lock the DB (in grantAccess) on the following string: " + cluster.getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
|
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
|
||||||
|
|
||||||
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
|
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
|
||||||
@ -155,19 +166,22 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||||||
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
|
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClusterVO cluster = _clusterDao.findById(clusterId);
|
|
||||||
|
|
||||||
SolidFireUtil.placeVolumeInVolumeAccessGroup(sfConnection, sfVolumeId, storagePoolId, cluster.getUuid(), hosts, _clusterDetailsDao);
|
SolidFireUtil.placeVolumeInVolumeAccessGroup(sfConnection, sfVolumeId, storagePoolId, cluster.getUuid(), hosts, _clusterDetailsDao);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
lock.releaseRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get the VAG associated with volumeInfo's cluster, if any (ListVolumeAccessGroups) // might not exist if using CHAP
|
// get the VAG associated with volumeInfo's cluster, if any (ListVolumeAccessGroups) // might not exist if using CHAP
|
||||||
// if the VAG exists
|
// if the VAG exists
|
||||||
// remove the ID of volumeInfo from the VAG (ModifyVolumeAccessGroup)
|
// remove the ID of volumeInfo from the VAG (ModifyVolumeAccessGroup)
|
||||||
@Override
|
@Override
|
||||||
public synchronized void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
|
public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
|
||||||
{
|
{
|
||||||
if (dataObject == null || host == null || dataStore == null) {
|
if (dataObject == null || host == null || dataStore == null) {
|
||||||
return;
|
return;
|
||||||
@ -177,6 +191,15 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||||||
long clusterId = host.getClusterId();
|
long clusterId = host.getClusterId();
|
||||||
long storagePoolId = dataStore.getId();
|
long storagePoolId = dataStore.getId();
|
||||||
|
|
||||||
|
ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||||
|
|
||||||
|
GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
|
||||||
|
|
||||||
|
if (!lock.lock(s_lockTimeInSeconds)) {
|
||||||
|
s_logger.debug("Couldn't lock the DB (in revokeAccess) on the following string: " + cluster.getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
|
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
|
||||||
|
|
||||||
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
|
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
|
||||||
@ -194,6 +217,11 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
|||||||
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
|
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
lock.releaseRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private long getSolidFireVolumeId(DataObject dataObject) {
|
private long getSolidFireVolumeId(DataObject dataObject) {
|
||||||
if (dataObject.getType() == DataObjectType.VOLUME) {
|
if (dataObject.getType() == DataObjectType.VOLUME) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user