use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class ParallelQueueRemovalMessageJUnitTest method createBucketRegionQueue.
private void createBucketRegionQueue() {
// Create InternalRegionArguments
InternalRegionArguments ira = new InternalRegionArguments();
ira.setPartitionedRegion(this.queueRegion);
ira.setPartitionedRegionBucketRedundancy(1);
BucketAdvisor ba = mock(BucketAdvisor.class);
ira.setBucketAdvisor(ba);
InternalRegionArguments pbrIra = new InternalRegionArguments();
RegionAdvisor ra = mock(RegionAdvisor.class);
when(ra.getPartitionedRegion()).thenReturn(this.queueRegion);
pbrIra.setPartitionedRegionAdvisor(ra);
PartitionAttributes pa = mock(PartitionAttributes.class);
when(this.queueRegion.getPartitionAttributes()).thenReturn(pa);
when(this.queueRegion.getBucketName(eq(BUCKET_ID))).thenAnswer(new Answer<String>() {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
return PartitionedRegionHelper.getBucketName(queueRegion.getFullPath(), BUCKET_ID);
}
});
when(this.queueRegion.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
when(pa.getColocatedWith()).thenReturn(null);
// classes cannot be mocked
ProxyBucketRegion pbr = new ProxyBucketRegion(BUCKET_ID, this.queueRegion, pbrIra);
when(ba.getProxyBucketRegion()).thenReturn(pbr);
// Create RegionAttributes
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
RegionAttributes attributes = factory.create();
// Create BucketRegionQueue
BucketRegionQueue realBucketRegionQueue = new BucketRegionQueue(this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
this.bucketRegionQueue = spy(realBucketRegionQueue);
// (this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
EntryEventImpl entryEvent = EntryEventImpl.create(this.bucketRegionQueue, Operation.DESTROY, mock(EventID.class), "value", null, false, mock(DistributedMember.class));
doReturn(entryEvent).when(this.bucketRegionQueue).newDestroyEntryEvent(any(), any());
// when(this.bucketRegionQueue.newDestroyEntryEvent(any(), any())).thenReturn();
this.bucketRegionQueueHelper = new BucketRegionQueueHelper(this.cache, this.queueRegion, this.bucketRegionQueue);
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class RoutingObject method tryVerifyPrimaryColocation.
protected static boolean tryVerifyPrimaryColocation() {
HashMap customerPrimaryMap = new HashMap();
RegionAdvisor customeAdvisor = ((PartitionedRegion) customerPR).getRegionAdvisor();
Iterator customerIterator = customeAdvisor.getBucketSet().iterator();
while (customerIterator.hasNext()) {
Integer bucketId = (Integer) customerIterator.next();
if (customeAdvisor.isPrimaryForBucket(bucketId.intValue())) {
customerPrimaryMap.put(bucketId, customeAdvisor.getPrimaryMemberForBucket(bucketId.intValue()).getId());
}
}
HashMap orderPrimaryMap = new HashMap();
RegionAdvisor orderAdvisor = ((PartitionedRegion) orderPR).getRegionAdvisor();
Iterator orderIterator = orderAdvisor.getBucketSet().iterator();
while (orderIterator.hasNext()) {
Integer bucketId = (Integer) orderIterator.next();
if (orderAdvisor.isPrimaryForBucket(bucketId.intValue())) {
orderPrimaryMap.put(bucketId, orderAdvisor.getPrimaryMemberForBucket(bucketId.intValue()).getId());
}
}
HashMap shipmentPrimaryMap = new HashMap();
RegionAdvisor shipmentAdvisor = ((PartitionedRegion) shipmentPR).getRegionAdvisor();
Iterator shipmentIterator = shipmentAdvisor.getBucketSet().iterator();
while (shipmentIterator.hasNext()) {
Integer bucketId = (Integer) shipmentIterator.next();
if (shipmentAdvisor.isPrimaryForBucket(bucketId.intValue())) {
shipmentPrimaryMap.put(bucketId, shipmentAdvisor.getPrimaryMemberForBucket(bucketId.intValue()).getId());
}
}
// verification for primary
int s1, s2;
s1 = customerPrimaryMap.size();
s2 = orderPrimaryMap.size();
if (s1 != s2) {
excuse = "customerPrimaryMap size (" + s1 + ") != orderPrimaryMap size (" + s2 + ")";
return false;
}
if (!customerPrimaryMap.entrySet().equals(orderPrimaryMap.entrySet())) {
excuse = "customerPrimaryMap entrySet != orderPrimaryMap entrySet";
return false;
}
if (!customerPrimaryMap.entrySet().equals(shipmentPrimaryMap.entrySet())) {
excuse = "customerPrimaryMap entrySet != shipmentPrimaryMap entrySet";
return false;
}
if (!customerPrimaryMap.equals(orderPrimaryMap)) {
excuse = "customerPrimaryMap != orderPrimaryMap";
return false;
}
if (!customerPrimaryMap.equals(shipmentPrimaryMap)) {
excuse = "customerPrimaryMap != shipmentPrimaryMap";
return false;
}
return true;
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class RoutingObject method tryVerifyColocation.
/**
* @return true if verified
*/
protected static boolean tryVerifyColocation() {
HashMap customerMap = new HashMap();
HashMap customerPrimaryMap = new HashMap();
RegionAdvisor customeAdvisor = ((PartitionedRegion) customerPR).getRegionAdvisor();
Iterator customerIterator = customeAdvisor.getBucketSet().iterator();
while (customerIterator.hasNext()) {
Integer bucketId = (Integer) customerIterator.next();
Set someOwners = customeAdvisor.getBucketOwners(bucketId.intValue());
customerMap.put(bucketId, someOwners);
if (customeAdvisor.isPrimaryForBucket(bucketId.intValue())) {
customerPrimaryMap.put(bucketId, customeAdvisor.getPrimaryMemberForBucket(bucketId.intValue()).getId());
}
}
HashMap orderMap = new HashMap();
HashMap orderPrimaryMap = new HashMap();
RegionAdvisor orderAdvisor = ((PartitionedRegion) orderPR).getRegionAdvisor();
Iterator orderIterator = orderAdvisor.getBucketSet().iterator();
while (orderIterator.hasNext()) {
Integer bucketId = (Integer) orderIterator.next();
Set someOwners = orderAdvisor.getBucketOwners(bucketId.intValue());
orderMap.put(bucketId, someOwners);
if (orderAdvisor.isPrimaryForBucket(bucketId.intValue())) {
orderPrimaryMap.put(bucketId, orderAdvisor.getPrimaryMemberForBucket(bucketId.intValue()).getId());
}
}
HashMap shipmentMap = new HashMap();
HashMap shipmentPrimaryMap = new HashMap();
RegionAdvisor shipmentAdvisor = ((PartitionedRegion) shipmentPR).getRegionAdvisor();
Iterator shipmentIterator = shipmentAdvisor.getBucketSet().iterator();
while (shipmentIterator.hasNext()) {
Integer bucketId = (Integer) shipmentIterator.next();
Set someOwners = shipmentAdvisor.getBucketOwners(bucketId.intValue());
shipmentMap.put(bucketId, someOwners);
if (!customerMap.get(bucketId).equals(someOwners)) {
excuse = "customerMap at " + bucketId + " has wrong owners";
return false;
}
if (!orderMap.get(bucketId).equals(someOwners)) {
excuse = "orderMap at " + bucketId + " has wrong owners";
return false;
}
if (shipmentAdvisor.isPrimaryForBucket(bucketId.intValue())) {
shipmentPrimaryMap.put(bucketId, shipmentAdvisor.getPrimaryMemberForBucket(bucketId.intValue()).getId());
}
}
// verification for primary
if (customerPrimaryMap.size() != orderPrimaryMap.size()) {
excuse = "customerPrimaryMap and orderPrimaryMap have different sizes";
return false;
}
if (customerPrimaryMap.size() != shipmentPrimaryMap.size()) {
excuse = "customerPrimaryMap and shipmentPrimaryMap have different sizes";
return false;
}
if (!customerPrimaryMap.entrySet().equals(orderPrimaryMap.entrySet())) {
excuse = "customerPrimaryMap and orderPrimaryMap have different entrySets";
return false;
}
if (!customerPrimaryMap.entrySet().equals(shipmentPrimaryMap.entrySet())) {
excuse = "customerPrimaryMap and shipmentPrimaryMap have different entrySets";
return false;
}
if (!customerPrimaryMap.equals(orderPrimaryMap)) {
excuse = "customerPrimaryMap and orderPrimaryMap not equal";
return false;
}
if (!customerPrimaryMap.equals(shipmentPrimaryMap)) {
excuse = "customerPrimaryMap and shipmentPrimaryMap not equal";
return false;
}
// verification for all
if (customerMap.size() != orderMap.size()) {
excuse = "customerMap and orderMap have different sizes";
return false;
}
if (customerMap.size() != shipmentMap.size()) {
excuse = "customerMap and shipmentMap have different sizes";
return false;
}
if (!customerMap.entrySet().equals(orderMap.entrySet())) {
excuse = "customerMap and orderMap have different entrySets";
return false;
}
if (!customerMap.entrySet().equals(shipmentMap.entrySet())) {
excuse = "customerMap and shipmentMap have different entrySets";
return false;
}
if (!customerMap.equals(orderMap)) {
excuse = "customerMap and orderMap not equal";
return false;
}
if (!customerMap.equals(shipmentMap)) {
excuse = "customerMap and shipmentMap not equal";
return false;
}
return true;
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class DestroyPartitionedRegionMessage method operateOnPartitionedRegion.
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws CacheException {
if (this.op.isLocal()) {
// notify the advisor that the sending member has locally destroyed (or closed) the region
PartitionProfile pp = r.getRegionAdvisor().getPartitionProfile(getSender());
if (pp == null) {
// Fix for bug#36863
return true;
}
// final Lock isClosingWriteLock =
// r.getRegionAdvisor().getPartitionProfile(getSender()).getIsClosingWriteLock();
Assert.assertTrue(this.prSerial != DistributionAdvisor.ILLEGAL_SERIAL);
boolean ok = true;
// Examine this peer's profile and look at the serial number in that
// profile. If we have a newer profile, ignore the request.
int oldSerial = pp.getSerialNumber();
if (DistributionAdvisor.isNewerSerialNumber(oldSerial, this.prSerial)) {
ok = false;
if (logger.isDebugEnabled()) {
logger.debug("Not removing region {}l serial requested = {}; actual is {}", r.getName(), this.prSerial, r.getSerialNumber());
}
}
if (ok) {
RegionAdvisor ra = r.getRegionAdvisor();
ra.removeIdAndBuckets(this.sender, this.prSerial, this.bucketSerials, !this.op.isClose());
// r.getRegionAdvisor().removeId(this.sender);
}
sendReply(getSender(), getProcessorId(), dm, null, r, startTime);
/*
* } finally { isClosingWriteLock.unlock(); }
*/
return false;
}
// we can invoke destroyPartitionedRegionLocally method.
if (r.isDestroyed()) {
boolean isClose = this.op.isClose();
r.destroyPartitionedRegionLocally(!isClose);
return true;
}
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "{} operateOnRegion: {}", getClass().getName(), r.getFullPath());
}
RegionEventImpl event = new RegionEventImpl(r, this.op, this.cbArg, true, r.getMyId());
r.basicDestroyRegion(event, false, false, true);
return true;
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class PartitionedRegionHelper method getProxyBucketRegion.
/**
* Find a ProxyBucketRegion by parsing the region fullPath
*
* @param fullPath full region path to parse
* @param postInit true if caller should wait for bucket initialization to complete
* @return ProxyBucketRegion as Bucket or null if not found
* @throws PRLocallyDestroyedException if the PartitionRegion is locally destroyed
*/
public static Bucket getProxyBucketRegion(Cache cache, String fullPath, boolean postInit) throws PRLocallyDestroyedException {
if (cache == null) {
// No cache
return null;
}
// fullPath = /__PR/_B_1_10
String bucketName = getBucketName(fullPath);
if (bucketName == null) {
return null;
}
String prid = getPRPath(bucketName);
// PartitionedRegion region =
// PartitionedRegion.getPRFromId(Integer.parseInt(prid));
Region region;
// Set thread local flag to allow entrance through initialization Latch
int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
try {
region = cache.getRegion(prid);
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
}
if (region == null || !(region instanceof PartitionedRegion)) {
return null;
}
PartitionedRegion pr = (PartitionedRegion) region;
int bid = getBucketId(bucketName);
RegionAdvisor ra = (RegionAdvisor) pr.getDistributionAdvisor();
if (postInit) {
return ra.getBucketPostInit(bid);
} else if (!ra.areBucketsInitialized()) {
// While the RegionAdvisor may be available, it's bucket meta-data may not be constructed yet
return null;
} else {
return ra.getBucket(bid);
}
}
Aggregations