Search in sources :

Example 31 with CqException

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);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TimeoutException(org.apache.geode.cache.TimeoutException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqClosedException(org.apache.geode.cache.query.CqClosedException) QueryException(org.apache.geode.cache.query.QueryException) FilterProfile(org.apache.geode.internal.cache.FilterProfile) StringId(org.apache.geode.i18n.StringId) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 32 with CqException

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);
        }
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) QueryException(org.apache.geode.cache.query.QueryException)

Example 33 with CqException

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;
    }
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) CqException(org.apache.geode.cache.query.CqException) CqService(org.apache.geode.cache.query.internal.cq.CqService) CqException(org.apache.geode.cache.query.CqException) IOException(java.io.IOException)

Example 34 with CqException

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);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheException(org.apache.geode.cache.CacheException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 35 with CqException

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());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) CqException(org.apache.geode.cache.query.CqException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

CqException (org.apache.geode.cache.query.CqException)46 CacheException (org.apache.geode.cache.CacheException)20 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)20 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)20 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 Test (org.junit.Test)16 CqExistsException (org.apache.geode.cache.query.CqExistsException)15 QueryService (org.apache.geode.cache.query.QueryService)14 CqClosedException (org.apache.geode.cache.query.CqClosedException)12 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)9 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)9 IOException (java.io.IOException)8 List (java.util.List)8 CqQuery (org.apache.geode.cache.query.CqQuery)8 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)8 CqService (org.apache.geode.cache.query.internal.cq.CqService)8 Set (java.util.Set)7 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)7 QueryException (org.apache.geode.cache.query.QueryException)7 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)7