Search in sources :

Example 16 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)

Example 17 with EntryEventImpl

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

the class CacheClientNotifier method removeDestroyTokensFromCqResultKeys.

private void removeDestroyTokensFromCqResultKeys(InternalCacheEvent event, FilterInfo filterInfo) {
    FilterProfile regionProfile = ((LocalRegion) event.getRegion()).getFilterProfile();
    if (event.getOperation().isEntry() && filterInfo.getCQs() != null) {
        EntryEventImpl entryEvent = (EntryEventImpl) event;
        for (Map.Entry<Long, Integer> e : filterInfo.getCQs().entrySet()) {
            Long cqID = e.getKey();
            String cqName = regionProfile.getRealCqID(cqID);
            if (cqName != null) {
                ServerCQ cq = regionProfile.getCq(cqName);
                if (cq != null && e.getValue().equals(Integer.valueOf(MessageType.LOCAL_DESTROY))) {
                    cq.removeFromCqResultKeys(entryEvent.getKey(), true);
                }
            }
        }
    }
}
Also used : FilterProfile(org.apache.geode.internal.cache.FilterProfile) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) 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)

Example 18 with EntryEventImpl

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

the class BatchDestroyOperation method initMessage.

@Override
protected void initMessage(CacheOperationMessage msg, DirectReplyProcessor processor) {
    super.initMessage(msg, processor);
    DestroyMessage m = (DestroyMessage) msg;
    EntryEventImpl event = getEvent();
    m.key = event.getKey();
    m.eventId = event.getEventId();
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl)

Example 19 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 20 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)

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