use of org.apache.geode.distributed.DistributedLockService in project geode by apache.
the class TXLockServiceDUnitTest method remoteCreateService.
/**
* Creates a new DistributedLockService in a remote VM.
*
* @param name The name of the newly-created DistributedLockService. It is recommended that the
* name of the Region be the {@link #getUniqueName()} of the test, or at least derive from
* it.
*/
protected static void remoteCreateService(String name) {
DistributedLockService newService = DistributedLockService.create(name, system);
logInfo("Created " + newService);
}
use of org.apache.geode.distributed.DistributedLockService in project geode by apache.
the class DLockManagementDUnitTest method verifyLockServiceMXBeanInMember.
private void verifyLockServiceMXBeanInMember(final VM memberVM) {
memberVM.invoke("verifyLockServiceMXBeanInManager", () -> {
DistributedLockService lockService = DistributedLockService.getServiceNamed(LOCK_SERVICE_NAME);
lockService.lock("lockObject_" + identifyPid(), MAX_WAIT_MILLIS, -1);
ManagementService service = this.managementTestRule.getManagementService();
LockServiceMXBean lockServiceMXBean = service.getLocalLockServiceMBean(LOCK_SERVICE_NAME);
assertThat(lockServiceMXBean).isNotNull();
String[] listHeldLock = lockServiceMXBean.listHeldLocks();
assertThat(listHeldLock).hasSize(1);
Map<String, String> lockThreadMap = lockServiceMXBean.listThreadsHoldingLock();
assertThat(lockThreadMap).hasSize(1);
});
}
use of org.apache.geode.distributed.DistributedLockService in project geode by apache.
the class AutoBalancerIntegrationJUnitTest method testLockAlreadyTakenElsewhere.
@Test
public void testLockAlreadyTakenElsewhere() throws InterruptedException {
DistributedLockService dls = new GeodeCacheFacade().getDLS();
assertTrue(dls.lock(AutoBalancer.AUTO_BALANCER_LOCK, 0, -1));
final AtomicBoolean success = new AtomicBoolean(true);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
CacheOperationFacade cacheFacade = new GeodeCacheFacade();
success.set(cacheFacade.acquireAutoBalanceLock());
}
});
thread.start();
thread.join();
assertFalse(success.get());
}
use of org.apache.geode.distributed.DistributedLockService in project geode by apache.
the class BucketAdvisor method getPrimaryLock.
/**
* Lazily gets the lock for acquiring primary lock. Caller must handle null. If DLS, Cache, or
* DistributedSystem are shutting down then null will be returned. If DLS does not yet exist and
* createDLS is false then null will be returned.
*
* @param createDLS true will create DLS if it does not exist
* @return distributed lock indicating primary member or null
*/
DistributedMemberLock getPrimaryLock(boolean createDLS) {
synchronized (this) {
if (this.primaryLock == null) {
DistributedLockService dls = DistributedLockService.getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
if (dls == null) {
if (!createDLS || getProxyBucketRegion().getCache().isClosed()) {
// cache closure has destroyed the DLS
return null;
}
try {
// TODO: call GemFireCache#getPartitionedRegionLockService
dls = DLockService.create(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME, getAdvisee().getSystem(), true, /* distributed */
true, /* destroyOnDisconnect */
true);
} catch (IllegalArgumentException e) {
// indicates that the DLS is already created
dls = DistributedLockService.getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
if (dls == null) {
// ok, caller will loop if necessary
return null;
}
}// perhaps: DistributedSystemUnavailableException
catch (IllegalStateException e) {
// create still throws IllegalStateException if isDisconnecting is true
return null;
} catch (DistributedSystemDisconnectedException e) {
// this would certainly prevent us from creating a DLS... messy
return null;
}
}
this.primaryLock = new DistributedMemberLock(dls, getAdvisee().getName(), DistributedMemberLock.NON_EXPIRING_LEASE, DistributedMemberLock.LockReentryPolicy.PREVENT_SILENTLY);
}
return this.primaryLock;
}
}
use of org.apache.geode.distributed.DistributedLockService in project geode by apache.
the class IndexRepositoryFactory method computeIndexRepository.
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, final IndexRepository oldRepository) throws IOException {
LuceneIndexForPartitionedRegion indexForPR = (LuceneIndexForPartitionedRegion) index;
final PartitionedRegion fileRegion = indexForPR.getFileAndChunkRegion();
BucketRegion fileAndChunkBucket = getMatchingBucket(fileRegion, bucketId);
BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
boolean success = false;
if (fileAndChunkBucket == null) {
if (oldRepository != null) {
oldRepository.cleanup();
}
return null;
}
if (!fileAndChunkBucket.getBucketAdvisor().isPrimary()) {
if (oldRepository != null) {
oldRepository.cleanup();
}
return null;
}
if (oldRepository != null && !oldRepository.isClosed()) {
return oldRepository;
}
if (oldRepository != null) {
oldRepository.cleanup();
}
DistributedLockService lockService = getLockService();
String lockName = getLockName(fileAndChunkBucket);
while (!lockService.lock(lockName, 100, -1)) {
if (!fileAndChunkBucket.getBucketAdvisor().isPrimary()) {
return null;
}
}
final IndexRepository repo;
try {
RegionDirectory dir = new RegionDirectory(getBucketTargetingMap(fileAndChunkBucket, bucketId), indexForPR.getFileSystemStats());
IndexWriterConfig config = new IndexWriterConfig(indexForPR.getAnalyzer());
IndexWriter writer = new IndexWriter(dir, config);
repo = new IndexRepositoryImpl(fileAndChunkBucket, writer, serializer, indexForPR.getIndexStats(), dataBucket, lockService, lockName);
success = true;
return repo;
} catch (IOException e) {
logger.info("Exception thrown while constructing Lucene Index for bucket:" + bucketId + " for file region:" + fileAndChunkBucket.getFullPath());
throw e;
} finally {
if (!success) {
lockService.unlock(lockName);
}
}
}
Aggregations