use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class PartitionedRegion method sendIndexCreationMsg.
/**
* Explicitly sends an index creation message to a newly added node to the system on prs.
*
* @param idM id on the newly added node.
*/
public void sendIndexCreationMsg(InternalDistributedMember idM) {
if (!this.isIndexed()) {
return;
}
RegionAdvisor advisor = (RegionAdvisor) getCacheDistributionAdvisor();
final Set<InternalDistributedMember> recipients = advisor.adviseDataStore();
if (!recipients.contains(idM)) {
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_NEWLY_ADDED_MEMBER_TO_THE_PR_IS_AN_ACCESSOR_AND_WILL_NOT_RECEIVE_INDEX_INFORMATION_0, idM));
return;
}
// this should add the member to a synchronized set and then sent this member
// and index creation msg latter after its completed creating the partitioned region.
IndexCreationMsg.IndexCreationResponse response;
IndexCreationMsg.IndexCreationResult result;
if (this.indexes.isEmpty()) {
return;
}
Iterator it = this.indexes.values().iterator();
HashSet<IndexCreationData> indexDefinitions = new HashSet<>();
Set<PartitionedIndex> indexes = new HashSet<>();
while (it.hasNext()) {
Object ind = it.next();
// the index is not in create phase, its created successfully).
if (!(ind instanceof Index)) {
continue;
}
PartitionedIndex prIndex = (PartitionedIndex) ind;
indexes.add(prIndex);
IndexCreationData icd = new IndexCreationData(prIndex.getName());
icd.setIndexData(prIndex.getType(), prIndex.getFromClause(), prIndex.getIndexedExpression(), prIndex.getImports(), true);
indexDefinitions.add(icd);
}
response = (IndexCreationMsg.IndexCreationResponse) IndexCreationMsg.send(idM, this, indexDefinitions);
if (logger.isDebugEnabled()) {
logger.debug("Sending explicitly index creation message to : {}", idM);
}
if (response != null) {
try {
result = response.waitForResult();
Map<String, Integer> remoteIndexBucketsMap = result.getIndexBucketsMap();
// set the number of remote buckets indexed for each pr index
for (Index ind : indexes) {
((PartitionedIndex) ind).setRemoteBucketesIndexed(remoteIndexBucketsMap.get(ind.getName()));
}
} catch (ForceReattemptException e) {
logger.info(LocalizedStrings.PartitionedRegion_FORCEREATTEMPT_EXCEPTION___0, e);
}
}
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class MemoryThresholdsOffHeapDUnitTest method testPRLoadRejection.
/**
* Test that a Partitioned Region loader invocation is rejected if the VM with the bucket is in a
* critical state.
*/
// GEODE-551: waitForCriterion, memory sensitive
@Category(FlakyTest.class)
@Test
public void testPRLoadRejection() throws Exception {
final Host host = Host.getHost(0);
final VM accessor = host.getVM(1);
final VM ds1 = host.getVM(2);
final String rName = getUniqueName();
// Make sure the desired VMs will have a fresh DS. TODO: convert these from AsyncInvocation to
// invoke
AsyncInvocation d0 = accessor.invokeAsync(() -> disconnectFromDS());
AsyncInvocation d1 = ds1.invokeAsync(() -> disconnectFromDS());
d0.join();
assertFalse(d0.exceptionOccurred());
d1.join();
assertFalse(d1.exceptionOccurred());
CacheSerializableRunnable establishConnectivity = new CacheSerializableRunnable("establishcConnectivity") {
@Override
public void run2() throws CacheException {
getSystem();
}
};
ds1.invoke(establishConnectivity);
accessor.invoke(establishConnectivity);
ds1.invoke(createPR(rName, false));
accessor.invoke(createPR(rName, true));
final AtomicInteger expectedInvocations = new AtomicInteger(0);
Integer ex = (Integer) accessor.invoke(new SerializableCallable("Invoke loader from accessor, non-critical") {
public Object call() throws Exception {
Region<Integer, String> r = getCache().getRegion(rName);
Integer k = new Integer(1);
Integer expectedInvocations0 = new Integer(expectedInvocations.getAndIncrement());
// should load for new key
assertEquals(k.toString(), r.get(k, expectedInvocations0));
assertTrue(r.containsKey(k));
Integer expectedInvocations1 = new Integer(expectedInvocations.get());
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations1));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations1));
return expectedInvocations1;
}
});
expectedInvocations.set(ex.intValue());
ex = (Integer) ds1.invoke(new SerializableCallable("Invoke loader from datastore, non-critical") {
public Object call() throws Exception {
Region<Integer, String> r = getCache().getRegion(rName);
Integer k = new Integer(2);
Integer expectedInvocations1 = new Integer(expectedInvocations.getAndIncrement());
// should load for new key
assertEquals(k.toString(), r.get(k, expectedInvocations1));
assertTrue(r.containsKey(k));
Integer expectedInvocations2 = new Integer(expectedInvocations.get());
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations2));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations2));
String oldVal = r.remove(k);
assertFalse(r.containsKey(k));
assertEquals(k.toString(), oldVal);
return expectedInvocations2;
}
});
expectedInvocations.set(ex.intValue());
accessor.invoke(addExpectedException);
ds1.invoke(addExpectedException);
ex = (Integer) ds1.invoke(new SerializableCallable("Set critical state, assert local load behavior") {
public Object call() throws Exception {
final OffHeapMemoryMonitor ohmm = ((InternalResourceManager) getCache().getResourceManager()).getOffHeapMonitor();
final PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
final RegionAdvisor advisor = pr.getRegionAdvisor();
pr.put("oh1", new byte[838860]);
pr.put("oh3", new byte[157287]);
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
for (final ProxyBucketRegion bucket : advisor.getProxyBucketArray()) {
if (bucket.isBucketSick()) {
return true;
}
}
return false;
}
};
Wait.waitForCriterion(wc, 30 * 1000, 10, true);
// reload with same key again and again
final Integer k = new Integer(2);
final Integer expectedInvocations3 = new Integer(expectedInvocations.getAndIncrement());
// load
assertEquals(k.toString(), pr.get(k, expectedInvocations3));
assertFalse(pr.containsKey(k));
Integer expectedInvocations4 = new Integer(expectedInvocations.getAndIncrement());
// load
assertEquals(k.toString(), pr.get(k, expectedInvocations4));
assertFalse(pr.containsKey(k));
Integer expectedInvocations5 = new Integer(expectedInvocations.get());
// load
assertEquals(k.toString(), pr.get(k, expectedInvocations5));
assertFalse(pr.containsKey(k));
return expectedInvocations5;
}
});
expectedInvocations.set(ex.intValue());
ex = (Integer) accessor.invoke(new SerializableCallable("During critical state on datastore, assert accesor load behavior") {
public Object call() throws Exception {
// reload with same key again and again
final Integer k = new Integer(2);
Integer expectedInvocations6 = new Integer(expectedInvocations.incrementAndGet());
Region<Integer, String> r = getCache().getRegion(rName);
// load
assertEquals(k.toString(), r.get(k, expectedInvocations6));
assertFalse(r.containsKey(k));
Integer expectedInvocations7 = new Integer(expectedInvocations.incrementAndGet());
// load
assertEquals(k.toString(), r.get(k, expectedInvocations7));
assertFalse(r.containsKey(k));
return expectedInvocations7;
}
});
expectedInvocations.set(ex.intValue());
ex = (Integer) ds1.invoke(new SerializableCallable("Set safe state on datastore, assert local load behavior") {
public Object call() throws Exception {
final PartitionedRegion r = (PartitionedRegion) getCache().getRegion(rName);
r.destroy("oh3");
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
return !r.memoryThresholdReached.get();
}
};
Wait.waitForCriterion(wc, 30 * 1000, 10, true);
// same key as previously used, this time is should stick
Integer k = new Integer(3);
Integer expectedInvocations8 = new Integer(expectedInvocations.incrementAndGet());
// last load for 3
assertEquals(k.toString(), r.get(k, expectedInvocations8));
assertTrue(r.containsKey(k));
return expectedInvocations8;
}
});
expectedInvocations.set(ex.intValue());
accessor.invoke(new SerializableCallable("Data store in safe state, assert load behavior, accessor sets critical state, assert load behavior") {
public Object call() throws Exception {
final OffHeapMemoryMonitor ohmm = ((InternalResourceManager) getCache().getResourceManager()).getOffHeapMonitor();
assertFalse(ohmm.getState().isCritical());
Integer k = new Integer(4);
Integer expectedInvocations9 = new Integer(expectedInvocations.incrementAndGet());
final PartitionedRegion r = (PartitionedRegion) getCache().getRegion(rName);
// load for 4
assertEquals(k.toString(), r.get(k, expectedInvocations9));
assertTrue(r.containsKey(k));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations9));
// Go critical in accessor
r.put("oh3", new byte[157287]);
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
return r.memoryThresholdReached.get();
}
};
k = new Integer(5);
Integer expectedInvocations10 = new Integer(expectedInvocations.incrementAndGet());
// load for key 5
assertEquals(k.toString(), r.get(k, expectedInvocations10));
assertTrue(r.containsKey(k));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations10));
// Clean up critical state
r.destroy("oh3");
wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
return !ohmm.getState().isCritical();
}
};
return expectedInvocations10;
}
});
accessor.invoke(removeExpectedException);
ds1.invoke(removeExpectedException);
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class PartitionedRegionQueryEvaluatorIntegrationTest method populateBucket2Node.
/**
* This function populates bucket2Node region of the partition region
*
* @param pr
*/
public void populateBucket2Node(PartitionedRegion pr, List nodes, int numOfBuckets) {
assertEquals(0, pr.getRegionAdvisor().getCreatedBucketsCount());
final RegionAdvisor ra = pr.getRegionAdvisor();
int nodeListCnt = 0;
Random ran = new Random();
// Map tracking version for profile insertion purposes
HashMap verMap = new HashMap();
for (int i = 0; i < numOfBuckets; i++) {
nodeListCnt = setNodeListCnt(nodeListCnt);
for (int j = 0; j < nodeListCnt; j++) {
BucketProfile bp = new BucketProfile();
bp.peerMemberId = (InternalDistributedMember) nodes.get(ran.nextInt(nodes.size()));
Integer v;
if ((v = (Integer) verMap.get(bp.getDistributedMember())) != null) {
bp.version = v.intValue() + 1;
verMap.put(bp.getDistributedMember(), new Integer(bp.version));
} else {
verMap.put(bp.getDistributedMember(), new Integer(0));
bp.version = 0;
}
bp.isHosting = true;
if (j == 0) {
bp.isPrimary = true;
}
bp.scope = Scope.DISTRIBUTED_ACK;
boolean forceBadProfile = true;
assertTrue(ra.getBucket(i).getBucketAdvisor().putProfile(bp, forceBadProfile));
}
}
}
use of org.apache.geode.internal.cache.partitioned.RegionAdvisor in project geode by apache.
the class PartitionedRegionQueryEvaluatorIntegrationTest method populateAllPartitionedRegion.
private void populateAllPartitionedRegion(PartitionedRegion pr, List nodes) {
// int totalNodes = 4;
Region rootReg = PartitionedRegionHelper.getPRRoot(pr.getCache());
// Region allPRs = PartitionedRegionHelper.getPRConfigRegion(rootReg, pr
// .getCache());
PartitionRegionConfig prConf = new PartitionRegionConfig(pr.getPRId(), pr.getFullPath(), pr.getPartitionAttributes(), pr.getScope());
RegionAdvisor ra = pr.getRegionAdvisor();
for (Iterator itr = nodes.iterator(); itr.hasNext(); ) {
Node n = (Node) itr.next();
prConf.addNode(n);
PartitionProfile pp = (PartitionProfile) ra.createProfile();
pp.peerMemberId = n.getMemberId();
pp.isDataStore = true;
final boolean forceFakeProfile = true;
pr.getRegionAdvisor().putProfile(pp, forceFakeProfile);
}
rootReg.put(pr.getRegionIdentifier(), prConf);
}
Aggregations