use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.
the class ManageBucketMessage method send.
/**
* Sends a PartitionedRegion manage bucket request to the recipient
*
* @param recipient the member to which the bucket manage request is sent
* @param r the PartitionedRegion to which the bucket belongs
* @param bucketId the unique identifier of the bucket
* @param bucketSize the size in bytes of the bucket
* @param forceCreation inform the recipient to accept the bucket appropriately ignoring maximums
* @return the processor used to fetch the returned Node if any
* @throws ForceReattemptException if the peer is no longer available
*/
public static NodeResponse send(InternalDistributedMember recipient, PartitionedRegion r, int bucketId, int bucketSize, boolean forceCreation) throws ForceReattemptException {
Assert.assertTrue(recipient != null, "ManageBucketMessage NULL recipient");
NodeResponse p = new NodeResponse(r.getSystem(), recipient);
ManageBucketMessage m = new ManageBucketMessage(recipient, r.getPRId(), p, bucketId, bucketSize, forceCreation);
p.enableSevereAlertProcessing();
Set failures = r.getDistributionManager().putOutgoing(m);
if (failures != null && failures.size() > 0) {
throw new ForceReattemptException(LocalizedStrings.ManageBucketMessage_FAILED_SENDING_0.toLocalizedString(m));
}
return p;
}
use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.
the class PartitionRegionHelperDUnitTest method testMembersForKey.
@Test
public void testMembersForKey() throws Exception {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM ds1 = host.getVM(1);
VM ds2 = host.getVM(2);
VM ds3 = host.getVM(3);
final String prName = getUniqueName();
final int tb = 11;
final int rc = 1;
accessor.invoke(new SerializableRunnable("createAccessor") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
attr.setPartitionAttributes(new PartitionAttributesFactory().setLocalMaxMemory(0).setRedundantCopies(rc).setTotalNumBuckets(tb).create());
cache.createRegion(prName, attr.create());
}
});
HashMap<DistributedMember, VM> d2v = new HashMap<DistributedMember, VM>();
SerializableCallable createPrRegion = new SerializableCallable("createDataStore") {
public Object call() throws Exception {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
attr.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(rc).setTotalNumBuckets(tb).create());
cache.createRegion(prName, attr.create());
return cache.getDistributedSystem().getDistributedMember();
}
};
DistributedMember dm = (DistributedMember) ds1.invoke(createPrRegion);
d2v.put(dm, ds1);
dm = (DistributedMember) ds2.invoke(createPrRegion);
d2v.put(dm, ds2);
dm = (DistributedMember) ds3.invoke(createPrRegion);
d2v.put(dm, ds3);
final Integer buk0Key1 = new Integer(0);
final Integer buk0Key2 = new Integer(buk0Key1.intValue() + tb);
final Integer buk1Key1 = new Integer(1);
accessor.invoke(new CacheSerializableRunnable("nonPRcheck") {
@SuppressWarnings("unchecked")
@Override
public void run2() throws CacheException {
AttributesFactory attr = new AttributesFactory();
{
attr.setScope(Scope.LOCAL);
Region lr = getCache().createRegion(prName + "lr", attr.create());
try {
// no-pr check
nonPRMemberForKey(lr, buk0Key1);
} finally {
lr.destroyRegion();
}
}
{
attr = new AttributesFactory();
attr.setScope(Scope.DISTRIBUTED_ACK);
Region dr = getCache().createRegion(prName + "dr", attr.create());
try {
// no-pr check
nonPRMemberForKey(dr, buk0Key1);
} finally {
dr.destroyRegion();
}
}
}
private void nonPRMemberForKey(Region lr, final Object key) {
try {
PartitionRegionHelper.getPrimaryMemberForKey(lr, key);
fail();
} catch (IllegalArgumentException expected) {
}
try {
PartitionRegionHelper.getAllMembersForKey(lr, key);
fail();
} catch (IllegalArgumentException expected) {
}
try {
PartitionRegionHelper.getRedundantMembersForKey(lr, key);
fail();
} catch (IllegalArgumentException expected) {
}
}
});
Object[] noKeyThenKeyStuff = (Object[]) accessor.invoke(new SerializableCallable("noKeyThenKey") {
public Object call() throws Exception {
Region<Integer, String> r = getCache().getRegion(prName);
// NPE check
try {
PartitionRegionHelper.getPrimaryMemberForKey(r, null);
fail();
} catch (IllegalStateException expected) {
}
try {
PartitionRegionHelper.getAllMembersForKey(r, null);
fail();
} catch (IllegalStateException expected) {
}
try {
PartitionRegionHelper.getRedundantMembersForKey(r, null);
fail();
} catch (IllegalStateException expected) {
}
// buk0
assertNull(PartitionRegionHelper.getPrimaryMemberForKey(r, buk0Key1));
assertTrue(PartitionRegionHelper.getAllMembersForKey(r, buk0Key1).isEmpty());
assertTrue(PartitionRegionHelper.getRedundantMembersForKey(r, buk0Key1).isEmpty());
// buk1
assertNull(PartitionRegionHelper.getPrimaryMemberForKey(r, buk1Key1));
assertTrue(PartitionRegionHelper.getAllMembersForKey(r, buk1Key1).isEmpty());
assertTrue(PartitionRegionHelper.getRedundantMembersForKey(r, buk1Key1).isEmpty());
r.put(buk0Key1, "zero");
// buk0, key1
DistributedMember key1Pri = PartitionRegionHelper.getPrimaryMemberForKey(r, buk0Key1);
assertNotNull(key1Pri);
Set<DistributedMember> buk0AllMems = PartitionRegionHelper.getAllMembersForKey(r, buk0Key1);
assertEquals(rc + 1, buk0AllMems.size());
Set<DistributedMember> buk0RedundantMems = PartitionRegionHelper.getRedundantMembersForKey(r, buk0Key1);
assertEquals(rc, buk0RedundantMems.size());
DistributedMember me = r.getCache().getDistributedSystem().getDistributedMember();
try {
buk0AllMems.add(me);
fail();
} catch (UnsupportedOperationException expected) {
}
try {
buk0AllMems.remove(me);
fail();
} catch (UnsupportedOperationException expected) {
}
try {
buk0RedundantMems.add(me);
fail();
} catch (UnsupportedOperationException expected) {
}
try {
buk0RedundantMems.remove(me);
fail();
} catch (UnsupportedOperationException expected) {
}
assertTrue(buk0AllMems.containsAll(buk0RedundantMems));
assertTrue(buk0AllMems.contains(key1Pri));
assertTrue(!buk0RedundantMems.contains(key1Pri));
// buk0, key2
DistributedMember key2Pri = PartitionRegionHelper.getPrimaryMemberForKey(r, buk0Key2);
assertNotNull(key2Pri);
buk0AllMems = PartitionRegionHelper.getAllMembersForKey(r, buk0Key2);
assertEquals(rc + 1, buk0AllMems.size());
buk0RedundantMems = PartitionRegionHelper.getRedundantMembersForKey(r, buk0Key2);
assertEquals(rc, buk0RedundantMems.size());
assertTrue(buk0AllMems.containsAll(buk0RedundantMems));
assertTrue(buk0AllMems.contains(key2Pri));
assertTrue(!buk0RedundantMems.contains(key2Pri));
// buk1
assertNull(PartitionRegionHelper.getPrimaryMemberForKey(r, buk1Key1));
assertTrue(PartitionRegionHelper.getAllMembersForKey(r, buk1Key1).isEmpty());
assertTrue(PartitionRegionHelper.getRedundantMembersForKey(r, buk1Key1).isEmpty());
return new Object[] { key1Pri, buk0AllMems, buk0RedundantMems };
}
});
final DistributedMember buk0Key1Pri = (DistributedMember) noKeyThenKeyStuff[0];
final Set<DistributedMember> buk0AllMems = (Set<DistributedMember>) noKeyThenKeyStuff[1];
final Set<DistributedMember> buk0Redundants = (Set<DistributedMember>) noKeyThenKeyStuff[2];
VM buk0Key1PriVM = d2v.get(buk0Key1Pri);
buk0Key1PriVM.invoke(new CacheSerializableRunnable("assertPrimaryness") {
@Override
public void run2() throws CacheException {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(prName);
Integer bucketId = new Integer(PartitionedRegionHelper.getHashKey(pr, null, buk0Key1, null, null));
try {
BucketRegion buk0 = pr.getDataStore().getInitializedBucketForId(buk0Key1, bucketId);
assertNotNull(buk0);
assertTrue(buk0.getBucketAdvisor().isPrimary());
} catch (ForceReattemptException e) {
LogWriterUtils.getLogWriter().severe(e);
fail();
}
}
});
CacheSerializableRunnable assertHasBucket = new CacheSerializableRunnable("assertHasBucketAndKey") {
@Override
public void run2() throws CacheException {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(prName);
Integer bucketId = new Integer(PartitionedRegionHelper.getHashKey(pr, null, buk0Key1, null, null));
try {
BucketRegion buk0 = pr.getDataStore().getInitializedBucketForId(buk0Key1, bucketId);
assertNotNull(buk0);
Entry k1e = buk0.getEntry(buk0Key1);
assertNotNull(k1e);
} catch (ForceReattemptException e) {
LogWriterUtils.getLogWriter().severe(e);
fail();
}
}
};
for (DistributedMember bom : buk0AllMems) {
VM v = d2v.get(bom);
LogWriterUtils.getLogWriter().info("Visiting bucket owner member " + bom + " for key " + buk0Key1);
v.invoke(assertHasBucket);
}
CacheSerializableRunnable assertRed = new CacheSerializableRunnable("assertRedundant") {
@Override
public void run2() throws CacheException {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(prName);
Integer bucketId = new Integer(PartitionedRegionHelper.getHashKey(pr, null, buk0Key1, null, null));
try {
BucketRegion buk0 = pr.getDataStore().getInitializedBucketForId(buk0Key1, bucketId);
assertNotNull(buk0);
assertFalse(buk0.getBucketAdvisor().isPrimary());
} catch (ForceReattemptException e) {
LogWriterUtils.getLogWriter().severe(e);
fail();
}
}
};
for (DistributedMember redm : buk0Redundants) {
VM v = d2v.get(redm);
LogWriterUtils.getLogWriter().info("Visiting redundant member " + redm + " for key " + buk0Key1);
v.invoke(assertRed);
}
}
Aggregations