Skip to content

Commit c2330f4

Browse files
author
Mike Tutkowski
committed
Replace synchronized with the use of database locking
1 parent a696947 commit c2330f4

2 files changed

Lines changed: 58 additions & 32 deletions

File tree

‎engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
200200
volumeInfo.stateTransit(Volume.Event.OperationFailed);
201201
}
202202

203-
if (snapshotVO != null) {
204-
_snapshotDao.releaseFromLockTable(snapshotInfo.getId());
205-
}
203+
_snapshotDao.releaseFromLockTable(snapshotInfo.getId());
206204
}
207205

208206
return snapshotInfo;

‎plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java‎

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@
7171
import com.cloud.user.AccountDetailsDao;
7272
import com.cloud.user.AccountVO;
7373
import com.cloud.user.dao.AccountDao;
74+
import com.cloud.utils.db.GlobalLock;
7475
import com.cloud.utils.exception.CloudRuntimeException;
7576

7677
public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
7778
private static final Logger s_logger = Logger.getLogger(SolidFirePrimaryDataStoreDriver.class);
79+
private static final int s_lockTimeInSeconds = 300;
7880

7981
@Inject private AccountDao _accountDao;
8082
@Inject private AccountDetailsDao _accountDetailsDao;
@@ -124,7 +126,7 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
124126
// if the ID of volumeInfo in not in the VAG, add it (ModifyVolumeAccessGroup)
125127
// if the VAG doesn't exist, create it with the IQNs of the hosts and the ID of volumeInfo (CreateVolumeAccessGroup)
126128
@Override
127-
public synchronized boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore)
129+
public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore)
128130
{
129131
if (dataObject == null || host == null || dataStore == null) {
130132
return false;
@@ -134,40 +136,52 @@ public synchronized boolean grantAccess(DataObject dataObject, Host host, DataSt
134136
long clusterId = host.getClusterId();
135137
long storagePoolId = dataStore.getId();
136138

137-
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
139+
ClusterVO cluster = _clusterDao.findById(clusterId);
138140

139-
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
141+
GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
140142

141-
List<HostVO> hosts = _hostDao.findByClusterId(clusterId);
142-
143-
if (!SolidFireUtil.hostsSupport_iScsi(hosts)) {
144-
return false;
143+
if (!lock.lock(s_lockTimeInSeconds)) {
144+
s_logger.debug("Couldn't lock the DB (in grantAccess) on the following string: " + cluster.getUuid());
145145
}
146146

147-
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
147+
try {
148+
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
148149

149-
if (vagId != null) {
150-
SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection, Long.parseLong(vagId));
150+
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
151151

152-
String[] hostIqns = SolidFireUtil.getNewHostIqns(sfVag.getInitiators(), SolidFireUtil.getIqnsFromHosts(hosts));
153-
long[] volumeIds = SolidFireUtil.getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, true);
152+
List<HostVO> hosts = _hostDao.findByClusterId(clusterId);
154153

155-
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
156-
}
157-
else {
158-
ClusterVO cluster = _clusterDao.findById(clusterId);
154+
if (!SolidFireUtil.hostsSupport_iScsi(hosts)) {
155+
return false;
156+
}
159157

160-
SolidFireUtil.placeVolumeInVolumeAccessGroup(sfConnection, sfVolumeId, storagePoolId, cluster.getUuid(), hosts, _clusterDetailsDao);
161-
}
158+
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
159+
160+
if (vagId != null) {
161+
SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection, Long.parseLong(vagId));
162+
163+
String[] hostIqns = SolidFireUtil.getNewHostIqns(sfVag.getInitiators(), SolidFireUtil.getIqnsFromHosts(hosts));
164+
long[] volumeIds = SolidFireUtil.getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, true);
165+
166+
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
167+
}
168+
else {
169+
SolidFireUtil.placeVolumeInVolumeAccessGroup(sfConnection, sfVolumeId, storagePoolId, cluster.getUuid(), hosts, _clusterDetailsDao);
170+
}
162171

163-
return true;
172+
return true;
173+
}
174+
finally {
175+
lock.unlock();
176+
lock.releaseRef();
177+
}
164178
}
165179

166180
// get the VAG associated with volumeInfo's cluster, if any (ListVolumeAccessGroups) // might not exist if using CHAP
167181
// if the VAG exists
168182
// remove the ID of volumeInfo from the VAG (ModifyVolumeAccessGroup)
169183
@Override
170-
public synchronized void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
184+
public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
171185
{
172186
if (dataObject == null || host == null || dataStore == null) {
173187
return;
@@ -177,21 +191,35 @@ public synchronized void revokeAccess(DataObject dataObject, Host host, DataStor
177191
long clusterId = host.getClusterId();
178192
long storagePoolId = dataStore.getId();
179193

180-
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
194+
ClusterVO cluster = _clusterDao.findById(clusterId);
181195

182-
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
196+
GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
183197

184-
if (vagId != null) {
185-
List<HostVO> hosts = _hostDao.findByClusterId(clusterId);
198+
if (!lock.lock(s_lockTimeInSeconds)) {
199+
s_logger.debug("Couldn't lock the DB (in revokeAccess) on the following string: " + cluster.getUuid());
200+
}
186201

187-
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
202+
try {
203+
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, SolidFireUtil.getVagKey(storagePoolId));
188204

189-
SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection, Long.parseLong(vagId));
205+
String vagId = clusterDetail != null ? clusterDetail.getValue() : null;
190206

191-
String[] hostIqns = SolidFireUtil.getNewHostIqns(sfVag.getInitiators(), SolidFireUtil.getIqnsFromHosts(hosts));
192-
long[] volumeIds = SolidFireUtil.getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, false);
207+
if (vagId != null) {
208+
List<HostVO> hosts = _hostDao.findByClusterId(clusterId);
193209

194-
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
210+
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
211+
212+
SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection, Long.parseLong(vagId));
213+
214+
String[] hostIqns = SolidFireUtil.getNewHostIqns(sfVag.getInitiators(), SolidFireUtil.getIqnsFromHosts(hosts));
215+
long[] volumeIds = SolidFireUtil.getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, false);
216+
217+
SolidFireUtil.modifySolidFireVag(sfConnection, sfVag.getId(), hostIqns, volumeIds);
218+
}
219+
}
220+
finally {
221+
lock.unlock();
222+
lock.releaseRef();
195223
}
196224
}
197225

0 commit comments

Comments
 (0)