Search in sources :

Example 6 with FilterProfile

use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.

the class CacheClientNotifier method singletonNotifyClients.

private void singletonNotifyClients(InternalCacheEvent event, ClientUpdateMessage cmsg) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final boolean isTraceEnabled = logger.isTraceEnabled();
    FilterInfo filterInfo = event.getLocalFilterInfo();
    FilterProfile regionProfile = ((LocalRegion) event.getRegion()).getFilterProfile();
    if (filterInfo != null) {
        // if the routing was made using an old profile we need to recompute it
        if (isTraceEnabled) {
            logger.trace("Event isOriginRemote={}", event.isOriginRemote());
        }
    }
    if ((filterInfo == null || (filterInfo.getCQs() == null && filterInfo.getInterestedClients() == null && filterInfo.getInterestedClientsInv() == null))) {
        return;
    }
    long startTime = this.statistics.startTime();
    ClientUpdateMessageImpl clientMessage;
    if (cmsg == null) {
        clientMessage = constructClientMessage(event);
    } else {
        clientMessage = (ClientUpdateMessageImpl) cmsg;
    }
    if (clientMessage == null) {
        return;
    }
    // Holds the clientIds to which filter message needs to be sent.
    Set<ClientProxyMembershipID> filterClients = new HashSet();
    // Add CQ info.
    if (filterInfo.getCQs() != null) {
        for (Map.Entry<Long, Integer> e : filterInfo.getCQs().entrySet()) {
            Long cqID = e.getKey();
            String cqName = regionProfile.getRealCqID(cqID);
            if (cqName == null) {
                continue;
            }
            ServerCQ cq = regionProfile.getCq(cqName);
            if (cq != null) {
                ClientProxyMembershipID id = cq.getClientProxyId();
                filterClients.add(id);
                if (isDebugEnabled) {
                    logger.debug("Adding cq routing info to message for id: {} and cq: {}", id, cqName);
                }
                clientMessage.addClientCq(id, cq.getName(), e.getValue());
            }
        }
    }
    // Add interestList info.
    if (filterInfo.getInterestedClientsInv() != null) {
        Set<Object> rawIDs = regionProfile.getRealClientIDs(filterInfo.getInterestedClientsInv());
        Set<ClientProxyMembershipID> ids = getProxyIDs(rawIDs, true);
        if (ids.remove(event.getContext())) {
            // don't send to member of origin
            CacheClientProxy ccp = getClientProxy(event.getContext());
            if (ccp != null) {
                ccp.getStatistics().incMessagesNotQueuedOriginator();
            }
        }
        if (!ids.isEmpty()) {
            if (isTraceEnabled) {
                logger.trace("adding invalidation routing to message for {}", ids);
            }
            clientMessage.addClientInterestList(ids, false);
            filterClients.addAll(ids);
        }
    }
    if (filterInfo.getInterestedClients() != null) {
        Set<Object> rawIDs = regionProfile.getRealClientIDs(filterInfo.getInterestedClients());
        Set<ClientProxyMembershipID> ids = getProxyIDs(rawIDs, true);
        if (ids.remove(event.getContext())) {
            // don't send to member of origin
            CacheClientProxy ccp = getClientProxy(event.getContext());
            if (ccp != null) {
                ccp.getStatistics().incMessagesNotQueuedOriginator();
            }
        }
        if (!ids.isEmpty()) {
            if (isTraceEnabled) {
                logger.trace("adding routing to message for {}", ids);
            }
            clientMessage.addClientInterestList(ids, true);
            filterClients.addAll(ids);
        }
    }
    Conflatable conflatable = null;
    if (clientMessage instanceof ClientTombstoneMessage) {
        // bug #46832 - HAEventWrapper deserialization can't handle subclasses
        // of ClientUpdateMessageImpl, so don't wrap them
        conflatable = clientMessage;
        // Remove clients older than 70 from the filterClients if the message is
        // ClientTombstoneMessage. Fix for #46591.
        Object[] objects = filterClients.toArray();
        for (Object id : objects) {
            CacheClientProxy ccp = getClientProxy((ClientProxyMembershipID) id, true);
            if (ccp != null && ccp.getVersion().compareTo(Version.GFE_70) < 0) {
                filterClients.remove(id);
            }
        }
    } else {
        HAEventWrapper wrapper = new HAEventWrapper(clientMessage);
        // Set the putInProgress flag to true before starting the put on proxy's
        // HA queues. Nowhere else, this flag is being set to true.
        wrapper.setPutInProgress(true);
        conflatable = wrapper;
    }
    singletonRouteClientMessage(conflatable, filterClients);
    this.statistics.endEvent(startTime);
    // destroyed are removed after the event is placed in clients HAQueue.
    if (filterInfo.filterProcessedLocally) {
        removeDestroyTokensFromCqResultKeys(event, filterInfo);
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) FilterProfile(org.apache.geode.internal.cache.FilterProfile) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) Conflatable(org.apache.geode.internal.cache.Conflatable) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HAContainerMap(org.apache.geode.internal.cache.ha.HAContainerMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet)

Example 7 with FilterProfile

use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.

the class UnregisterInterestDUnitTest method checkKeyList.

public static void checkKeyList(Integer value, Integer valueInv) {
    FilterProfile fp = ((GemFireCacheImpl) cache).getFilterProfile(regionname);
    assertEquals(value.intValue(), fp.getKeysOfInterestSize());
    assertEquals(valueInv.intValue(), fp.getKeysOfInterestInvSize());
}
Also used : FilterProfile(org.apache.geode.internal.cache.FilterProfile) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl)

Example 8 with FilterProfile

use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.

the class UnregisterInterestDUnitTest method checkPatterns.

public static void checkPatterns(Integer value, Integer valueInv) {
    FilterProfile fp = ((GemFireCacheImpl) cache).getFilterProfile(regionname);
    assertEquals(value.intValue(), fp.getPatternsOfInterestSize());
    assertEquals(valueInv.intValue(), fp.getPatternsOfInterestInvSize());
}
Also used : FilterProfile(org.apache.geode.internal.cache.FilterProfile) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl)

Example 9 with FilterProfile

use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.

the class CqServiceVsdStats method numCqsOnRegion.

/**
   * This is a test method. It silently ignores exceptions and should not be used outside of unit
   * tests.
   * <p>
   * Returns the number of CQs (active + suspended) on the given region.
   */
public long numCqsOnRegion(final InternalCache cache, String regionName) {
    if (cache == null) {
        return 0;
    }
    DefaultQueryService queryService = (DefaultQueryService) cache.getQueryService();
    CqService cqService = null;
    try {
        cqService = queryService.getCqService();
    } catch (CqException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to get CqService {}", e.getLocalizedMessage());
        }
        e.printStackTrace();
        // We're confused
        return -1;
    }
    if (((CqServiceImpl) cqService).isServer()) {
        // If we are on the server, look at the number of CQs in the filter profile.
        try {
            FilterProfile fp = cache.getFilterProfile(regionName);
            if (fp == null) {
                return 0;
            }
            return fp.getCqCount();
        } catch (Exception ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to get serverside CQ count for region: {} {}", regionName, ex.getLocalizedMessage());
            }
        }
    } else {
        try {
            CqQuery[] cqs = queryService.getCqs(regionName);
            if (cqs != null) {
                return cqs.length;
            }
        } catch (Exception ex) {
        // Dont do anything.
        }
    }
    return 0;
}
Also used : FilterProfile(org.apache.geode.internal.cache.FilterProfile) CqException(org.apache.geode.cache.query.CqException) CqQuery(org.apache.geode.cache.query.CqQuery) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) CqException(org.apache.geode.cache.query.CqException)

Example 10 with FilterProfile

use of org.apache.geode.internal.cache.FilterProfile 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)

Aggregations

FilterProfile (org.apache.geode.internal.cache.FilterProfile)14 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CqException (org.apache.geode.cache.query.CqException)4 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)4 Set (java.util.Set)3 InvalidDeltaException (org.apache.geode.InvalidDeltaException)3 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)3 TimeoutException (org.apache.geode.cache.TimeoutException)3 CqClosedException (org.apache.geode.cache.query.CqClosedException)3 CqExistsException (org.apache.geode.cache.query.CqExistsException)3 QueryException (org.apache.geode.cache.query.QueryException)3 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)3 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)3 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2