Search in sources :

Example 6 with FilterInfo

use of org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo in project geode by apache.

the class LocalRegion method notifyClientsOfTombstoneGC.

/**
   * pass tombstone garbage-collection info to clients
   * 
   * @param eventID the ID of the event (see bug #50683)
   * @param routing routing info (routing is computed if this is null)
   */
protected void notifyClientsOfTombstoneGC(Map<VersionSource, Long> regionGCVersions, Set<Object> keysRemoved, EventID eventID, FilterInfo routing) {
    if (CacheClientNotifier.getInstance() != null) {
        // Only route the event to clients interested in the partitioned region.
        // We do this by constructing a region-level event and then use it to
        // have the filter profile ferret out all of the clients that have interest
        // in this region
        FilterProfile fp = getFilterProfile();
        if (fp != null || routing != null) {
            // null check - fix for bug #45614
            RegionEventImpl regionEvent = new RegionEventImpl(this, Operation.REGION_DESTROY, null, true, getMyId());
            regionEvent.setEventID(eventID);
            FilterInfo clientRouting = routing;
            if (clientRouting == null) {
                clientRouting = fp.getLocalFilterRouting(regionEvent);
            }
            regionEvent.setLocalFilterInfo(clientRouting);
            ClientUpdateMessage clientMessage = ClientTombstoneMessage.gc(this, regionGCVersions, eventID);
            CacheClientNotifier.notifyClients(regionEvent, clientMessage);
        }
    }
}
Also used : ClientUpdateMessage(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Example 7 with FilterInfo

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

Example 8 with FilterInfo

use of org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo in project geode by apache.

the class HAGIIDUnitTest method tombstonegc.

/** queue a tombstone GC message for the client. See bug #46832 */
public static void tombstonegc() throws Exception {
    LocalRegion r = (LocalRegion) cache.getRegion("/" + REGION_NAME);
    assertNotNull(r);
    DistributedMember id = r.getCache().getDistributedSystem().getDistributedMember();
    RegionEventImpl regionEvent = new RegionEventImpl(r, Operation.REGION_DESTROY, null, true, id);
    FilterInfo clientRouting = r.getFilterProfile().getLocalFilterRouting(regionEvent);
    assertTrue(clientRouting.getInterestedClients().size() > 0);
    regionEvent.setLocalFilterInfo(clientRouting);
    Map<VersionSource, Long> map = Collections.emptyMap();
    ClientTombstoneMessage message = ClientTombstoneMessage.gc(r, map, new EventID(r.getCache().getDistributedSystem()));
    CacheClientNotifier.notifyClients(regionEvent, message);
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) ClientTombstoneMessage(org.apache.geode.internal.cache.tier.sockets.ClientTombstoneMessage) RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) LocalRegion(org.apache.geode.internal.cache.LocalRegion) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Example 9 with FilterInfo

use of org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo in project geode by apache.

the class FilterProfile method getLocalFilterRoutingForPutAllOp.

/**
   * computes FilterRoutingInfo objects for each of the given events
   */
public void getLocalFilterRoutingForPutAllOp(DistributedPutAllOperation dpao, DistributedPutAllOperation.PutAllEntryData[] putAllData) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (this.region != null && this.localProfile.hasCacheServer) {
        Set clientsInv = null;
        Set clients = null;
        int size = putAllData.length;
        CqService cqService = getCqService(dpao.getRegion());
        boolean doCQs = cqService.isRunning() && this.region != null;
        for (int idx = 0; idx < size; idx++) {
            PutAllEntryData pEntry = putAllData[idx];
            if (pEntry != null) {
                @Unretained final EntryEventImpl ev = dpao.getEventForPosition(idx);
                FilterRoutingInfo fri = pEntry.filterRouting;
                FilterInfo fi = null;
                if (fri != null) {
                    fi = fri.getLocalFilterInfo();
                }
                if (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);
                }
                ev.setLocalFilterInfo(fi);
            }
        }
    }
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CqService(org.apache.geode.cache.query.internal.cq.CqService) PutAllEntryData(org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData) Unretained(org.apache.geode.internal.offheap.annotations.Unretained) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Example 10 with FilterInfo

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

Aggregations

FilterInfo (org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)10 HashSet (java.util.HashSet)4 Set (java.util.Set)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 CopyOnWriteHashSet (org.apache.geode.internal.CopyOnWriteHashSet)3 StoredObject (org.apache.geode.internal.offheap.StoredObject)3 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 CqService (org.apache.geode.cache.query.internal.cq.CqService)2 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 ClientUpdateMessage (org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage)2 Unretained (org.apache.geode.internal.offheap.annotations.Unretained)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1 Vector (java.util.Vector)1