use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PRColocationDUnitTest method createSubPR.
public static void createSubPR(String partitionedRegionName, Integer redundancy, Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, Boolean isPartitionResolver) {
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(redundancy.intValue()).setLocalMaxMemory(localMaxMemory.intValue()).setTotalNumBuckets(totalNumBuckets.intValue()).setColocatedWith((String) colocatedWith);
if (isPartitionResolver.booleanValue()) {
paf.setPartitionResolver(new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
}
PartitionAttributes prAttr = paf.create();
AttributesFactory attr = new AttributesFactory();
assertNotNull(basicGetCache());
Region root = basicGetCache().createRegion("root" + partitionedRegionName, attr.create());
attr.setPartitionAttributes(prAttr);
Region pr = root.createSubregion(partitionedRegionName, attr.create());
assertNotNull(pr);
LogWriterUtils.getLogWriter().info("Partitioned sub region " + pr.getName() + " created Successfully :" + pr.toString());
if (localMaxMemory == 0) {
putInPartitionedRegion(pr);
}
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method testConflictChecksDuringConcurrentDeltaGIIAndOtherOp.
/**
* This test creates 2 VMs in a distributed system with a persistent PartitionedRegion and one VM
* (VM1) puts an entry in region. Second VM (VM2) starts later and does a delta GII. During Delta
* GII in VM2 a DESTROY operation happens in VM1 and gets propagated to VM2 concurrently with GII.
* At this point if entry version is greater than the once received from GII then it must not get
* applied. Which is Bug #45921.
*
*/
@Test
public void testConflictChecksDuringConcurrentDeltaGIIAndOtherOp() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(new CacheSerializableRunnable("Create PR and put an entry") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
PartitionAttributes attrs = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
AttributesFactory factory = new AttributesFactory();
factory.setPartitionAttributes(attrs);
RegionAttributes rAttrs = factory.create();
Region region = cache.createRegionFactory(rAttrs).create("prRegion");
region.put("testKey", "testValue");
assertEquals(1, region.size());
}
});
// Create a cache and region, do an update to change the version no. and
// restart the cache and region.
vm1.invoke(new CacheSerializableRunnable("Create PR and put an entry") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
PartitionAttributes attrs = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
AttributesFactory factory = new AttributesFactory();
factory.setPartitionAttributes(attrs);
RegionAttributes rAttrs = factory.create();
Region region = cache.createRegionFactory(rAttrs).create("prRegion");
region.put("testKey", "testValue2");
cache.close();
// Restart
cache = getCache();
region = cache.createRegionFactory(rAttrs).create("prRegion");
}
});
// Do a DESTROY in vm0 when delta GII is in progress in vm1 (Hopefully, Not
// guaranteed).
AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("Detroy entry in region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region region = cache.getRegion("prRegion");
while (!region.get("testKey").equals("testValue2")) {
Wait.pause(100);
}
region.destroy("testKey");
}
});
try {
async.join(3000);
} catch (InterruptedException e) {
new AssertionError("VM1 entry destroy did not finish in 3000 ms");
}
vm1.invoke(new CacheSerializableRunnable("Verifying entry version in new node VM1") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region region = cache.getRegion("prRegion");
Region.Entry entry = ((PartitionedRegion) region).getEntry("testKey", true);
RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
VersionTag tag = re.getVersionStamp().asVersionTag();
assertEquals(3, /* Two puts and a Destroy */
tag.getEntryVersion());
}
});
closeCache(vm0);
closeCache(vm1);
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PDXQueryTestBase method configAndStartBridgeServer.
protected void configAndStartBridgeServer(boolean isPr, boolean isAccessor, boolean asyncIndex, Compressor compressor) {
AttributesFactory factory = new AttributesFactory();
if (isPr) {
PartitionAttributesFactory paf = new PartitionAttributesFactory();
if (isAccessor) {
paf.setLocalMaxMemory(0);
}
PartitionAttributes prAttr = paf.setTotalNumBuckets(20).setRedundantCopies(0).create();
factory.setPartitionAttributes(prAttr);
} else {
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
}
if (asyncIndex) {
factory.setIndexMaintenanceSynchronous(!asyncIndex);
}
if (compressor != null) {
factory.setCompressor(compressor);
}
createRegion(this.regionName, this.rootRegionName, factory.create());
createRegion(this.regionName2, this.rootRegionName, factory.create());
try {
startBridgeServer(0, false);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PartitionedRegion method registerPartitionedRegion.
/**
* Register this PartitionedRegion by: 1) Create a PartitionRegionConfig and 2) Bind it into the
* allPartitionedRegion system wide Region.
*
* @param storesData which indicates whether the instance in this cache stores data, effecting the
* Nodes PRType
*
* @see Node#setPRType(int)
*/
private void registerPartitionedRegion(boolean storesData) {
// Register this ParitionedRegion. First check if the ParitionedRegion
// entry already exists globally.
PartitionRegionConfig prConfig = null;
PartitionAttributes prAttribs = getAttributes().getPartitionAttributes();
if (storesData) {
if (this.fixedPAttrs != null) {
this.node.setPRType(Node.FIXED_PR_DATASTORE);
} else {
this.node.setPRType(Node.ACCESSOR_DATASTORE);
}
this.node.setPersistence(getAttributes().getDataPolicy() == DataPolicy.PERSISTENT_PARTITION);
byte loaderByte = (byte) (getAttributes().getCacheLoader() != null ? 0x01 : 0x00);
byte writerByte = (byte) (getAttributes().getCacheWriter() != null ? 0x02 : 0x00);
this.node.setLoaderWriterByte((byte) (loaderByte + writerByte));
} else {
if (this.fixedPAttrs != null) {
this.node.setPRType(Node.FIXED_PR_ACCESSOR);
} else {
this.node.setPRType(Node.ACCESSOR);
}
}
final RegionLock rl = getRegionLock();
try {
if (logger.isDebugEnabled()) {
logger.debug("registerPartitionedRegion: obtaining lock");
}
rl.lock();
checkReadiness();
prConfig = this.prRoot.get(getRegionIdentifier());
if (prConfig == null) {
validateParalleGatewaySenderIds();
this.partitionedRegionId = generatePRId(getSystem());
prConfig = new PartitionRegionConfig(this.partitionedRegionId, this.getFullPath(), prAttribs, this.getScope(), getAttributes().getEvictionAttributes(), getAttributes().getRegionIdleTimeout(), getAttributes().getRegionTimeToLive(), getAttributes().getEntryIdleTimeout(), getAttributes().getEntryTimeToLive(), this.getAllGatewaySenderIds());
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_PARTITIONED_REGION_0_IS_BORN_WITH_PRID_1_IDENT_2, new Object[] { getFullPath(), this.partitionedRegionId, getRegionIdentifier() }));
PRSanityCheckMessage.schedule(this);
} else {
validator.validatePartitionAttrsFromPRConfig(prConfig);
if (storesData) {
validator.validatePersistentMatchBetweenDataStores(prConfig);
validator.validateCacheLoaderWriterBetweenDataStores(prConfig);
validator.validateFixedPABetweenDataStores(prConfig);
}
this.partitionedRegionId = prConfig.getPRId();
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_PARTITIONED_REGION_0_IS_CREATED_WITH_PRID_1, new Object[] { getFullPath(), this.partitionedRegionId }));
}
synchronized (prIdToPR) {
// last
prIdToPR.put(this.partitionedRegionId, this);
}
prConfig.addNode(this.node);
if (this.getFixedPartitionAttributesImpl() != null) {
calculateStartingBucketIDs(prConfig);
}
updatePRConfig(prConfig, false);
/*
* try { if (this.redundantCopies > 0) { if (storesData) {
* this.dataStore.grabBackupBuckets(false); } } } catch (RegionDestroyedException rde) { if
* (!this.isClosed) throw rde; }
*/
this.cleanPRRegistration = true;
} catch (LockServiceDestroyedException lsde) {
if (logger.isDebugEnabled()) {
logger.debug("registerPartitionedRegion: unable to obtain lock for {}", this);
}
cleanupFailedInitialization();
throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_CAN_NOT_CREATE_PARTITIONEDREGION_FAILED_TO_ACQUIRE_REGIONLOCK.toLocalizedString(), lsde);
} catch (IllegalStateException ill) {
cleanupFailedInitialization();
throw ill;
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
String registerErrMsg = LocalizedStrings.PartitionedRegion_AN_EXCEPTION_WAS_CAUGHT_WHILE_REGISTERING_PARTITIONEDREGION_0_DUMPPRID_1.toLocalizedString(getFullPath(), prIdToPR.dump());
try {
synchronized (prIdToPR) {
if (prIdToPR.containsKey(this.partitionedRegionId)) {
prIdToPR.put(this.partitionedRegionId, PRIdMap.FAILED_REGISTRATION, false);
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_FAILED_REGISTRATION_PRID_0_NAMED_1, new Object[] { this.partitionedRegionId, this.getName() }));
}
}
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable e) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
if (logger.isDebugEnabled()) {
logger.debug("Partitioned Region creation, could not clean up after caught exception", e);
}
}
throw new PartitionedRegionException(registerErrMsg, t);
} finally {
try {
rl.unlock();
if (logger.isDebugEnabled()) {
logger.debug("registerPartitionedRegion: released lock");
}
} catch (Exception es) {
if (logger.isDebugEnabled()) {
logger.debug(es.getMessage(), es);
}
}
}
}
use of org.apache.geode.cache.PartitionAttributes in project geode by apache.
the class PRQueryDUnitHelper method getCacheSerializableRunnableForCacheClose.
/**
* This function <br>
* 1. calls the cache.close on the VM <br>
* 2. creates the cache again & also the PR <br>
*
* @return cacheSerializable object
*
* NOTE: Closing of the cache must be done from the test case rather than in
* PRQueryDUintHelper
*
*/
public CacheSerializableRunnable getCacheSerializableRunnableForCacheClose(final String regionName, final int redundancy, final Class constraint) {
SerializableRunnable PrRegion = new CacheSerializableRunnable("cacheClose") {
@Override
public void run2() throws CacheException {
final String expectedCacheClosedException = CacheClosedException.class.getName();
final String expectedReplyException = ReplyException.class.getName();
getCache().getLogger().info("<ExpectedException action=add>" + expectedCacheClosedException + "</ExpectedException>");
getCache().getLogger().info("<ExpectedException action=add>" + expectedReplyException + "</ExpectedException>");
Cache cache = getCache();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PROperationWithQueryDUnitTest#getCacheSerializableRunnableForCacheClose: Recreating the cache ");
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(constraint);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
PartitionAttributes prAttr = paf.setRedundantCopies(redundancy).create();
attr.setPartitionAttributes(prAttr);
final CountDownLatch cdl = new CountDownLatch(1);
ResourceObserverAdapter observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
cdl.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
try {
cache.createRegion(regionName, attr.create());
// Wait for recovery to finish
cdl.await();
} catch (InterruptedException e) {
Assert.fail("interupted", e);
} finally {
InternalResourceManager.setResourceObserver(null);
}
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PROperationWithQueryDUnitTest#getCacheSerializableRunnableForCacheClose: cache Recreated on VM ");
getCache().getLogger().info("<ExpectedException action=remove>" + expectedReplyException + "</ExpectedException>");
getCache().getLogger().info("<ExpectedException action=remove>" + expectedCacheClosedException + "</ExpectedException>");
}
};
return (CacheSerializableRunnable) PrRegion;
}
Aggregations