Search in sources :

Example 11 with EntryEventImpl

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

the class ConcurrentSerialGatewaySenderEventProcessor method enqueueEvent.

public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue, int index) throws CacheException, IOException {
    // Get the appropriate gateway
    SerialGatewaySenderEventProcessor serialProcessor = this.processors.get(index);
    if (sender.getOrderPolicy() == OrderPolicy.KEY || sender.getOrderPolicy() == OrderPolicy.PARTITION) {
        // Create copy since the event id will be changed, otherwise the same
        // event will be changed for multiple gateways. Fix for bug 44471.
        @Released EntryEventImpl clonedEvent = new EntryEventImpl((EntryEventImpl) event);
        try {
            EventID originalEventId = clonedEvent.getEventId();
            if (logger.isDebugEnabled()) {
                logger.debug("The original EventId is {}", originalEventId);
            }
            // PARALLEL_THREAD_BUFFER * (index +1) + originalEventId.getThreadID();
            // generating threadId by the algorithm explained above used to clash with
            // fakeThreadId generated by putAll
            // below is new way to generate threadId so that it doesn't clash with
            // any.
            long newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGateway(index, originalEventId.getThreadID(), 0);
            EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID());
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Generated event id for event with key={}, index={}, original event id={}, threadId={}, new event id={}, newThreadId={}", this, event.getKey(), index, originalEventId, originalEventId.getThreadID(), newEventId, newThreadId);
            }
            clonedEvent.setEventId(newEventId);
            serialProcessor.enqueueEvent(operation, clonedEvent, substituteValue);
        } finally {
            clonedEvent.release();
        }
    } else {
        serialProcessor.enqueueEvent(operation, event, substituteValue);
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EventID(org.apache.geode.internal.cache.EventID)

Example 12 with EntryEventImpl

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

the class ParallelGatewaySenderEventProcessor method enqueueEvent.

@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue) throws IOException, CacheException {
    GatewaySenderEventImpl gatewayQueueEvent = null;
    Region region = event.getRegion();
    if (!(region instanceof DistributedRegion) && ((EntryEventImpl) event).getTailKey() == -1) {
        // Fix for #49081 and EntryDestroyedException in #49367.
        if (logger.isDebugEnabled()) {
            logger.debug("ParallelGatewaySenderEventProcessor not enqueing the following event since tailKey is not set. {}", event);
        }
        return;
    }
    // TODO: Looks like for PDX region bucket id is set to -1.
    boolean queuedEvent = false;
    try {
        EventID eventID = ((EntryEventImpl) event).getEventId();
        // while merging 42004, kept substituteValue as it is(it is barry's
        // change 42466). bucketID is merged with eventID.getBucketID
        gatewayQueueEvent = new GatewaySenderEventImpl(operation, event, substituteValue, true, eventID.getBucketID());
        if (getSender().beforeEnqueue(gatewayQueueEvent)) {
            long start = getSender().getStatistics().startTime();
            try {
                queuedEvent = this.queue.put(gatewayQueueEvent);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            getSender().getStatistics().endPut(start);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("The Event {} is filtered.", gatewayQueueEvent);
            }
            getSender().getStatistics().incEventsFiltered();
        }
    } finally {
        if (!queuedEvent) {
            // it was not queued for some reason
            gatewayQueueEvent.release();
        }
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EventID(org.apache.geode.internal.cache.EventID) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 13 with EntryEventImpl

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

the class AbstractGatewaySender method distribute.

public void distribute(EnumListenerEvent operation, EntryEventImpl event, List<Integer> allRemoteDSIds) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    // If this gateway is not running, return
    if (!isRunning()) {
        if (isDebugEnabled) {
            logger.debug("Returning back without putting into the gateway sender queue");
        }
        return;
    }
    final GatewaySenderStats stats = getStatistics();
    stats.incEventsReceived();
    if (!checkForDistribution(event, stats)) {
        stats.incEventsNotQueued();
        return;
    }
    // not considering this filter
    if (!this.filter.enqueueEvent(event)) {
        stats.incEventsFiltered();
        return;
    }
    // released by this method or transfers ownership to TmpQueueEvent
    @Released EntryEventImpl clonedEvent = new EntryEventImpl(event, false);
    boolean freeClonedEvent = true;
    try {
        Region region = event.getRegion();
        setModifiedEventId(clonedEvent);
        Object callbackArg = clonedEvent.getRawCallbackArgument();
        if (isDebugEnabled) {
            // We can't deserialize here for logging purposes so don't
            // call getNewValue.
            // event.getNewValue(); // to deserialize the value if necessary
            logger.debug("{} : About to notify {} to perform operation {} for {} callback arg {}", this.isPrimary(), getId(), operation, clonedEvent, callbackArg);
        }
        if (callbackArg instanceof GatewaySenderEventCallbackArgument) {
            GatewaySenderEventCallbackArgument seca = (GatewaySenderEventCallbackArgument) callbackArg;
            if (isDebugEnabled) {
                logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
            }
            if (seca.getOriginatingDSId() == DEFAULT_DISTRIBUTED_SYSTEM_ID) {
                if (isDebugEnabled) {
                    logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                }
                seca.setOriginatingDSId(this.getMyDSId());
                seca.initializeReceipientDSIds(allRemoteDSIds);
            } else {
                // if the dispatcher is GatewaySenderEventCallbackDispatcher (which is the case of WBCL),
                // skip the below check of remoteDSId.
                // Fix for #46517
                AbstractGatewaySenderEventProcessor ep = getEventProcessor();
                if (ep != null && !(ep.getDispatcher() instanceof GatewaySenderEventCallbackDispatcher)) {
                    if (seca.getOriginatingDSId() == this.getRemoteDSId()) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. It is being dropped as remote is originator.", this, seca.getOriginatingDSId(), getMyDSId());
                        }
                        return;
                    } else if (seca.getRecipientDSIds().contains(this.getRemoteDSId())) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}.. It is being dropped as remote ds is already a recipient. Recipients are: {}", this, seca.getOriginatingDSId(), getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                        }
                        return;
                    }
                }
                seca.getRecipientDSIds().addAll(allRemoteDSIds);
            }
        } else {
            GatewaySenderEventCallbackArgument geCallbackArg = new GatewaySenderEventCallbackArgument(callbackArg, this.getMyDSId(), allRemoteDSIds);
            clonedEvent.setCallbackArgument(geCallbackArg);
        }
        if (!this.getLifeCycleLock().readLock().tryLock()) {
            synchronized (this.queuedEventsSync) {
                if (!this.enqueuedAllTempQueueEvents) {
                    if (!this.getLifeCycleLock().readLock().tryLock()) {
                        Object substituteValue = getSubstituteValue(clonedEvent, operation);
                        this.tmpQueuedEvents.add(new TmpQueueEvent(operation, clonedEvent, substituteValue));
                        freeClonedEvent = false;
                        stats.incTempQueueSize();
                        if (isDebugEnabled) {
                            logger.debug("Event : {} is added to TempQueue", clonedEvent);
                        }
                        return;
                    }
                }
            }
            if (this.enqueuedAllTempQueueEvents) {
                this.getLifeCycleLock().readLock().lock();
            }
        }
        try {
            // The sender may have stopped, after we have checked the status in the beginning.
            if (!isRunning()) {
                if (isDebugEnabled) {
                    logger.debug("Returning back without putting into the gateway sender queue");
                }
                return;
            }
            try {
                AbstractGatewaySenderEventProcessor ev = this.eventProcessor;
                if (ev == null) {
                    getStopper().checkCancelInProgress(null);
                    this.getCache().getDistributedSystem().getCancelCriterion().checkCancelInProgress(null);
                    // connecting to the other site (bug #40681)
                    if (ev == null) {
                        throw new GatewayCancelledException("Event processor thread is gone");
                    }
                }
                // Get substitution value to enqueue if necessary
                Object substituteValue = getSubstituteValue(clonedEvent, operation);
                ev.enqueueEvent(operation, clonedEvent, substituteValue);
            } catch (CancelException e) {
                logger.debug("caught cancel exception", e);
                throw e;
            } catch (RegionDestroyedException e) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            } catch (Exception e) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            }
        } finally {
            this.getLifeCycleLock().readLock().unlock();
        }
    } finally {
        if (freeClonedEvent) {
            // fix for bug 48035
            clonedEvent.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException)

Example 14 with EntryEventImpl

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

the class AbstractGatewaySenderEventProcessor method addPDXEvent.

private List<GatewaySenderEventImpl> addPDXEvent() throws IOException {
    List<GatewaySenderEventImpl> pdxEventsToBeDispatched = new ArrayList<GatewaySenderEventImpl>();
    // getPDXRegion
    InternalCache cache = this.sender.getCache();
    Region<Object, Object> pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
    if (rebuildPdxList) {
        pdxEventsMap.clear();
        pdxSenderEventsList.clear();
        rebuildPdxList = false;
    }
    // PDX region
    if (pdxRegion != null && pdxRegion.size() != pdxEventsMap.size()) {
        for (Map.Entry<Object, Object> typeEntry : pdxRegion.entrySet()) {
            if (!pdxEventsMap.containsKey(typeEntry.getKey())) {
                // event should never be off-heap so it does not need to be released
                EntryEventImpl event = EntryEventImpl.create((LocalRegion) pdxRegion, Operation.UPDATE, typeEntry.getKey(), typeEntry.getValue(), null, false, cache.getMyId());
                event.disallowOffHeapValues();
                event.setEventId(new EventID(cache.getInternalDistributedSystem()));
                List<Integer> allRemoteDSIds = new ArrayList<Integer>();
                for (GatewaySender sender : cache.getGatewaySenders()) {
                    allRemoteDSIds.add(sender.getRemoteDSId());
                }
                GatewaySenderEventCallbackArgument geCallbackArg = new GatewaySenderEventCallbackArgument(event.getRawCallbackArgument(), this.sender.getMyDSId(), allRemoteDSIds);
                event.setCallbackArgument(geCallbackArg);
                GatewaySenderEventImpl pdxSenderEvent = // OFFHEAP:
                new GatewaySenderEventImpl(EnumListenerEvent.AFTER_UPDATE, event, null);
                // event for
                // pdx type
                // meta data
                // so it
                // should
                // never be
                // off-heap
                pdxEventsMap.put(typeEntry.getKey(), pdxSenderEvent);
                pdxSenderEventsList.add(pdxSenderEvent);
            }
        }
    }
    Iterator<GatewaySenderEventImpl> iterator = pdxSenderEventsList.iterator();
    while (iterator.hasNext()) {
        GatewaySenderEventImpl pdxEvent = iterator.next();
        if (pdxEvent.isAcked) {
            // Since this is acked, it means it has reached to remote site.Dont add
            // to pdxEventsToBeDispatched
            iterator.remove();
            continue;
        }
        if (pdxEvent.isDispatched) {
            // containing this event.Dont add to pdxEventsToBeDispatched
            continue;
        }
        pdxEventsToBeDispatched.add(pdxEvent);
    }
    if (!pdxEventsToBeDispatched.isEmpty() && logger.isDebugEnabled()) {
        logger.debug("List of PDX Event to be dispatched : {}", pdxEventsToBeDispatched);
    }
    // add all these pdx events before filtered events
    return pdxEventsToBeDispatched;
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) EventID(org.apache.geode.internal.cache.EventID) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 15 with EntryEventImpl

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

the class CacheClientUpdater method handleUpdate.

/**
   * Create or update an entry
   * 
   * @param clientMessage message containing the data
   */
private void handleUpdate(Message clientMessage) {
    String regionName = null;
    Object key = null;
    Part valuePart = null;
    final boolean isDebugEnabled = logger.isDebugEnabled();
    try {
        this.isOpCompleted = false;
        // Retrieve the data from the put message parts
        if (isDebugEnabled) {
            logger.debug("Received put message of length ({} bytes)", clientMessage.getPayloadLength());
        }
        int partCnt = 0;
        Part regionNamePart = clientMessage.getPart(partCnt++);
        Part keyPart = clientMessage.getPart(partCnt++);
        boolean isDeltaSent = (Boolean) clientMessage.getPart(partCnt++).getObject();
        valuePart = clientMessage.getPart(partCnt++);
        Part callbackArgumentPart = clientMessage.getPart(partCnt++);
        VersionTag versionTag = (VersionTag) clientMessage.getPart(partCnt++).getObject();
        if (versionTag != null) {
            versionTag.replaceNullIDs((InternalDistributedMember) this.endpoint.getMemberId());
        }
        Part isInterestListPassedPart = clientMessage.getPart(partCnt++);
        Part hasCqsPart = clientMessage.getPart(partCnt++);
        EventID eventId = (EventID) clientMessage.getPart(clientMessage.getNumberOfParts() - 1).getObject();
        boolean withInterest = (Boolean) isInterestListPassedPart.getObject();
        boolean withCQs = (Boolean) hasCqsPart.getObject();
        regionName = regionNamePart.getString();
        key = keyPart.getStringOrObject();
        Object callbackArgument = callbackArgumentPart.getObject();
        // Don't automatically deserialize the value.
        // Pass it onto the region as a byte[]. If it is a serialized
        // object, it will be stored as a CachedDeserializable and
        // deserialized only when requested.
        boolean isCreate = clientMessage.getMessageType() == MessageType.LOCAL_CREATE;
        if (isDebugEnabled) {
            logger.debug("Putting entry for region: {} key: {} create: {}{} callbackArgument: {} withInterest={} withCQs={} eventID={} version={}", regionName, key, isCreate, valuePart.isObject() ? new StringBuilder(" value: ").append(deserialize(valuePart.getSerializedForm())) : "", callbackArgument, withInterest, withCQs, eventId, versionTag);
        }
        LocalRegion region = (LocalRegion) this.cacheHelper.getRegion(regionName);
        Object newValue = null;
        byte[] deltaBytes = null;
        Object fullValue = null;
        boolean isValueObject;
        if (!isDeltaSent) {
            // bug #42162 - must check for a serialized null here
            byte[] serializedForm = valuePart.getSerializedForm();
            if (isCreate && InternalDataSerializer.isSerializedNull(serializedForm)) {
            // newValue = null; newValue is already null
            } else {
                newValue = valuePart.getSerializedForm();
            }
            if (withCQs) {
                fullValue = valuePart.getObject();
            }
            isValueObject = valuePart.isObject();
        } else {
            deltaBytes = valuePart.getSerializedForm();
            isValueObject = true;
        }
        if (region == null) {
            if (isDebugEnabled && !quitting()) {
                logger.debug("{}: Region named {} does not exist", this, regionName);
            }
        } else if (region.hasServerProxy() && ServerResponseMatrix.checkForValidStateAfterNotification(region, key, clientMessage.getMessageType()) && (withInterest || !withCQs)) {
            @Released EntryEventImpl newEvent = null;
            try {
                // Create an event and put the entry
                newEvent = EntryEventImpl.create(region, clientMessage.getMessageType() == MessageType.LOCAL_CREATE ? Operation.CREATE : Operation.UPDATE, key, null, /* newValue */
                callbackArgument, /* callbackArg */
                true, /* originRemote */
                eventId.getDistributedMember());
                newEvent.setVersionTag(versionTag);
                newEvent.setFromServer(true);
                region.basicBridgeClientUpdate(eventId.getDistributedMember(), key, newValue, deltaBytes, isValueObject, callbackArgument, clientMessage.getMessageType() == MessageType.LOCAL_CREATE, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, newEvent, eventId);
                this.isOpCompleted = true;
                // flag
                if (withCQs && isDeltaSent) {
                    fullValue = newEvent.getNewValue();
                }
            } catch (InvalidDeltaException ignore) {
                Part fullValuePart = requestFullValue(eventId, "Caught InvalidDeltaException.");
                region.getCachePerfStats().incDeltaFullValuesRequested();
                // TODO: fix this line
                fullValue = newValue = fullValuePart.getObject();
                isValueObject = fullValuePart.isObject();
                region.basicBridgeClientUpdate(eventId.getDistributedMember(), key, newValue, null, isValueObject, callbackArgument, clientMessage.getMessageType() == MessageType.LOCAL_CREATE, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, newEvent, eventId);
                this.isOpCompleted = true;
            } finally {
                if (newEvent != null)
                    newEvent.release();
            }
            if (isDebugEnabled) {
                logger.debug("Put entry for region: {} key: {} callbackArgument: {}", regionName, key, callbackArgument);
            }
        }
        // Update CQs. CQs can exist without client region.
        if (withCQs) {
            Part numCqsPart = clientMessage.getPart(partCnt++);
            if (isDebugEnabled) {
                logger.debug("Received message has CQ Event. Number of cqs interested in the event : {}", numCqsPart.getInt() / 2);
            }
            partCnt = processCqs(clientMessage, partCnt, numCqsPart.getInt(), clientMessage.getMessageType(), key, fullValue, deltaBytes, eventId);
            this.isOpCompleted = true;
        }
    } catch (Exception e) {
        String message = LocalizedStrings.CacheClientUpdater_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_ATTEMPTING_TO_PUT_ENTRY_REGION_0_KEY_1_VALUE_2.toLocalizedString(regionName, key, deserialize(valuePart.getSerializedForm()));
        handleException(message, e);
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Endpoint(org.apache.geode.cache.client.internal.Endpoint) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) SSLException(javax.net.ssl.SSLException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EventID(org.apache.geode.internal.cache.EventID) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)34 EventID (org.apache.geode.internal.cache.EventID)14 Released (org.apache.geode.internal.offheap.annotations.Released)8 HashMap (java.util.HashMap)7 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)7 Map (java.util.Map)6 CacheWriterException (org.apache.geode.cache.CacheWriterException)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)6 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)6 CancelException (org.apache.geode.CancelException)5 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 PutAllPartialResultException (org.apache.geode.internal.cache.PutAllPartialResultException)5 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)5 CacheException (org.apache.geode.cache.CacheException)4 ReplyException (org.apache.geode.distributed.internal.ReplyException)4 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)4