Search in sources :

Example 1 with CacheProfile

use of org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile in project geode by apache.

the class DistributedCacheOperation method removeDestroyTokensFromCqResultKeys.

/**
   * Cleanup destroyed events in CQ result cache for remote CQs. While maintaining the CQ results
   * key caching. the destroy event keys are marked as destroyed instead of removing them, this is
   * to take care, arrival of duplicate events. The key marked as destroyed are removed after the
   * event is placed in clients HAQueue or distributed to the peers.
   *
   * This is similar to CacheClientNotifier.removeDestroyTokensFromCqResultKeys() where the
   * destroyed events for local CQs are handled.
   */
private void removeDestroyTokensFromCqResultKeys(FilterRoutingInfo filterRouting) {
    for (InternalDistributedMember m : filterRouting.getMembers()) {
        FilterInfo filterInfo = filterRouting.getFilterInfo(m);
        if (filterInfo.getCQs() == null) {
            continue;
        }
        CacheProfile cf = (CacheProfile) ((Bucket) getRegion()).getPartitionedRegion().getCacheDistributionAdvisor().getProfile(m);
        if (cf == null || cf.filterProfile == null || cf.filterProfile.isLocalProfile() || cf.filterProfile.getCqMap().isEmpty()) {
            continue;
        }
        for (Object value : cf.filterProfile.getCqMap().values()) {
            ServerCQ cq = (ServerCQ) value;
            for (Map.Entry<Long, Integer> e : filterInfo.getCQs().entrySet()) {
                Long cqID = e.getKey();
                // the entry form CQ cache.
                if (cq.getFilterID() == cqID && (e.getValue().equals(MessageType.LOCAL_DESTROY))) {
                    cq.removeFromCqResultKeys(((EntryOperation) event).getKey(), true);
                }
            }
        }
    }
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) StoredObject(org.apache.geode.internal.offheap.StoredObject) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo) Map(java.util.Map)

Example 2 with CacheProfile

use of org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile in project geode by apache.

the class DistributedRegion method fillInProfile.

@Override
public void fillInProfile(Profile profile) {
    assert profile instanceof CacheProfile;
    CacheProfile cacheProfile = (CacheProfile) profile;
    cacheProfile.dataPolicy = getDataPolicy();
    cacheProfile.hasCacheLoader = basicGetLoader() != null;
    cacheProfile.hasCacheWriter = basicGetWriter() != null;
    cacheProfile.hasCacheListener = hasListener();
    Assert.assertTrue(this.scope.isDistributed());
    cacheProfile.scope = this.scope;
    cacheProfile.inRecovery = getImageState().getInRecovery();
    cacheProfile.isPersistent = getDataPolicy().withPersistence();
    cacheProfile.setSubscriptionAttributes(getSubscriptionAttributes());
    // Below PDX check is added for rolling upgrade support. We are
    // removing Old wan in this checkin. PDX region are always gatewayEnabled
    // irrespective whether gatewayHub is configured or not.
    // Old version Pdx region always has this attribute true so to avoid region
    // attribute comparison across member we are setting it to true.
    cacheProfile.isGatewayEnabled = isPdxTypesRegion();
    cacheProfile.serialNumber = getSerialNumber();
    cacheProfile.regionInitialized = isInitialized();
    cacheProfile.persistentID = getPersistentID();
    if (getPersistenceAdvisor() != null) {
        cacheProfile.persistenceInitialized = getPersistenceAdvisor().isOnline();
    }
    cacheProfile.hasCacheServer = this.cache.getCacheServers().size() > 0 ? true : false;
    cacheProfile.requiresOldValueInEvents = this.dataPolicy.withReplication() && this.filterProfile != null && this.filterProfile.hasCQs();
    cacheProfile.gatewaySenderIds = getGatewaySenderIds();
    cacheProfile.asyncEventQueueIds = getVisibleAsyncEventQueueIds();
    cacheProfile.isOffHeap = getOffHeap();
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile)

Example 3 with CacheProfile

use of org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile in project geode by apache.

the class CqServiceImpl method processRegionEvent.

private void processRegionEvent(CacheEvent event, Profile localProfile, Profile[] profiles, FilterRoutingInfo frInfo) throws CqException {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("CQ service processing region event {}", event);
    }
    Integer cqRegionEvent = generateCqRegionEvent(event);
    for (int i = -1; i < profiles.length; i++) {
        CacheProfile cf;
        if (i < 0) {
            cf = (CacheProfile) localProfile;
            if (cf == null)
                continue;
        } else {
            cf = (CacheProfile) profiles[i];
        }
        FilterProfile pf = cf.filterProfile;
        if (pf == null || pf.getCqMap().isEmpty()) {
            continue;
        }
        Map cqs = pf.getCqMap();
        HashMap<Long, Integer> cqInfo = new HashMap<>();
        Iterator cqIter = cqs.entrySet().iterator();
        while (cqIter.hasNext()) {
            Map.Entry cqEntry = (Map.Entry) cqIter.next();
            ServerCQImpl cQuery = (ServerCQImpl) cqEntry.getValue();
            if (!event.isOriginRemote() && event.getOperation().isRegionDestroy() && !((LocalRegion) event.getRegion()).isUsedForPartitionedRegionBucket()) {
                try {
                    if (isDebugEnabled) {
                        logger.debug("Closing CQ on region destroy event. CqName : {}", cQuery.getName());
                    }
                    cQuery.close(false);
                } catch (Exception ex) {
                    if (isDebugEnabled) {
                        logger.debug("Failed to Close CQ on region destroy. CqName : {}", cQuery.getName(), ex);
                    }
                }
            }
            cqInfo.put(cQuery.getFilterID(), cqRegionEvent);
            cQuery.getVsdStats().updateStats(cqRegionEvent);
        }
        if (pf.isLocalProfile()) {
            frInfo.setLocalCqInfo(cqInfo);
        } else {
            frInfo.setCqRoutingInfo(cf.getDistributedMember(), cqInfo);
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) 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) CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) FilterProfile(org.apache.geode.internal.cache.FilterProfile) Iterator(java.util.Iterator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 4 with CacheProfile

use of org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile in project geode by apache.

the class FilterProfile method fillInInterestRoutingInfo.

/**
   * Fills in the routing information for clients that have registered interest in the given event.
   * The routing information is stored in the given FilterRoutingInfo object for use in message
   * delivery.
   * 
   * @param event the event being applied to the cache
   * @param profiles the profiles of members having the affected region
   * @param filterRoutingInfo the routing object that is modified by this method (may be null)
   * @param cacheOpRecipients members that will receive a CacheDistributionMessage for the event
   * @return the resulting FilterRoutingInfo
   */
public FilterRoutingInfo fillInInterestRoutingInfo(CacheEvent event, Profile[] profiles, FilterRoutingInfo filterRoutingInfo, Set cacheOpRecipients) {
    Set clientsInv = Collections.emptySet();
    Set clients = Collections.emptySet();
    if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
        logger.trace(LogMarker.BRIDGE_SERVER, "finding interested clients for {}", event);
    }
    FilterRoutingInfo frInfo = filterRoutingInfo;
    for (int i = 0; i < profiles.length; i++) {
        CacheProfile cf = (CacheProfile) profiles[i];
        if (!cf.hasCacheServer) {
            continue;
        }
        FilterProfile pf = cf.filterProfile;
        if (pf == null) {
            continue;
        }
        if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
            logger.trace(LogMarker.BRIDGE_SERVER, "Processing {}", pf);
        }
        if (!pf.hasInterest()) {
            // the routing.
            if (!pf.isLocalProfile() && cacheOpRecipients.contains(cf.getDistributedMember())) {
                if (frInfo == null)
                    frInfo = new FilterRoutingInfo();
                frInfo.addInterestedClients(cf.getDistributedMember(), Collections.emptySet(), Collections.emptySet(), false);
            }
            continue;
        }
        if (event.getOperation().isEntry()) {
            EntryEvent entryEvent = (EntryEvent) event;
            if (pf.allKeyClientsInv != null || pf.keysOfInterestInv != null || pf.patternsOfInterestInv != null || pf.filtersOfInterestInv != null) {
                clientsInv = pf.getInterestedClients(entryEvent, pf.allKeyClientsInv, pf.keysOfInterestInv, pf.patternsOfInterestInv, pf.filtersOfInterestInv);
            }
            if (pf.allKeyClients != null || pf.keysOfInterest != null || pf.patternsOfInterest != null || pf.filtersOfInterest != null) {
                clients = pf.getInterestedClients(entryEvent, pf.allKeyClients, pf.keysOfInterest, pf.patternsOfInterest, pf.filtersOfInterest);
            }
        } else {
            if (event.getOperation().isRegionDestroy() || event.getOperation().isClear()) {
                clientsInv = pf.getAllClientsWithInterestInv();
                clients = pf.getAllClientsWithInterest();
            } else {
                return frInfo;
            }
        }
        if (pf.isLocalProfile) {
            if (logger.isDebugEnabled()) {
                logger.debug("Setting local interested clients={} and clientsInv={}", clients, clientsInv);
            }
            if (frInfo == null)
                frInfo = new FilterRoutingInfo();
            frInfo.setLocalInterestedClients(clients, clientsInv);
        } else {
            if (// always send a routing with
            cacheOpRecipients.contains(cf.getDistributedMember()) || // CacheOperationMessages
            (clients != null && !clients.isEmpty()) || (clientsInv != null && !clientsInv.isEmpty())) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Adding interested clients={} and clientsIn={} to {}", clients, clientsInv, filterRoutingInfo);
                }
                if (frInfo == null)
                    frInfo = new FilterRoutingInfo();
                frInfo.addInterestedClients(cf.getDistributedMember(), clients, clientsInv, this.clientMap.hasLongID);
            }
        }
    }
    return frInfo;
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) EntryEvent(org.apache.geode.cache.EntryEvent)

Example 5 with CacheProfile

use of org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile in project geode by apache.

the class FilterProfile method getFilterRoutingInfoPart1.

/**
   * Compute the full routing information for the given set of peers. This will not include local
   * routing information from interest processing. That is done by getFilterRoutingInfoPart2
   */
public FilterRoutingInfo getFilterRoutingInfoPart1(CacheEvent event, Profile[] peerProfiles, Set cacheOpRecipients) {
    // early out if there are no cache servers in the system
    boolean anyServers = false;
    for (int i = 0; i < peerProfiles.length; i++) {
        if (((CacheProfile) peerProfiles[i]).hasCacheServer) {
            anyServers = true;
            break;
        }
    }
    if (!anyServers && !this.localProfile.hasCacheServer) {
        return null;
    }
    FilterRoutingInfo frInfo = null;
    CqService cqService = getCqService(event.getRegion());
    if (cqService.isRunning()) {
        frInfo = new FilterRoutingInfo();
        // bug #50809 - local routing for transactional ops must be done here
        // because the event isn't available later and we lose the old value for the entry
        final boolean processLocalProfile = event.getOperation().isEntry() && ((EntryEvent) event).getTransactionId() != null;
        fillInCQRoutingInfo(event, processLocalProfile, peerProfiles, frInfo);
    }
    // Process InterestList.
    // return fillInInterestRoutingInfo(event, peerProfiles, frInfo, cacheOpRecipients);
    frInfo = fillInInterestRoutingInfo(event, peerProfiles, frInfo, cacheOpRecipients);
    if (frInfo == null || !frInfo.hasMemberWithFilterInfo()) {
        return null;
    } else {
        return frInfo;
    }
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) EntryEvent(org.apache.geode.cache.EntryEvent) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Aggregations

CacheProfile (org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile)8 Map (java.util.Map)3 EntryEvent (org.apache.geode.cache.EntryEvent)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 InvalidDeltaException (org.apache.geode.InvalidDeltaException)2 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)2 TimeoutException (org.apache.geode.cache.TimeoutException)2 CqClosedException (org.apache.geode.cache.query.CqClosedException)2 CqException (org.apache.geode.cache.query.CqException)2 CqExistsException (org.apache.geode.cache.query.CqExistsException)2 QueryException (org.apache.geode.cache.query.QueryException)2 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)2 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)2 FilterProfile (org.apache.geode.internal.cache.FilterProfile)2 TreeSet (java.util.TreeSet)1 CqQueryVsdStats (org.apache.geode.cache.query.internal.CqQueryVsdStats)1