Search in sources :

Example 11 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ServerCQImpl method registerCq.

@Override
public void registerCq(ClientProxyMembershipID p_clientProxyId, CacheClientNotifier p_ccn, int p_cqState) throws CqException, RegionNotFoundException {
    CacheClientProxy clientProxy = null;
    this.clientProxyId = p_clientProxyId;
    if (p_ccn != null) {
        this.ccn = p_ccn;
        clientProxy = p_ccn.getClientProxy(p_clientProxyId, true);
    }
    validateCq();
    final boolean isDebugEnabled = logger.isDebugEnabled();
    StringId msg = LocalizedStrings.ONE_ARG;
    Throwable t = null;
    try {
        this.query = constructServerSideQuery();
        if (isDebugEnabled) {
            logger.debug("Server side query for the cq: {} is: {}", cqName, this.query.getQueryString());
        }
    } catch (Exception ex) {
        t = ex;
        if (ex instanceof ClassNotFoundException) {
            msg = LocalizedStrings.CqQueryImpl_CLASS_NOT_FOUND_EXCEPTION_THE_ANTLRJAR_OR_THE_SPCIFIED_CLASS_MAY_BE_MISSING_FROM_SERVER_SIDE_CLASSPATH_ERROR_0;
        } else {
            msg = LocalizedStrings.CqQueryImpl_ERROR_WHILE_PARSING_THE_QUERY_ERROR_0;
        }
    } finally {
        if (t != null) {
            String s = msg.toLocalizedString(t);
            if (isDebugEnabled) {
                logger.debug(s, t);
            }
            throw new CqException(s);
        }
    }
    // Update Regions Book keeping.
    // TODO replace getRegion() with getRegionByPathForProcessing() so this doesn't block
    // if the region is still being initialized
    this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
    if (this.cqBaseRegion == null) {
        throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION__0_SPECIFIED_WITH_CQ_NOT_FOUND_CQNAME_1.toLocalizedString(new Object[] { regionName, this.cqName }));
    }
    // Make sure that the region is partitioned or
    // replicated with distributed ack or global.
    DataPolicy dp = this.cqBaseRegion.getDataPolicy();
    this.isPR = dp.withPartitioning();
    if (!(this.isPR || dp.withReplication())) {
        String errMsg = null;
        // replicated regions with eviction set to local destroy get turned into preloaded
        if (dp.withPreloaded() && cqBaseRegion.getAttributes().getEvictionAttributes() != null && cqBaseRegion.getAttributes().getEvictionAttributes().getAction().equals(EvictionAction.LOCAL_DESTROY)) {
            errMsg = LocalizedStrings.CqQueryImpl_CQ_NOT_SUPPORTED_FOR_REPLICATE_WITH_LOCAL_DESTROY.toString(this.regionName, cqBaseRegion.getAttributes().getEvictionAttributes().getAction());
        } else {
            errMsg = "The region " + this.regionName + "  specified in CQ creation is neither replicated nor partitioned; " + "only replicated or partitioned regions are allowed in CQ creation.";
        }
        if (isDebugEnabled) {
            logger.debug(errMsg);
        }
        throw new CqException(errMsg);
    }
    if ((dp.withReplication() && (!(cqBaseRegion.getAttributes().getScope().isDistributedAck() || cqBaseRegion.getAttributes().getScope().isGlobal())))) {
        String errMsg = "The replicated region " + this.regionName + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
        if (isDebugEnabled) {
            logger.debug(errMsg);
        }
        throw new CqException(errMsg);
    }
    // Can be null by the time we are here
    if (clientProxy != null) {
        clientProxy.incCqCount();
        if (clientProxy.hasOneCq()) {
            cqService.stats().incClientsWithCqs();
        }
        if (isDebugEnabled) {
            logger.debug("Added CQ to the base region: {} With key as: {}", cqBaseRegion.getFullPath(), serverCqName);
        }
    }
    this.updateCqCreateStats();
    // Initialize the state of CQ.
    if (this.cqState.getState() != p_cqState) {
        setCqState(p_cqState);
    }
    // it to other matching cqs for performance reasons
    if (p_cqState == CqStateImpl.RUNNING) {
        // Add to the matchedCqMap.
        cqService.addToMatchingCqMap(this);
    }
    // Initialize CQ results (key) cache.
    if (CqServiceProvider.MAINTAIN_KEYS) {
        this.cqResultKeys = new HashMap<Object, Object>();
        // added to the results cache (not from the CQ Results).
        if (this.isPR) {
            this.setCqResultsCacheInitialized();
        } else {
            this.destroysWhileCqResultsInProgress = new HashSet<Object>();
        }
    }
    if (p_ccn != null) {
        try {
            cqService.addToCqMap(this);
        } catch (CqExistsException cqe) {
            // Should not happen.
            throw new CqException(LocalizedStrings.CqQueryImpl_UNABLE_TO_CREATE_CQ_0_ERROR__1.toLocalizedString(new Object[] { cqName, cqe.getMessage() }));
        }
        this.cqBaseRegion.getFilterProfile().registerCq(this);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CqException(org.apache.geode.cache.query.CqException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) 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) StringId(org.apache.geode.i18n.StringId) CqExistsException(org.apache.geode.cache.query.CqExistsException) DataPolicy(org.apache.geode.cache.DataPolicy)

Example 12 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class CqDataUsingPoolDUnitTest method testGetDurableCqsFromServerCycleClientsAndMoreCqs.

@Test
public void testGetDurableCqsFromServerCycleClientsAndMoreCqs() {
    final String regionName = "testGetAllDurableCqsFromServerCycleClients";
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client1 = host.getVM(1);
    VM client2 = host.getVM(2);
    int timeout = 60000;
    // Start server 1
    final int server1Port = ((Integer) server.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
    // Start client 1
    client1.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client1.getHost()), server1Port), regionName, getDurableClientProperties("client1_dc", timeout)));
    // Start client 2
    client2.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client2.getHost()), server1Port), regionName, getDurableClientProperties("client2_dc", timeout)));
    // create the test cqs
    createClient1CqsAndDurableCqs(client1, regionName);
    createClient2CqsAndDurableCqs(client2, regionName);
    cycleDurableClient(client1, "client1_dc", server1Port, regionName, timeout);
    cycleDurableClient(client2, "client2_dc", server1Port, regionName, timeout);
    client1.invoke(new CacheSerializableRunnable("Register more cq for client 1") {

        @Override
        public void run2() throws CacheException {
            // register the cq's
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            CqAttributesFactory cqAf = new CqAttributesFactory();
            CqAttributes attributes = cqAf.create();
            try {
                queryService.newCq("client1MoreDCQ1", "Select * From /" + regionName + " where id = 1", attributes, true).execute();
                queryService.newCq("client1MoreDCQ2", "Select * From /" + regionName + " where id = 10", attributes, true).execute();
                queryService.newCq("client1MoreNoDC1", "Select * From /" + regionName, attributes, false).execute();
                queryService.newCq("client1MoreNoDC2", "Select * From /" + regionName + " where id = 3", attributes, false).execute();
            } catch (RegionNotFoundException e) {
                fail("failed", e);
            } catch (CqException e) {
                fail("failed", e);
            } catch (CqExistsException e) {
                fail("failed", e);
            }
        }
    });
    client2.invoke(new CacheSerializableRunnable("Register more cq for client 2") {

        @Override
        public void run2() throws CacheException {
            // register the cq's
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            CqAttributesFactory cqAf = new CqAttributesFactory();
            CqAttributes attributes = cqAf.create();
            try {
                queryService.newCq("client2MoreDCQ1", "Select * From /" + regionName + " where id = 1", attributes, true).execute();
                queryService.newCq("client2MoreDCQ2", "Select * From /" + regionName + " where id = 10", attributes, true).execute();
                queryService.newCq("client2MoreDCQ3", "Select * From /" + regionName, attributes, true).execute();
                queryService.newCq("client2MoreDCQ4", "Select * From /" + regionName + " where id = 3", attributes, true).execute();
            } catch (RegionNotFoundException e) {
                fail("failed", e);
            } catch (CqException e) {
                fail("failed", e);
            } catch (CqExistsException e) {
                fail("failed", e);
            }
        }
    });
    // Cycle clients a second time
    cycleDurableClient(client1, "client1_dc", server1Port, regionName, timeout);
    cycleDurableClient(client2, "client2_dc", server1Port, regionName, timeout);
    client2.invoke(new CacheSerializableRunnable("check durable cqs for client 2") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(8, list.size());
            assertTrue(list.contains("client2DCQ1"));
            assertTrue(list.contains("client2DCQ2"));
            assertTrue(list.contains("client2DCQ3"));
            assertTrue(list.contains("client2DCQ4"));
            assertTrue(list.contains("client2MoreDCQ1"));
            assertTrue(list.contains("client2MoreDCQ2"));
            assertTrue(list.contains("client2MoreDCQ3"));
            assertTrue(list.contains("client2MoreDCQ4"));
        }
    });
    client1.invoke(new CacheSerializableRunnable("check durable cqs for client 1") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(4, list.size());
            assertTrue(list.contains("client1DCQ1"));
            assertTrue(list.contains("client1DCQ2"));
            assertTrue(list.contains("client1MoreDCQ1"));
            assertTrue(list.contains("client1MoreDCQ2"));
        }
    });
    client1.invoke(() -> CacheServerTestUtil.closeCache());
    client2.invoke(() -> CacheServerTestUtil.closeCache());
    server.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqException(org.apache.geode.cache.query.CqException) Host(org.apache.geode.test.dunit.Host) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) VM(org.apache.geode.test.dunit.VM) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) List(java.util.List) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 13 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ClientCQImpl method initConnectionProxy.

/**
   * Initializes the connection using the pool from the client region. Also sets the cqBaseRegion
   * value of this CQ.
   */
private void initConnectionProxy() throws CqException, RegionNotFoundException {
    cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
    // is obtained by the Bridge Client/writer/loader on the local region.
    if (cqBaseRegion == null) {
        throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION_ON_WHICH_QUERY_IS_SPECIFIED_NOT_FOUND_LOCALLY_REGIONNAME_0.toLocalizedString(regionName));
    }
    ServerRegionProxy srp = cqBaseRegion.getServerProxy();
    if (srp != null) {
        if (logger.isTraceEnabled()) {
            logger.trace("Found server region proxy on region. RegionName: {}", regionName);
        }
        this.cqProxy = new ServerCQProxyImpl(srp);
        if (!srp.getPool().getSubscriptionEnabled()) {
            throw new CqException("The 'queueEnabled' flag on Pool installed on Region " + regionName + " is set to false.");
        }
    } else {
        throw new CqException("Unable to get the connection pool. The Region does not have a pool configured.");
    }
}
Also used : RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) CqException(org.apache.geode.cache.query.CqException) ServerCQProxyImpl(org.apache.geode.cache.client.internal.ServerCQProxyImpl)

Example 14 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ClientCQImpl method executeCqOnRedundantsAndPrimary.

/**
   * This executes the CQ first on the redundant server and then on the primary server. This is
   * required to keep the redundancy behavior in accordance with the HAQueue expectation (wherein
   * the events are delivered only from the primary).
   * 
   * @param executeWithInitialResults boolean
   * @return Object SelectResults in case of executeWithInitialResults
   */
private Object executeCqOnRedundantsAndPrimary(boolean executeWithInitialResults) throws CqClosedException, RegionNotFoundException, CqException {
    Object initialResults = null;
    synchronized (this.cqState) {
        if (this.isClosed()) {
            throw new CqClosedException(LocalizedStrings.CqQueryImpl_CQ_IS_CLOSED_CQNAME_0.toLocalizedString(this.cqName));
        }
        if (this.isRunning()) {
            throw new IllegalStateException(LocalizedStrings.CqQueryImpl_CQ_IS_IN_RUNNING_STATE_CQNAME_0.toLocalizedString(this.cqName));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Performing Execute {} request for CQ. CqName: {}", ((executeWithInitialResults) ? "WithInitialResult" : ""), this.cqName);
        }
        this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(this.regionName);
        // If not server send the request to server.
        if (!cqService.isServer()) {
            // pool that initializes the CQ. Else its set using the Region proxy.
            if (this.cqProxy == null) {
                initConnectionProxy();
            }
            boolean success = false;
            try {
                if (this.proxyCache != null) {
                    if (this.proxyCache.isClosed()) {
                        throw new CacheClosedException("Cache is closed for this user.");
                    }
                    UserAttributes.userAttributes.set(this.proxyCache.getUserAttributes());
                }
                if (executeWithInitialResults) {
                    initialResults = cqProxy.createWithIR(this);
                    if (initialResults == null) {
                        String errMsg = "Failed to execute the CQ.  CqName: " + this.cqName + ", Query String is: " + this.queryString;
                        throw new CqException(errMsg);
                    }
                } else {
                    cqProxy.create(this);
                }
                success = true;
            } catch (Exception ex) {
                // Check for system shutdown.
                if (this.shutdownInProgress()) {
                    throw new CqException("System shutdown in progress.");
                }
                if (ex.getCause() instanceof GemFireSecurityException) {
                    if (securityLogWriter.warningEnabled()) {
                        securityLogWriter.warning(LocalizedStrings.CqQueryImpl_EXCEPTION_WHILE_EXECUTING_CQ_EXCEPTION_0, ex, null);
                    }
                    throw new CqException(ex.getCause().getMessage(), ex.getCause());
                } else if (ex instanceof CqException) {
                    throw (CqException) ex;
                } else {
                    String errMsg = LocalizedStrings.CqQueryImpl_FAILED_TO_EXECUTE_THE_CQ_CQNAME_0_QUERY_STRING_IS_1_ERROR_FROM_LAST_SERVER_2.toLocalizedString(this.cqName, this.queryString, ex.getLocalizedMessage());
                    if (logger.isDebugEnabled()) {
                        logger.debug(errMsg, ex);
                    }
                    throw new CqException(errMsg, ex);
                }
            } finally {
                if (!success && !this.shutdownInProgress()) {
                    try {
                        cqProxy.close(this);
                    } catch (Exception e) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Exception cleaning up failed cq", e);
                        }
                        UserAttributes.userAttributes.set(null);
                    }
                }
                UserAttributes.userAttributes.set(null);
            }
        }
        this.cqState.setState(CqStateImpl.RUNNING);
    }
    // If client side, alert listeners that a cqs have been connected
    if (!cqService.isServer()) {
        connected = true;
        CqListener[] cqListeners = getCqAttributes().getCqListeners();
        for (int lCnt = 0; lCnt < cqListeners.length; lCnt++) {
            if (cqListeners[lCnt] != null) {
                if (cqListeners[lCnt] instanceof CqStatusListener) {
                    CqStatusListener listener = (CqStatusListener) cqListeners[lCnt];
                    listener.onCqConnected();
                }
            }
        }
    }
    // Update CQ-base region for book keeping.
    this.cqService.stats().incCqsActive();
    this.cqService.stats().decCqsStopped();
    return initialResults;
}
Also used : CqException(org.apache.geode.cache.query.CqException) CqListener(org.apache.geode.cache.query.CqListener) CqClosedException(org.apache.geode.cache.query.CqClosedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqException(org.apache.geode.cache.query.CqException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CqClosedException(org.apache.geode.cache.query.CqClosedException) CqStatusListener(org.apache.geode.cache.query.CqStatusListener) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 15 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ClientCQImpl method executeWithInitialResults.

/**
   * Start or resume executing the query. Gets or updates the CQ results and returns them.
   */
@Override
public <E> CqResults<E> executeWithInitialResults() throws CqClosedException, RegionNotFoundException, CqException {
    synchronized (queuedEventsSynchObject) {
        // until first call is completed.
        while (queuedEvents != null) {
            try {
                queuedEventsSynchObject.wait();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        // At this point we know queuedEvents is null and no one is adding to queuedEvents yet.
        this.queuedEvents = new ConcurrentLinkedQueue<CqEventImpl>();
    }
    if (CqQueryImpl.testHook != null) {
        testHook.pauseUntilReady();
    }
    // Send CQ request to servers.
    // If an exception is thrown, we need to clean up the queuedEvents
    // or else client will hang on next executeWithInitialResults
    CqResults initialResults;
    try {
        initialResults = (CqResults) executeCqOnRedundantsAndPrimary(true);
    } catch (RegionNotFoundException | CqException | RuntimeException e) {
        queuedEvents = null;
        throw e;
    }
    // initial results can be added to the queue.
    synchronized (queuedEventsSynchObject) {
        // Invoke the CQ Listeners with the received CQ Events.
        try {
            if (!this.queuedEvents.isEmpty()) {
                try {
                    Runnable r = new Runnable() {

                        @Override
                        public void run() {
                            Object[] eventArray = null;
                            if (CqQueryImpl.testHook != null) {
                                testHook.setEventCount(queuedEvents.size());
                            }
                            // Synchronization for the executer thread.
                            synchronized (queuedEventsSynchObject) {
                                try {
                                    eventArray = queuedEvents.toArray();
                                    // Process through the events
                                    for (Object cqEvent : eventArray) {
                                        cqService.invokeListeners(cqName, ClientCQImpl.this, (CqEventImpl) cqEvent);
                                        stats.decQueuedCqListenerEvents();
                                    }
                                } finally {
                                    // Make sure that we notify waiting threads or else possible dead lock
                                    queuedEvents.clear();
                                    queuedEvents = null;
                                    queuedEventsSynchObject.notify();
                                }
                            }
                        }
                    };
                    final LoggingThreadGroup group = LoggingThreadGroup.createThreadGroup("CQEventHandler", logger);
                    Thread thread = new Thread(group, r, "CQEventHandler For " + cqName);
                    thread.setDaemon(true);
                    thread.start();
                } catch (Exception ex) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Exception while invoking the CQ Listener with queued events.", ex);
                    }
                }
            } else {
                queuedEvents = null;
            }
        } finally {
            queuedEventsSynchObject.notify();
        }
        return initialResults;
    }
}
Also used : RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqException(org.apache.geode.cache.query.CqException) LoggingThreadGroup(org.apache.geode.internal.logging.LoggingThreadGroup) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqException(org.apache.geode.cache.query.CqException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CqClosedException(org.apache.geode.cache.query.CqClosedException) CqResults(org.apache.geode.cache.query.CqResults)

Aggregations

RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)26 Test (org.junit.Test)11 Region (org.apache.geode.cache.Region)9 CqException (org.apache.geode.cache.query.CqException)9 QueryService (org.apache.geode.cache.query.QueryService)9 CqExistsException (org.apache.geode.cache.query.CqExistsException)7 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)7 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)7 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)7 Cache (org.apache.geode.cache.Cache)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 CacheException (org.apache.geode.cache.CacheException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 CancelException (org.apache.geode.CancelException)5 CqAttributes (org.apache.geode.cache.query.CqAttributes)5 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)5 CqClosedException (org.apache.geode.cache.query.CqClosedException)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 Host (org.apache.geode.test.dunit.Host)5