use of org.apache.geode.CancelException in project geode by apache.
the class LuceneIndexForPartitionedRegion method destroyOnRemoteMembers.
private void destroyOnRemoteMembers() {
PartitionedRegion pr = (PartitionedRegion) getDataRegion();
DM dm = pr.getDistributionManager();
Set<InternalDistributedMember> recipients = pr.getRegionAdvisor().adviseAllPRNodes();
if (!recipients.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("LuceneIndexForPartitionedRegion: About to send destroy message recipients=" + recipients);
}
ReplyProcessor21 processor = new ReplyProcessor21(dm, recipients);
DestroyLuceneIndexMessage message = new DestroyLuceneIndexMessage(recipients, processor.getProcessorId(), regionPath, indexName);
dm.putOutgoing(message);
if (logger.isDebugEnabled()) {
logger.debug("LuceneIndexForPartitionedRegion: Sent message recipients=" + recipients);
}
try {
processor.waitForReplies();
} catch (ReplyException e) {
if (!(e.getCause() instanceof CancelException)) {
throw e;
}
} catch (InterruptedException e) {
dm.getCancelCriterion().checkCancelInProgress(e);
Thread.currentThread().interrupt();
}
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class GatewaySenderEventRemoteDispatcher method readAcknowledgement.
protected GatewayAck readAcknowledgement() {
SenderProxy sp = new SenderProxy(this.processor.getSender().getProxy());
GatewayAck ack = null;
Exception ex;
try {
connection = getConnection(false);
if (logger.isDebugEnabled()) {
logger.debug(" Receiving ack on the thread {}", connection);
}
this.connectionLifeCycleLock.readLock().lock();
try {
if (connection != null && !processor.isStopped()) {
ack = (GatewayAck) sp.receiveAckFromReceiver(connection);
}
} finally {
this.connectionLifeCycleLock.readLock().unlock();
}
} catch (Exception e) {
Throwable t = e.getCause();
if (t instanceof BatchException70) {
// A BatchException has occurred.
// Do not process the connection as dead since it is not dead.
ex = (BatchException70) t;
} else if (e instanceof GatewaySenderException) {
// This Exception is thrown from
// getConnection
ex = (Exception) e.getCause();
} else {
ex = e;
// keep using the connection if we had a batch exception. Else, destroy
// it
destroyConnection();
}
if (this.sender.getProxy() == null || this.sender.getProxy().isDestroyed()) {
// if our pool is shutdown then just be silent
} else if (ex instanceof IOException || (ex instanceof ServerConnectivityException && !(ex.getCause() instanceof PdxRegistryMismatchException)) || ex instanceof ConnectionDestroyedException) {
// Sleep for a bit and recheck.
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
} else {
if (!(ex instanceof CancelException)) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayEventRemoteDispatcher_STOPPING_THE_PROCESSOR_BECAUSE_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_PROCESSING_A_BATCH), ex);
}
this.processor.setIsStopped(true);
}
}
return ack;
}
use of org.apache.geode.CancelException in project geode by apache.
the class Bug39356DUnitTest method testCrashWhileCreatingABucket.
/**
* This tests the case where the VM forcing other VMs to create a bucket crashes while creating
* the bucket.
*/
@Test
public void testCrashWhileCreatingABucket() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
SerializableRunnable createParReg = new SerializableRunnable("Create parReg") {
public void run() {
DistributionMessageObserver.setInstance(new MyRegionObserver(vm0));
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory pf = new PartitionAttributesFactory();
pf.setRedundantCopies(1);
pf.setRecoveryDelay(0);
af.setDataPolicy(DataPolicy.PARTITION);
af.setPartitionAttributes(pf.create());
cache.createRegion(REGION_NAME, af.create());
}
};
vm1.invoke(createParReg);
vm2.invoke(createParReg);
SerializableRunnable createParRegAccessor = new SerializableRunnable("Create parReg") {
public void run() {
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory pf = new PartitionAttributesFactory();
pf.setRedundantCopies(1);
pf.setLocalMaxMemory(0);
af.setDataPolicy(DataPolicy.PARTITION);
af.setPartitionAttributes(pf.create());
Region r = cache.createRegion(REGION_NAME, af.create());
// trigger the creation of a bucket, which should trigger the destruction of this VM.
try {
r.put("ping", "pong");
fail("Should have gotten a CancelException");
} catch (CancelException e) {
// this is ok, we expect our observer to close this cache.
}
}
};
vm0.invoke(createParRegAccessor);
SerializableRunnable verifyBuckets = new SerializableRunnable("Verify buckets") {
public void run() {
LogWriter log = org.apache.geode.test.dunit.LogWriterUtils.getLogWriter();
Cache cache = getCache();
PartitionedRegion r = (PartitionedRegion) cache.getRegion(REGION_NAME);
for (int i = 0; i < r.getAttributes().getPartitionAttributes().getTotalNumBuckets(); i++) {
List owners = null;
while (owners == null) {
try {
owners = r.getBucketOwnersForValidation(i);
} catch (ForceReattemptException e) {
log.info(Bug39356DUnitTest.class + " verify buckets Caught a ForceReattemptException");
Wait.pause(1000);
}
}
if (owners.isEmpty()) {
log.info("skipping bucket " + i + " because it has no data");
continue;
}
assertEquals("Expecting bucket " + i + " to have two copies", 2, owners.size());
log.info("bucket " + i + " had two copies");
}
}
};
vm1.invoke(verifyBuckets);
vm2.invoke(verifyBuckets);
}
use of org.apache.geode.CancelException in project geode by apache.
the class RootRegionResponse method create.
/**
* Returns a {@code RootRegionResponse} that will be returned to the specified recipient. The
* message will contains a copy of the local manager's system config.
*/
public static RootRegionResponse create(DistributionManager dm, InternalDistributedMember recipient) {
RootRegionResponse m = new RootRegionResponse();
try {
InternalCache cache = (InternalCache) CacheFactory.getInstance(dm.getSystem());
final Collection roots;
if (!Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRDebug")) {
roots = cache.rootRegions();
} else {
roots = cache.rootRegions(true);
}
List regionNames = new ArrayList();
List userAttributes = new ArrayList();
for (Object root : roots) {
Region r = (Region) root;
regionNames.add(r.getName());
userAttributes.add(CacheDisplay.getCachedObjectDisplay(r.getUserAttribute(), GemFireVM.LIGHTWEIGHT_CACHE_VALUE));
}
String[] temp = new String[0];
m.regions = (String[]) regionNames.toArray(temp);
m.userAttrs = (String[]) userAttributes.toArray(temp);
;
} catch (CancelException ignore) {
/* no cache yet */
}
m.setRecipient(recipient);
return m;
}
use of org.apache.geode.CancelException in project geode by apache.
the class ShutdownAllRequest method send.
/**
* Sends a shutdownAll request to all other members and performs local shutdownAll processing in
* the waitingThreadPool.
*/
public static Set send(final DM dm, long timeout) {
boolean hadCache = hasCache();
DistributionManager dism = dm instanceof DistributionManager ? (DistributionManager) dm : null;
InternalDistributedMember myId = dm.getDistributionManagerId();
Set recipients = dm.getOtherNormalDistributionManagerIds();
recipients.remove(myId);
// now do shutdownall
ShutdownAllRequest request = new ShutdownAllRequest();
request.setRecipients(recipients);
ShutDownAllReplyProcessor replyProcessor = new ShutDownAllReplyProcessor(dm, recipients);
request.msgId = replyProcessor.getProcessorId();
dm.putOutgoing(request);
if (!InternalLocator.isDedicatedLocator()) {
if (hadCache && dism != null) {
AdminResponse response;
try {
request.setSender(myId);
response = request.createResponse(dism);
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("caught exception while processing shutdownAll locally", ex);
}
response = AdminFailureResponse.create(dism, myId, ex);
}
response.setSender(myId);
replyProcessor.process(response);
}
}
boolean interrupted = false;
try {
if (!replyProcessor.waitForReplies(timeout)) {
return null;
}
} catch (ReplyException e) {
if (!(e.getCause() instanceof CancelException)) {
e.handleAsUnexpected();
}
} catch (CancelException ignore) {
// expected
} catch (InterruptedException ignore) {
interrupted = true;
}
// wait until all the recipients send response, shut down itself (if not a locator)
if (hadCache) {
// because the cache is closed at GemFireCacheImpl.getInstance().shutDownAll()
if (!InternalLocator.isDedicatedLocator()) {
InternalDistributedSystem ids = dm.getSystem();
if (ids.isConnected()) {
ids.disconnect();
}
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
try {
Thread.sleep(3 * SLEEP_TIME_BEFORE_DISCONNECT_DS);
} catch (InterruptedException ignore) {
}
return replyProcessor.getResults();
}
Aggregations