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);
}
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations