use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqServiceImpl method closeCq.
@Override
public void closeCq(String cqName, ClientProxyMembershipID clientProxyId) throws CqException {
String serverCqName = cqName;
if (clientProxyId != null) {
serverCqName = this.constructServerCqName(cqName, clientProxyId);
removeFromCacheForServerToConstructedCQName(cqName, clientProxyId);
}
ServerCQImpl cQuery = null;
StringId errMsg = null;
Exception ex = null;
try {
HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
if (!cqMap.containsKey(serverCqName)) {
/*
* gregp 052808: We should silently fail here instead of throwing error. This is to deal
* with races in recovery
*/
return;
}
cQuery = (ServerCQImpl) cqMap.get(serverCqName);
} catch (CacheLoaderException e1) {
errMsg = LocalizedStrings.CqService_CQ_NOT_FOUND_IN_THE_CQ_META_REGION_CQNAME_0;
ex = e1;
} catch (TimeoutException e2) {
errMsg = LocalizedStrings.CqService_TIMEOUT_WHILE_TRYING_TO_GET_CQ_FROM_META_REGION_CQNAME_0;
ex = e2;
} finally {
if (ex != null) {
String s = errMsg.toLocalizedString(cqName);
if (logger.isDebugEnabled()) {
logger.debug(s);
}
throw new CqException(s, ex);
}
}
try {
cQuery.close(false);
// CqBaseRegion
try {
LocalRegion baseRegion = cQuery.getCqBaseRegion();
if (baseRegion != null && !baseRegion.isDestroyed()) {
// Server specific clean up.
if (isServer()) {
FilterProfile fp = baseRegion.getFilterProfile();
if (fp != null) {
fp.closeCq(cQuery);
}
CacheClientProxy clientProxy = cQuery.getCacheClientNotifier().getClientProxy(clientProxyId);
clientProxy.decCqCount();
if (clientProxy.hasNoCq()) {
this.stats.decClientsWithCqs();
}
}
}
} catch (Exception e) {
// May be cache is being shutdown
if (logger.isDebugEnabled()) {
logger.debug("Failed to remove CQ from the base region. CqName : {}", cqName);
}
}
if (isServer()) {
removeFromBaseRegionToCqNameMap(cQuery.getRegionName(), serverCqName);
}
LocalRegion baseRegion = cQuery.getCqBaseRegion();
if (baseRegion.getFilterProfile().getCqCount() <= 0) {
if (logger.isDebugEnabled()) {
logger.debug("Should update the profile for this partitioned region {} for not requiring old value", baseRegion);
}
}
} catch (CqClosedException cce) {
throw new CqException(cce.getMessage());
} finally {
this.removeFromMatchingCqMap(cQuery);
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class ServerCQImpl method cleanup.
/**
* Clears the resource used by CQ.
*/
@Override
protected void cleanup() throws CqException {
// CqBaseRegion
try {
if (this.cqBaseRegion != null && !this.cqBaseRegion.isDestroyed()) {
this.cqBaseRegion.getFilterProfile().closeCq(this);
CacheClientProxy clientProxy = ccn.getClientProxy(clientProxyId);
clientProxy.decCqCount();
if (clientProxy.hasNoCq()) {
cqService.stats().decClientsWithCqs();
}
}
} catch (Exception ex) {
// May be cache is being shutdown
if (logger.isDebugEnabled()) {
logger.debug("Failed to remove CQ from the base region. CqName :{}", cqName);
}
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class MonitorCQ method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException {
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
int op = clientMessage.getPart(0).getInt();
if (op < 1) {
// This should have been taken care at the client - remove?
String err = LocalizedStrings.MonitorCQ__0_THE_MONITORCQ_OPERATION_IS_INVALID.toLocalizedString(serverConnection.getName());
sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
return;
}
String regionName = null;
if (clientMessage.getNumberOfParts() == 2) {
// This will be enable/disable on region.
regionName = clientMessage.getPart(1).getString();
if (regionName == null) {
// This should have been taken care at the client - remove?
String err = LocalizedStrings.MonitorCQ__0_A_NULL_REGION_NAME_WAS_PASSED_FOR_MONITORCQ_OPERATION.toLocalizedString(serverConnection.getName());
sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
return;
}
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Received MonitorCq request from {} op: {}{}", serverConnection.getName(), serverConnection.getSocketString(), op, (regionName != null) ? " RegionName: " + regionName : "");
}
this.securityService.authorizeClusterRead();
try {
CqService cqService = crHelper.getCache().getCqService();
cqService.start();
// Should never come.
throw new CqException(LocalizedStrings.CqService_INVALID_CQ_MONITOR_REQUEST_RECEIVED.toLocalizedString());
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
return;
} catch (Exception e) {
String err = LocalizedStrings.MonitorCQ_EXCEPTION_WHILE_HANDLING_THE_MONITOR_REQUEST_OP_IS_0.toLocalizedString(Integer.valueOf(op));
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e, serverConnection);
return;
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqDataUsingPoolDUnitTest method testCQWithEstablishCallBackConnection.
/**
* Test for CQ with establishCallBackConnection.
*/
@Test
public void testCQWithEstablishCallBackConnection() throws Exception {
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(1);
cqDUnitTest.createServer(server1, 0, false, MirrorType.KEYS_VALUES);
final int port1 = server1.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
final String poolName = "testCQWithEstablishCallBackConnection";
client.invoke(new CacheSerializableRunnable("createPool :" + poolName) {
@Override
public void run2() throws CacheException {
// Create Cache.
getCache();
PoolFactory cpf = PoolManager.createFactory();
cpf.setSubscriptionEnabled(false);
cpf.addServer(serverHost, port1);
cpf.create(poolName);
}
});
// Create CQs.
cqDUnitTest.createCQ(client, poolName, "testCQWithEstablishCallBackConnection_0", cqDUnitTest.cqs[0]);
// This should fail.
try {
cqDUnitTest.executeCQ(client, "testCQWithEstablishCallBackConnection_0", false, "CqException");
fail("Test should have failed with connection with establishCallBackConnection not found.");
} catch (Exception expected) {
// Expected.
}
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server1);
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testCloseAllCqsAndDrainEventsNoInterestRegistered.
/**
* Test functionality to close the cq and drain all events from the ha queue from the server This
* draining should remove all events due to no interest registered Continues to publish afterwards
* to verify that stats are correct
*/
@Test
public void testCloseAllCqsAndDrainEventsNoInterestRegistered() throws Exception {
String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
String allQuery = "select * from /" + regionName + " p where p.ID > -1";
String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
// Start server 1
Integer[] ports = ((Integer[]) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerReturnPorts(regionName, new Boolean(true))));
final int serverPort = ports[0].intValue();
final String durableClientId = getName() + "_client";
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
// send client ready
sendClientReady(durableClientVM);
// Verify durable client on server
verifyDurableClientOnServer(server1VM, durableClientId);
// Stop the durable client
this.disconnectDurableClient(true);
// Start normal publisher client
startClient(publisherClientVM, serverPort, regionName);
// Publish some entries
publishEntries(publisherClientVM, regionName, 10);
this.server1VM.invoke(new CacheSerializableRunnable("Close cq for durable client") {
@Override
public void run2() throws CacheException {
final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
ClientProxyMembershipID proxyId = clientProxy.getProxyID();
try {
ccnInstance.closeClientCq(durableClientId, "All");
ccnInstance.closeClientCq(durableClientId, "GreaterThan5");
ccnInstance.closeClientCq(durableClientId, "LessThan5");
} catch (CqException e) {
fail("failed", e);
}
}
});
// Restart the durable client
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// Reregister durable cqs
createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
// send client ready
sendClientReady(durableClientVM);
checkCqListenerEvents(durableClientVM, "GreaterThan5", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
checkCqListenerEvents(durableClientVM, "LessThan5", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
// Due to the implementation of DurableHARegionQueue where remove is called after dispatch.
// This can cause events to linger in the queue due to a "later" ack and only cleared on
// the next dispatch. We need to send one more message to dispatch, that calls remove one more
// time and any remaining acks (with or without this final published events ack)
flushEntries(server1VM, durableClientVM, regionName);
// the flush entry message may remain in the queue due
// verify the queue stats are as close/correct as possible
this.checkHAQueueSize(server1VM, durableClientId, 0, 1);
// continue to publish and make sure we get the events
publishEntries(publisherClientVM, regionName, 10);
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
10);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
10);
checkCqListenerEvents(durableClientVM, "All", 10, /* numEventsExpected */
10, /* numEventsToWaitFor */
10);
// Due to the implementation of DurableHARegionQueue where remove is called after dispatch.
// This can cause events to linger in the queue due to a "later" ack and only cleared on
// the next dispatch. We need to send one more message to dispatch, that calls remove one more
// time and any remaining acks (with or without this final published events ack)
flushEntries(server1VM, durableClientVM, regionName);
// the flush entry message may remain in the queue due
// verify the queue stats are as close/correct as possible
this.checkHAQueueSize(server1VM, durableClientId, 0, 1);
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
Aggregations