use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class SystemFailureDUnitTest method verifyDisconnected.
protected static Boolean verifyDisconnected() {
if (SystemFailure.getFailure() == null) {
fail("No system failure present!");
return Boolean.FALSE;
}
GemFireCacheImpl gfc = (GemFireCacheImpl) cache;
// Allow cache time to finish disconnecting
long done = System.currentTimeMillis() + MAX_WAIT;
for (; ; ) {
long now = System.currentTimeMillis();
if (now >= done) {
fail("Time out waiting for cache to close: " + cache.toString());
return Boolean.FALSE;
}
if (gfc.isClosed()) {
break;
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
fail("interrupted");
return Boolean.FALSE;
}
}
// At this point, the cache we peeked earlier should be unavailable
assertTrue(GemFireCacheImpl.getInstance() == null);
// Ditto for the distributed system
InternalDistributedSystem ids = (InternalDistributedSystem) gfc.getDistributedSystem();
if (ids == null) {
// uhhh, pretty dead!
return Boolean.TRUE;
}
try {
DistributionManager dm = (DistributionManager) ids.getDistributionManager();
if (dm == null) {
return Boolean.TRUE;
}
return new Boolean(dm.getCancelCriterion().isCancelInProgress());
} catch (CancelException e) {
// TODO -- it would be nice to avoid the checkConnected() call above
return Boolean.TRUE;
}
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method doTestPersistConflictOperations.
/**
* vm0 and vm1 are peers, each holds a DR. They do put to the same key for different value at the
* same time. Use DistributionMessageObserver.beforeSendMessage to hold on the distribution
* message. One of the member will persist the conflict version tag, while another member will
* persist both of the 2 operations. Overall, their RVV should match after the operations.
*/
public void doTestPersistConflictOperations(boolean diskSync) 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
SerializableRunnable addObserver = new SerializableRunnable() {
public void run() {
// System.setProperty("disk.TRACE_WRITES", "true");
// System.setProperty("disk.TRACE_RECOVERY", "true");
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof AbstractUpdateMessage) {
try {
Thread.sleep(2000);
getCache().getLogger().info("testPersistConflictOperations, beforeSendMessage");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof AbstractUpdateMessage) {
getCache().getLogger().info("testPersistConflictOperations, beforeSendMessage");
DistributionMessageObserver.setInstance(null);
}
}
});
}
};
vm0.invoke(addObserver);
vm1.invoke(addObserver);
AsyncInvocation future0 = createPersistentRegionAsync(vm0, diskSync);
AsyncInvocation future1 = createPersistentRegionAsync(vm1, diskSync);
future0.join(MAX_WAIT);
future1.join(MAX_WAIT);
// createPersistentRegion(vm0);
// createPersistentRegion(vm1);
AsyncInvocation ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.put("A", "vm0");
}
});
AsyncInvocation ins1 = vm1.invokeAsync(new SerializableRunnable("change the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.put("A", "vm1");
}
});
ins0.join(MAX_WAIT);
ins1.join(MAX_WAIT);
RegionVersionVector rvv0 = getRVV(vm0);
RegionVersionVector rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
Object value0 = getEntry(vm0, "A");
Object value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
closeRegion(vm0);
closeRegion(vm1);
// recover
future1 = createPersistentRegionAsync(vm1, diskSync);
future0 = createPersistentRegionAsync(vm0, diskSync);
future1.join(MAX_WAIT);
future0.join(MAX_WAIT);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
// round 2: async disk write
vm0.invoke(addObserver);
vm1.invoke(addObserver);
ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm0") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 1000; i++) {
region.put("A", "vm0-" + i);
}
}
});
ins1 = vm1.invokeAsync(new SerializableRunnable("change the entry at vm1") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 1000; i++) {
region.put("A", "vm1-" + i);
}
}
});
ins0.join(MAX_WAIT);
ins1.join(MAX_WAIT);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
closeCache(vm0);
closeCache(vm1);
// recover again
future1 = createPersistentRegionAsync(vm1, diskSync);
future0 = createPersistentRegionAsync(vm0, diskSync);
future1.join(MAX_WAIT);
future0.join(MAX_WAIT);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testMissingEntryOnDisk.
@Test
public void testMissingEntryOnDisk() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will perform some updates while the region is initializing
vm0.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
if (region == null) {
LogWriterUtils.getLogWriter().severe("removing listener for PersistentRecoveryOrderDUnitTest because region was not found: " + REGION_NAME);
Object old = DistributionMessageObserver.setInstance(null);
if (old != this) {
LogWriterUtils.getLogWriter().severe("removed listener was not the invoked listener", new Exception("stack trace"));
}
return;
}
region.put("A", "B");
region.destroy("A");
region.put("A", "C");
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
createPersistentRegion(vm1);
checkForEntry(vm1);
closeRegion(vm0);
closeRegion(vm1);
// This should work
createPersistentRegion(vm1);
checkForEntry(vm1);
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testGIIDuringDestroy.
/**
* Test to make sure we don't leak any persistent ids if a member does GII while a distributed
* destroy is in progress
*/
@Test
public void testGIIDuringDestroy() throws Exception {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
// Add a hook which will disconnect from the distributed
// system when the initial image message shows up.
vm1.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof DestroyRegionMessage) {
createPersistentRegionAsync(vm2);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DistributionMessageObserver.setInstance(null);
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
}
});
}
});
createPersistentRegion(vm1);
vm0.invoke(new SerializableRunnable("Destroy region") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.destroyRegion();
}
});
vm1.invoke(new SerializableRunnable("check destroyed") {
public void run() {
Cache cache = getCache();
assertNull(cache.getRegion(REGION_NAME));
}
});
vm2.invoke(new SerializableRunnable("Wait for region creation") {
public void run() {
final Cache cache = getCache();
Wait.waitForCriterion(new WaitCriterion() {
public String description() {
return "Waiting for creation of region " + REGION_NAME;
}
public boolean done() {
Region region = cache.getRegion(REGION_NAME);
return region != null;
}
}, MAX_WAIT, 100, true);
}
});
vm2.invoke(new SerializableRunnable("Check offline members") {
public void run() {
final Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
PersistenceAdvisor persistAdvisor = region.getPersistenceAdvisor();
assertEquals(Collections.emptySet(), persistAdvisor.getMembershipView().getOfflineMembers());
}
});
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testCrashDuringGII.
/**
* Test to make sure that if if a member crashes while a GII is in progress, we wait for the
* member to come back for starting.
*/
@Test
public void testCrashDuringGII() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
putAnEntry(vm0);
LogWriterUtils.getLogWriter().info("closing region in vm0");
closeRegion(vm0);
updateTheEntry(vm1);
LogWriterUtils.getLogWriter().info("closing region in vm1");
closeRegion(vm1);
// This ought to wait for VM1 to come back
LogWriterUtils.getLogWriter().info("Creating region in VM0");
AsyncInvocation future = createPersistentRegionAsync(vm0);
waitForBlockedInitialization(vm0);
assertTrue(future.isAlive());
// Add a hook which will disconnect from the distributed
// system when the initial image message shows up.
vm1.invoke(new SerializableRunnable() {
public void run() {
sawRequestImageMessage.set(false);
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS();
synchronized (sawRequestImageMessage) {
sawRequestImageMessage.set(true);
sawRequestImageMessage.notifyAll();
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm1);
vm1.invoke(new SerializableRunnable() {
public void run() {
synchronized (sawRequestImageMessage) {
try {
while (!sawRequestImageMessage.get()) {
sawRequestImageMessage.wait();
}
} catch (InterruptedException ex) {
}
}
}
});
waitForBlockedInitialization(vm0);
assertTrue(future.isAlive());
// Now create the region again. The initialization should
// work (the observer was cleared when we disconnected from the DS.
createPersistentRegion(vm1);
;
future.join(MAX_WAIT);
if (future.isAlive()) {
fail("Region not created within" + MAX_WAIT);
}
if (future.exceptionOccurred()) {
throw new Exception(future.getException());
}
checkForEntry(vm0);
checkForEntry(vm1);
checkForRecoveryStat(vm1, true);
checkForRecoveryStat(vm0, false);
}
Aggregations