Search in sources :

Example 11 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class DurableClientTestCase method flushEntries.

/*
   * Due to the way removal from ha region queue is implemented a dummy cq or interest needs to be
   * created and a dummy value used so that none of the actual cqs will be triggered and yet an
   * event will flush the queue
   */
protected void flushEntries(VM server, VM client, final String regionName) {
    // ack counts
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    registerInterest(client, regionName, false);
    server.invoke(new CacheSerializableRunnable("flush entries") {

        public void run2() throws CacheException {
            CqService service = ((InternalCache) CacheServerTestUtil.getCache()).getCqService();
            // Get the region
            Region region = CacheServerTestUtil.getCache().getRegion(regionName);
            assertNotNull(region);
            region.put("LAST", "ENTRY");
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Region(org.apache.geode.cache.Region) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 12 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class FilterProfile method fillInCQRoutingInfo.

/**
   * get continuous query routing information
   * 
   * @param event the event to process
   * @param peerProfiles the profiles getting this event
   * @param frInfo the routing table to update
   */
private void fillInCQRoutingInfo(CacheEvent event, boolean processLocalProfile, Profile[] peerProfiles, FilterRoutingInfo frInfo) {
    CqService cqService = getCqService(event.getRegion());
    if (cqService != null) {
        try {
            Profile local = processLocalProfile ? this.localProfile : null;
            cqService.processEvents(event, local, peerProfiles, frInfo);
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            SystemFailure.checkFailure();
            logger.error(LocalizedMessage.create(LocalizedStrings.CacheClientNotifier_EXCEPTION_OCCURRED_WHILE_PROCESSING_CQS), t);
        }
    }
}
Also used : CqService(org.apache.geode.cache.query.internal.cq.CqService) CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) Profile(org.apache.geode.distributed.internal.DistributionAdvisor.Profile)

Example 13 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class FilterProfile method processRegisterCq.

/**
   * adds a new CQ to this profile during a delta operation or deserialization
   * 
   * @param serverCqName the query objects' name
   * @param ServerCQ the new query object
   * @param addToCqMap whether to add the query to this.cqs
   */
void processRegisterCq(String serverCqName, ServerCQ ServerCQ, boolean addToCqMap) {
    ServerCQ cq = (ServerCQ) ServerCQ;
    try {
        CqService cqService = GemFireCacheImpl.getInstance().getCqService();
        cqService.start();
        cq.setCqService(cqService);
        CqStateImpl cqState = (CqStateImpl) cq.getState();
        cq.setName(generateCqName(serverCqName));
        cq.registerCq(null, null, cqState.getState());
    } catch (Exception ex) {
        // Change it to Info level.
        if (logger.isDebugEnabled()) {
            logger.debug("Error while initializing the CQs with FilterProfile for CQ {}, Error : {}", serverCqName, ex.getMessage(), ex);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Adding CQ to remote members FilterProfile using name: {}", serverCqName);
    }
    if (addToCqMap) {
        this.cqs.put(serverCqName, cq);
    }
    // region is not set on the FilterProfile created for the peer nodes.
    if (cq.getCqBaseRegion() != null) {
        FilterProfile pf = cq.getCqBaseRegion().getFilterProfile();
        if (pf != null) {
            pf.incCqCount();
        }
    }
}
Also used : ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CqService(org.apache.geode.cache.query.internal.cq.CqService) CqStateImpl(org.apache.geode.cache.query.internal.CqStateImpl) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException)

Example 14 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class FilterProfile method getFilterRoutingInfoPart2.

/**
   * get local routing information
   * 
   * @param part1Info routing information for peers, if any
   * @param event the event to process
   * @return routing information for clients connected to this server
   */
public FilterRoutingInfo getFilterRoutingInfoPart2(FilterRoutingInfo part1Info, CacheEvent event) {
    FilterRoutingInfo result = part1Info;
    if (localProfile.hasCacheServer) {
        // bug #45520 - CQ events arriving out of order causes result set
        // inconsistency, so don't compute routings for events in conflict
        boolean isInConflict = event.getOperation().isEntry() && ((EntryEventImpl) event).isConcurrencyConflict();
        CqService cqService = getCqService(event.getRegion());
        if (!isInConflict && cqService.isRunning() && this.region != null) /*
                                  * && !( this.region.isUsedForPartitionedRegionBucket() || //
                                  * partitioned region CQ this.region instanceof PartitionedRegion)
                                  */
        {
            // processing is done in part 1
            if (result == null) {
                result = new FilterRoutingInfo();
            }
            if (logger.isDebugEnabled()) {
                logger.debug("getting local cq matches for {}", event);
            }
            fillInCQRoutingInfo(event, true, NO_PROFILES, result);
        }
        result = fillInInterestRoutingInfo(event, localProfileArray, result, Collections.emptySet());
    }
    return result;
}
Also used : CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 15 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class FilterProfile method getLocalFilterRoutingForRemoveAllOp.

/**
   * computes FilterRoutingInfo objects for each of the given events
   */
public void getLocalFilterRoutingForRemoveAllOp(DistributedRemoveAllOperation op, RemoveAllEntryData[] removeAllData) {
    if (this.region != null && this.localProfile.hasCacheServer) {
        Set clientsInv = null;
        Set clients = null;
        int size = removeAllData.length;
        CqService cqService = getCqService(op.getRegion());
        boolean doCQs = cqService.isRunning() && this.region != null;
        for (int idx = 0; idx < size; idx++) {
            RemoveAllEntryData pEntry = removeAllData[idx];
            if (pEntry != null) {
                @Unretained final EntryEventImpl ev = op.getEventForPosition(idx);
                FilterRoutingInfo fri = pEntry.filterRouting;
                FilterInfo fi = null;
                if (fri != null) {
                    fi = fri.getLocalFilterInfo();
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Finding locally interested clients for {}", ev);
                }
                if (doCQs) {
                    if (fri == null) {
                        fri = new FilterRoutingInfo();
                    }
                    fillInCQRoutingInfo(ev, true, NO_PROFILES, fri);
                    fi = fri.getLocalFilterInfo();
                }
                if (this.allKeyClientsInv != null || this.keysOfInterestInv != null || this.patternsOfInterestInv != null || this.filtersOfInterestInv != null) {
                    clientsInv = this.getInterestedClients(ev, this.allKeyClientsInv, this.keysOfInterestInv, this.patternsOfInterestInv, this.filtersOfInterestInv);
                }
                if (this.allKeyClients != null || this.keysOfInterest != null || this.patternsOfInterest != null || this.filtersOfInterest != null) {
                    clients = this.getInterestedClients(ev, this.allKeyClients, this.keysOfInterest, this.patternsOfInterest, this.filtersOfInterest);
                }
                if (clients != null || clientsInv != null) {
                    if (fi == null) {
                        fi = new FilterInfo();
                    // no need to create or update a FilterRoutingInfo at this time
                    }
                    fi.setInterestedClients(clients);
                    fi.setInterestedClientsInv(clientsInv);
                }
                // if (this.logger.fineEnabled()) {
                // this.region.getLogWriterI18n().fine("setting event routing to " + fi);
                // }
                ev.setLocalFilterInfo(fi);
            }
        }
    }
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) RemoveAllEntryData(org.apache.geode.internal.cache.DistributedRemoveAllOperation.RemoveAllEntryData) CqService(org.apache.geode.cache.query.internal.cq.CqService) Unretained(org.apache.geode.internal.offheap.annotations.Unretained) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Aggregations

CqService (org.apache.geode.cache.query.internal.cq.CqService)36 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)15 CacheException (org.apache.geode.cache.CacheException)11 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 IOException (java.io.IOException)9 Collection (java.util.Collection)9 Set (java.util.Set)8 CqException (org.apache.geode.cache.query.CqException)8 HashSet (java.util.HashSet)7 Region (org.apache.geode.cache.Region)7 ServerCQImpl (org.apache.geode.cache.query.internal.cq.ServerCQImpl)7 Host (org.apache.geode.test.dunit.Host)7 VM (org.apache.geode.test.dunit.VM)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Portfolio (org.apache.geode.cache.query.data.Portfolio)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5