use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class ClientsWithVersioningRetryDUnitTest method testRetryPut.
/**
* Test that we can successfully retry a distributed put all and get the version information.
* second failure in bug 44951
*/
@Test
public void testRetryPut() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
createServerRegion(vm0, RegionShortcut.REPLICATE);
createServerRegion(vm1, RegionShortcut.REPLICATE);
// create an event tag in vm0 and then replay that event in vm1
final DistributedMember memberID = (DistributedMember) vm0.invoke(new SerializableCallable("get id") {
public Object call() {
return ((DistributedRegion) getCache().getRegion("region")).getDistributionManager().getDistributionManagerId();
}
});
vm0.invoke(new SerializableCallable("create entry with fake event ID") {
@Override
public Object call() {
DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
VersionTag tag = new VMVersionTag();
tag.setMemberID(dr.getVersionMember());
tag.setRegionVersion(123);
tag.setEntryVersion(9);
tag.setVersionTimeStamp(System.currentTimeMillis());
EventID eventID = new EventID(new byte[0], 1, 0);
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
event.setVersionTag(tag);
event.setContext(new ClientProxyMembershipID(memberID));
dr.recordEvent(event);
event.release();
return memberID;
}
});
vm1.invoke(new SerializableRunnable("recover event tag in vm1 from vm0") {
@Override
public void run() {
DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
EventID eventID = new EventID(new byte[0], 1, 0);
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
try {
event.setContext(new ClientProxyMembershipID(memberID));
boolean recovered = ((BaseCommand) Put70.getCommand()).recoverVersionTagForRetriedOperation(event);
assertTrue("Expected to recover the version for this event ID", recovered);
assertEquals("Expected the region version to be 123", 123, event.getVersionTag().getRegionVersion());
} finally {
event.release();
}
}
});
// bug #48205 - a retried op in PR nodes not owning the primary bucket
// may already have a version assigned to it in another backup bucket
vm1.invoke(new SerializableRunnable("recover posdup event tag in vm1 event tracker from vm0") {
@Override
public void run() {
DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
EventID eventID = new EventID(new byte[0], 1, 0);
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
event.setPossibleDuplicate(true);
try {
dr.hasSeenEvent(event);
assertTrue("Expected to recover the version for the event ID", event.getVersionTag() != null);
} finally {
event.release();
}
}
});
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class MemoryThresholdsOffHeapDUnitTest method doDistributedRegionRemotePutRejection.
/**
* test that puts in a server are rejected when a remote VM crosses critical threshold
*
* @throws Exception
*/
private void doDistributedRegionRemotePutRejection(boolean localDestroy, boolean cacheClose) throws Exception {
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM server2 = host.getVM(1);
final String regionName = "offHeapDRRemotePutRejection";
// set port to 0 in-order for system to pickup a random port.
startCacheServer(server1, 0f, 0f, regionName, false, /* createPR */
false, /* notifyBySubscription */
0);
startCacheServer(server2, 0f, 90f, regionName, false, /* createPR */
false, /* notifyBySubscription */
0);
registerTestMemoryThresholdListener(server1);
registerTestMemoryThresholdListener(server2);
doPuts(server1, regionName, false, /* catchRejectedException */
false);
doPutAlls(server1, regionName, false, /* catchRejectedException */
false, /* catchLowMemoryException */
Range.DEFAULT);
// make server2 critical
setUsageAboveCriticalThreshold(server2, regionName);
verifyListenerValue(server1, MemoryState.CRITICAL, 1, true);
verifyListenerValue(server2, MemoryState.CRITICAL, 1, true);
// make sure that local server1 puts are rejected
doPuts(server1, regionName, false, /* catchRejectedException */
true);
Range r1 = new Range(Range.DEFAULT, Range.DEFAULT.width() + 1);
doPutAlls(server1, regionName, false, /* catchRejectedException */
true, /* catchLowMemoryException */
r1);
if (localDestroy) {
// local destroy the region on sick member
server2.invoke(new SerializableCallable("local destroy") {
public Object call() throws Exception {
Region r = getRootRegion().getSubregion(regionName);
r.localDestroyRegion();
return null;
}
});
} else if (cacheClose) {
server2.invoke(new SerializableCallable() {
public Object call() throws Exception {
getCache().close();
return null;
}
});
} else {
setUsageBelowEviction(server2, regionName);
}
// wait for remote region destroyed message to be processed
server1.invoke(new SerializableCallable() {
public Object call() throws Exception {
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "remote localRegionDestroyed message not received";
}
public boolean done() {
DistributedRegion dr = (DistributedRegion) getRootRegion().getSubregion(regionName);
return dr.getMemoryThresholdReachedMembers().size() == 0;
}
};
Wait.waitForCriterion(wc, 10000, 10, true);
return null;
}
});
// make sure puts succeed
doPuts(server1, regionName, false, /* catchRejectedException */
false);
Range r2 = new Range(r1, r1.width() + 1);
doPutAlls(server1, regionName, false, /* catchRejectedException */
false, /* catchLowMemoryException */
r2);
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class MemoryThresholdsDUnitTest method startCacheServer.
/**
* Starts up a CacheServer.
*
* @return a {@link ServerPorts} containing the CacheServer ports.
*/
private ServerPorts startCacheServer(VM server, final float evictionThreshold, final float criticalThreshold, final String regionName, final boolean createPR, final boolean notifyBySubscription, final int prRedundancy) throws Exception {
return (ServerPorts) server.invoke(new SerializableCallable() {
public Object call() throws Exception {
getSystem(getServerProperties());
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
InternalResourceManager irm = cache.getInternalResourceManager();
HeapMemoryMonitor hmm = irm.getHeapMonitor();
hmm.setTestMaxMemoryBytes(1000);
HeapMemoryMonitor.setTestBytesUsedForThresholdSet(500);
irm.setEvictionHeapPercentage(evictionThreshold);
irm.setCriticalHeapPercentage(criticalThreshold);
AttributesFactory factory = new AttributesFactory();
if (createPR) {
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(prRedundancy);
paf.setTotalNumBuckets(11);
factory.setPartitionAttributes(paf.create());
} else {
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
}
Region region = createRegion(regionName, factory.create());
if (createPR) {
assertTrue(region instanceof PartitionedRegion);
} else {
assertTrue(region instanceof DistributedRegion);
}
CacheServer cacheServer = getCache().addCacheServer();
int port = AvailablePortHelper.getRandomAvailableTCPPorts(1)[0];
cacheServer.setPort(port);
cacheServer.setNotifyBySubscription(notifyBySubscription);
cacheServer.start();
return new ServerPorts(port);
}
});
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.
@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
vm1.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof PrepareNewPersistentMemberMessage) {
DistributionMessageObserver.setInstance(null);
getSystem().disconnect();
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
putAnEntry(vm0);
updateTheEntry(vm0);
try {
createPersistentRegion(vm1);
} catch (Exception e) {
if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
throw e;
}
}
closeRegion(vm0);
// This wait for VM0 to come back
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
waitForBlockedInitialization(vm1);
createPersistentRegion(vm0);
async1.getResult();
checkForEntry(vm1);
vm0.invoke(new SerializableRunnable("check for offline members") {
public void run() {
Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
DiskRegion dr = region.getDiskRegion();
assertEquals(Collections.emptySet(), dr.getOfflineMembers());
assertEquals(1, dr.getOnlineMembers().size());
}
});
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class MembershipViewRequest method process.
@Override
protected void process(DistributionManager dm) {
int initLevel = this.targetReinitializing ? LocalRegion.AFTER_INITIAL_IMAGE : LocalRegion.ANY_INIT;
int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
PersistentMembershipView view = null;
ReplyException exception = null;
try {
// get the region from the path, but do NOT wait on initialization,
// otherwise we could have a distributed deadlock
Cache cache = CacheFactory.getInstance(dm.getSystem());
Region region = cache.getRegion(this.regionPath);
PersistenceAdvisor persistenceAdvisor = null;
if (region instanceof DistributedRegion) {
persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
} else if (region == null) {
Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
if (proxy != null) {
persistenceAdvisor = proxy.getPersistenceAdvisor();
}
}
if (persistenceAdvisor != null) {
view = persistenceAdvisor.getMembershipView();
}
} catch (RegionDestroyedException e) {
// exception = new ReplyException(e);
logger.debug("<RegionDestroyed> {}", this);
} catch (CancelException e) {
// exception = new ReplyException(e);
logger.debug("<CancelException> {}", this);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
exception = new ReplyException(t);
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
MembershipViewReplyMessage replyMsg = new MembershipViewReplyMessage();
replyMsg.setRecipient(getSender());
replyMsg.setProcessorId(processorId);
replyMsg.view = view;
if (logger.isDebugEnabled()) {
logger.debug("MembershipViewRequest returning view {} for region {}", view, this.regionPath);
}
if (exception != null) {
replyMsg.setException(exception);
}
dm.putOutgoing(replyMsg);
}
}
Aggregations