use of com.emc.storageos.db.client.impl.GlobalLockImpl in project coprhd-controller by CoprHD.
the class GeoUpgradeVoter method isVdcOpLockHold.
/**
* Check if any vdc op lock is hold - it means some vdc op is in progress
*
* @return True if a vdc op lock is hold
* @throws Exception
*/
private boolean isVdcOpLockHold(StringBuffer msg) {
try {
// it doesn't matter if it's nodesvcshared or vdcshared
GlobalLockImpl glock = new GlobalLockImpl((DbClientImpl) dbClient, GeoServiceClient.VDCOP_LOCK_NAME, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, GeoServiceClient.VDCOP_LOCK_TIMEOUT, VdcUtil.getLocalShortVdcId());
String owner = glock.getOwner();
boolean locked = owner != null && !owner.isEmpty();
log.info("Vdc op lock is locked {}", locked);
if (locked && msg != null && !StringUtils.isEmpty(glock.getErrorMessage())) {
msg.append(glock.getErrorMessage());
}
return locked;
} catch (Exception ex) {
log.error("Unexpected exception during check vdc lock", ex);
throw GeoException.fatals.accessGlobalLockFail();
}
}
use of com.emc.storageos.db.client.impl.GlobalLockImpl in project coprhd-controller by CoprHD.
the class GlobalGCExecutorLoop method preGC.
@Override
protected boolean preGC() {
log.info("PrepareGC for geo DB");
dbClient.start();
VdcUtil.setDbClient(dbClient);
locked = false;
try {
String myVdcId = VdcUtil.getLocalShortVdcId();
glock = new GlobalLockImpl((DbClientImpl) dbClient, GeoLockName, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, myVdcId);
log.info("Set global VdcShared lock owner to {} vdcId={}", dbServiceId, myVdcId);
glock.acquire(dbServiceId);
locked = true;
} catch (Exception e) {
log.error("Failed to generate the global Geo GC lock e=", e);
}
log.info("Get global lock for Geo GC {}", locked);
// get the lock
return locked;
}
use of com.emc.storageos.db.client.impl.GlobalLockImpl in project coprhd-controller by CoprHD.
the class VdcOperationLockHelper method acquire.
public void acquire(String vdcShortId) {
boolean lockAcquired = false;
String lockErrMsg = null;
GlobalLockImpl glock = null;
try {
log.info("try to acquire lock for vdc operation {}", vdcShortId);
glock = new GlobalLockImpl(dbClient, GLOBAL_LOCK, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, GLOBAL_LOCK_TIMEOUT, VdcUtil.getLocalShortVdcId());
if (glock.acquire(serviceInfo.getId())) {
lockAcquired = true;
} else {
lockErrMsg = glock.getErrorMessage();
if (StringUtils.isEmpty(lockErrMsg)) {
lockErrMsg = "Could not acquire global lock for vdc operation";
}
}
} catch (Exception e) {
if (glock == null || StringUtils.isEmpty(glock.getErrorMessage())) {
lockErrMsg = "Could not acquire global lock for vdc operation";
} else {
lockErrMsg = glock.getErrorMessage();
}
log.error(e.getMessage(), e);
}
if (!lockAcquired) {
throw GeoException.fatals.acquireLockFail(vdcShortId, lockErrMsg);
}
}
use of com.emc.storageos.db.client.impl.GlobalLockImpl in project coprhd-controller by CoprHD.
the class VdcOperationLockHelper method release.
public void release(String vdcShortId) {
try {
log.info("try to release lock for vdc operation {}", vdcShortId);
GlobalLockImpl glock = new GlobalLockImpl(dbClient, GLOBAL_LOCK, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, GLOBAL_LOCK_TIMEOUT, VdcUtil.getLocalShortVdcId());
glock.release(serviceInfo.getId(), true);
} catch (Exception e) {
// don't fail if we can't release the lock; it'll eventually time out
log.error(e.getMessage(), e);
}
}
use of com.emc.storageos.db.client.impl.GlobalLockImpl in project coprhd-controller by CoprHD.
the class DbGlobalLockTest method testNodesvcSharedGlobalLock.
@Test
public void testNodesvcSharedGlobalLock() throws Exception {
// NodeSvcShared MODE
_logger.info("Starting node/svc shared global lock test");
DbClientImpl dbClient = (DbClientImpl) getDbClient();
boolean flag;
String vdc = "vdc1";
// 1. basic test
String lockname = "testlock1";
GlobalLockImpl glock = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 0, vdc);
// acquire the lock
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// get lock owner
String owner = null;
owner = glock.getOwner();
Assert.assertEquals(owner, "vdc1:vipr1");
// re-enter the lock again with the same owner
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// try to acquire the lock with a different owner
GlobalLockImpl glock2 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 0, vdc);
flag = glock2.acquire("vipr2");
Assert.assertFalse(flag);
// try to release the lock with a different owner
flag = glock2.release("vipr2");
Assert.assertFalse(flag);
// release the lock
flag = glock.release("vipr1");
Assert.assertTrue(flag);
// 2. timeout test
glock = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 3000, vdc);
// acquire the lock
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// try to acquire the lock with a different owner
glock2 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 3000, vdc);
flag = glock2.acquire("vipr2");
Assert.assertFalse(flag);
// acquire the lock (expired) again with a different owner
Thread.sleep(3000);
flag = glock2.acquire("vipr2");
Assert.assertTrue(flag);
// try to release with original owner
flag = glock.release("vipr1");
Assert.assertFalse(flag);
// release with current owner
flag = glock2.release("vipr2");
Assert.assertTrue(flag);
}
Aggregations