Search in sources :

Example 6 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class EntryEventImpl method processDeltaBytes.

private void processDeltaBytes(Object oldValueInVM) {
    if (!this.region.hasSeenEvent(this)) {
        if (oldValueInVM == null || Token.isInvalidOrRemoved(oldValueInVM)) {
            this.region.getCachePerfStats().incDeltaFailedUpdates();
            throw new InvalidDeltaException("Old value not found for key " + this.keyInfo.getKey());
        }
        FilterProfile fp = this.region.getFilterProfile();
        // If compression is enabled then we've already gotten a new copy due to the
        // serializaion and deserialization that occurs.
        boolean copy = this.region.getCompressor() == null && (this.region.isCopyOnRead() || this.region.getCloningEnabled() || (fp != null && fp.getCqCount() > 0));
        Object value = oldValueInVM;
        boolean wasCD = false;
        if (value instanceof CachedDeserializable) {
            wasCD = true;
            if (copy) {
                value = ((CachedDeserializable) value).getDeserializedWritableCopy(this.region, re);
            } else {
                value = ((CachedDeserializable) value).getDeserializedValue(this.region, re);
            }
        } else {
            if (copy) {
                value = CopyHelper.copy(value);
            }
        }
        boolean deltaBytesApplied = false;
        try {
            long start = CachePerfStats.getStatTime();
            ((org.apache.geode.Delta) value).fromDelta(new DataInputStream(new ByteArrayInputStream(getDeltaBytes())));
            this.region.getCachePerfStats().endDeltaUpdate(start);
            deltaBytesApplied = true;
        } catch (RuntimeException rte) {
            throw rte;
        } catch (VirtualMachineError e) {
            SystemFailure.initiateFailure(e);
            throw e;
        } catch (Throwable t) {
            SystemFailure.checkFailure();
            throw new DeltaSerializationException("Exception while deserializing delta bytes.", t);
        } finally {
            if (!deltaBytesApplied) {
                this.region.getCachePerfStats().incDeltaFailedUpdates();
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Delta has been applied for key {}", getKey());
        }
        // assert event.getNewValue() == null;
        if (wasCD) {
            CachedDeserializable old = (CachedDeserializable) oldValueInVM;
            int valueSize;
            if (GemFireCacheImpl.DELTAS_RECALCULATE_SIZE) {
                valueSize = CachedDeserializableFactory.calcMemSize(value, region.getObjectSizer(), false);
            } else {
                valueSize = old.getValueSizeInBytes();
            }
            value = CachedDeserializableFactory.create(value, valueSize);
        }
        setNewValue(value);
        if (this.causedByMessage != null && this.causedByMessage instanceof PutMessage) {
            ((PutMessage) this.causedByMessage).setDeltaValObj(value);
        }
    } else {
        this.region.getCachePerfStats().incDeltaFailedUpdates();
        throw new InvalidDeltaException("Cache encountered replay of event containing delta bytes for key " + this.keyInfo.getKey());
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DeltaSerializationException(org.apache.geode.DeltaSerializationException) StoredObject(org.apache.geode.internal.offheap.StoredObject) PutMessage(org.apache.geode.internal.cache.partitioned.PutMessage)

Example 7 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class PutMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException, IOException {
    // set the internal DS. Required to
    this.setInternalDs(r.getSystem());
    // checked DS level delta-enabled property
    // while sending delta
    PartitionedRegionDataStore ds = r.getDataStore();
    boolean sendReply = true;
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released final EntryEventImpl ev = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
    getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            ev.setVersionTag(this.versionTag);
        }
        if (this.bridgeContext != null) {
            ev.setContext(this.bridgeContext);
        }
        Assert.assertTrue(eventId != null);
        ev.setEventId(eventId);
        ev.setCausedByMessage(this);
        ev.setInvokePRCallbacks(!notificationOnly);
        ev.setPossibleDuplicate(this.posDup);
        /*
       * if (this.hasOldValue) { if (this.oldValueIsSerialized) {
       * ev.setSerializedOldValue(getOldValueBytes()); } else { ev.setOldValue(getOldValueBytes());
       * } }
       */
        ev.setDeltaBytes(this.deltaBytes);
        if (this.hasDelta) {
            this.valObj = null;
            // New value will be set once it is generated with fromDelta() inside
            // EntryEventImpl.processDeltaBytes()
            ev.setNewValue(this.valObj);
        } else {
            switch(this.deserializationPolicy) {
                case DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY:
                    ev.setSerializedNewValue(getValBytes());
                    break;
                case DistributedCacheOperation.DESERIALIZATION_POLICY_NONE:
                    ev.setNewValue(getValBytes());
                    break;
                default:
                    throw new AssertionError("unknown deserialization policy: " + deserializationPolicy);
            }
        }
        if (!notificationOnly) {
            if (ds == null) {
                throw new AssertionError("This process should have storage" + " for this operation: " + this.toString());
            }
            try {
                // the event must show it's true origin for cachewriter invocation
                // event.setOriginRemote(true);
                // this.op = r.doCacheWriteBeforePut(event, ifNew); // TODO fix this for bug 37072
                ev.setOriginRemote(false);
                result = r.getDataView().putEntryOnRemote(ev, this.ifNew, this.ifOld, this.expectedOldValue, this.requireOldValue, this.lastModified, true);
                if (!this.result) {
                    // make sure the region hasn't gone away
                    r.checkReadiness();
                // sbawaska: I cannot see how ifOld and ifNew can both be false, hence removing
                // if (!this.ifNew && !this.ifOld) {
                // // no reason to be throwing an exception, so let's retry
                // ForceReattemptException fre = new ForceReattemptException(
                // LocalizedStrings.PutMessage_UNABLE_TO_PERFORM_PUT_BUT_OPERATION_SHOULD_NOT_FAIL_0.toLocalizedString());
                // fre.setHash(key.hashCode());
                // sendReply(getSender(), getProcessorId(), dm,
                // new ReplyException(fre), r, startTime);
                // sendReply = false;
                // }
                }
            } catch (CacheWriterException cwe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(cwe), r, startTime);
                return false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            } catch (InvalidDeltaException ide) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(ide), r, startTime);
                r.getCachePerfStats().incDeltaFullValuesRequested();
                return false;
            }
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "PutMessage {} with key: {} val: {}", (result ? "updated bucket" : "did not update bucket"), getKey(), (getValBytes() == null ? "null" : "(" + getValBytes().length + " bytes)"));
            }
        } else {
            // notificationOnly
            @Released EntryEventImpl e2 = createListenerEvent(ev, r, dm.getDistributionManagerId());
            final EnumListenerEvent le;
            try {
                if (e2.getOperation().isCreate()) {
                    le = EnumListenerEvent.AFTER_CREATE;
                } else {
                    le = EnumListenerEvent.AFTER_UPDATE;
                }
                r.invokePutCallbacks(le, e2, r.isInitialized(), true);
            } finally {
                // if e2 == ev then no need to free it here. The outer finally block will get it.
                if (e2 != ev) {
                    e2.release();
                }
            }
            result = true;
        }
        // set operation for reply message
        setOperation(ev.getOperation());
        if (sendReply) {
            sendReply(getSender(), getProcessorId(), dm, null, r, startTime, ev);
        }
        return false;
    } finally {
        ev.release();
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) EnumListenerEvent(org.apache.geode.internal.cache.EnumListenerEvent) Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 8 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class Put61 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long p_start) throws IOException, InterruptedException {
    long start = p_start;
    Part regionNamePart = null, keyPart = null, valuePart = null, callbackArgPart = null;
    String regionName = null;
    Object callbackArg = null, key = null;
    Part eventPart = null;
    StringBuffer errMessage = new StringBuffer();
    boolean isDelta = false;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    // requiresResponse = true;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incReadPutRequestTime(start - oldStart);
    }
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    keyPart = clientMessage.getPart(1);
    try {
        isDelta = (Boolean) clientMessage.getPart(2).getObject();
    } catch (Exception e) {
        writeException(clientMessage, MessageType.PUT_DELTA_ERROR, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        // CachePerfStats not available here.
        return;
    }
    valuePart = clientMessage.getPart(3);
    eventPart = clientMessage.getPart(4);
    if (clientMessage.getNumberOfParts() > 5) {
        callbackArgPart = clientMessage.getPart(5);
        try {
            callbackArg = callbackArgPart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("{}: Received 6.1{}put request ({} bytes) from {} for region {} key {}", serverConnection.getName(), (isDelta ? " delta " : " "), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
    }
    // Process the put request
    if (key == null || regionName == null) {
        if (key == null) {
            String putMsg = " The input key for the 6.1 put request is null";
            if (isDebugEnabled) {
                logger.debug("{}:{}", serverConnection.getName(), putMsg);
            }
            errMessage.append(putMsg);
        }
        if (regionName == null) {
            String putMsg = " The input region name for the 6.1 put request is null";
            if (isDebugEnabled) {
                logger.debug("{}:{}", serverConnection.getName(), putMsg);
            }
            errMessage.append(putMsg);
        }
        writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        String reason = " was not found during 6.1 put request";
        writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (valuePart.isNull() && region.containsKey(key)) {
        // Invalid to 'put' a null value in an existing key
        String putMsg = " Attempted to 6.1 put a null value for existing key " + key;
        if (isDebugEnabled) {
            logger.debug("{}:{}", serverConnection.getName(), putMsg);
        }
        errMessage.append(putMsg);
        writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // try {
    // this.eventId = (EventID)eventPart.getObject();
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(eventPart.getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
    try {
        Object value = null;
        if (!isDelta) {
            value = valuePart.getSerializedForm();
        }
        boolean isObject = valuePart.isObject();
        boolean isMetaRegion = region.isUsedForMetaRegion();
        clientMessage.setMetaRegion(isMetaRegion);
        this.securityService.authorizeRegionWrite(regionName, key.toString());
        AuthorizeRequest authzRequest = null;
        if (!isMetaRegion) {
            authzRequest = serverConnection.getAuthzRequest();
        }
        if (authzRequest != null) {
            if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                authzRequest.createRegionAuthorize((String) key);
            } else // Allow PUT operations on meta regions (bug #38961)
            {
                PutOperationContext putContext = authzRequest.putAuthorize(regionName, key, value, isObject, callbackArg);
                value = putContext.getValue();
                isObject = putContext.isObject();
                callbackArg = putContext.getCallbackArg();
            }
        }
        // If the value is 1 byte and the byte represents null,
        // attempt to create the entry. This test needs to be
        // moved to DataSerializer or DataSerializer.NULL needs
        // to be publicly accessible.
        boolean result = false;
        if (value == null && !isDelta) {
            // Create the null entry. Since the value is null, the value of the
            // isObject
            // the true after null doesn't matter and is not used.
            result = region.basicBridgeCreate(key, null, true, callbackArg, serverConnection.getProxyID(), true, new EventIDHolder(eventId), false);
        } else {
            // Put the entry
            byte[] delta = null;
            if (isDelta) {
                delta = valuePart.getSerializedForm();
            }
            result = region.basicBridgePut(key, value, delta, isObject, callbackArg, serverConnection.getProxyID(), true, new EventIDHolder(eventId));
        }
        if (result) {
            serverConnection.setModificationInfo(true, regionName, key);
        } else {
            String message = serverConnection.getName() + ": Failed to 6.1 put entry for region " + regionName + " key " + key + " value " + valuePart;
            if (isDebugEnabled) {
                logger.debug(message);
            }
            throw new Exception(message);
        }
    } catch (RegionDestroyedException rde) {
        writeException(clientMessage, rde, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (ResourceException re) {
        writeException(clientMessage, re, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (InvalidDeltaException ide) {
        logger.info(LocalizedMessage.create(LocalizedStrings.UpdateOperation_ERROR_APPLYING_DELTA_FOR_KEY_0_OF_REGION_1, new Object[] { key, regionName }));
        writeException(clientMessage, MessageType.PUT_DELTA_ERROR, ide, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        region.getCachePerfStats().incDeltaFullValuesRequested();
        return;
    } catch (Exception ce) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ce);
        // If an exception occurs during the put, preserve the connection
        writeException(clientMessage, ce, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        if (ce instanceof GemFireSecurityException) {
            // logged by the security logger
            if (isDebugEnabled) {
                logger.debug("{}: Unexpected Security exception", serverConnection.getName(), ce);
            }
        } else if (isDebugEnabled) {
            logger.debug("{}: Unexpected Exception", serverConnection.getName(), ce);
        }
        return;
    } finally {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessPutTime(start - oldStart);
    }
    // Increment statistics and write the reply
    if (region instanceof PartitionedRegion) {
        PartitionedRegion pr = (PartitionedRegion) region;
        if (pr.getNetworkHopType() != PartitionedRegion.NETWORK_HOP_NONE) {
            writeReplyWithRefreshMetadata(clientMessage, serverConnection, pr, pr.getNetworkHopType());
            pr.clearNetworkHopData();
        } else {
            writeReply(clientMessage, serverConnection);
        }
    } else {
        writeReply(clientMessage, serverConnection);
    }
    serverConnection.setAsTrue(RESPONDED);
    if (isDebugEnabled) {
        logger.debug("{}: Sent 6.1 put response back to {} for region {} key {} value {}", serverConnection.getName(), serverConnection.getSocketString(), regionName, key, valuePart);
    }
    stats.incWritePutResponseTime(DistributionStats.getStatTime() - start);
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ByteBuffer(java.nio.ByteBuffer) InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException) ResourceException(org.apache.geode.cache.ResourceException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Part(org.apache.geode.internal.cache.tier.sockets.Part) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EventID(org.apache.geode.internal.cache.EventID) ResourceException(org.apache.geode.cache.ResourceException) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext)

Example 9 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException 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 10 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class CqServiceImpl method invokeListeners.

private void invokeListeners(String cqName, ClientCQImpl cQuery, CqEventImpl cqEvent, Object[] fullValue) {
    if (!cQuery.isRunning() || cQuery.getCqAttributes() == null) {
        return;
    }
    // invoke CQ Listeners.
    CqListener[] cqListeners = cQuery.getCqAttributes().getCqListeners();
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("Invoking CQ listeners for {}, number of listeners : {} cqEvent : {}", cqName, cqListeners.length, cqEvent);
    }
    for (int lCnt = 0; lCnt < cqListeners.length; lCnt++) {
        try {
            // by the CqAttributeMutator.
            if (cqListeners[lCnt] != null) {
                cQuery.getVsdStats().incNumCqListenerInvocations();
                try {
                    if (cqEvent.getThrowable() != null) {
                        cqListeners[lCnt].onError(cqEvent);
                    } else {
                        cqListeners[lCnt].onEvent(cqEvent);
                    }
                } catch (InvalidDeltaException ide) {
                    if (isDebugEnabled) {
                        logger.debug("CqService.dispatchCqListeners(): Requesting full value...");
                    }
                    Part result = (Part) GetEventValueOp.executeOnPrimary(cqEvent.getQueueManager().getPool(), cqEvent.getEventID(), null);
                    Object newVal = result.getObject();
                    if (result == null || newVal == null) {
                        if (!cache.getCancelCriterion().isCancelInProgress()) {
                            Exception ex = new Exception("Failed to retrieve full value from server for eventID " + cqEvent.getEventID());
                            logger.warn(LocalizedMessage.create(LocalizedStrings.CqService_EXCEPTION_IN_THE_CQLISTENER_OF_THE_CQ_CQNAME_0_ERROR__1, new Object[] { cqName, ex.getMessage() }));
                            if (isDebugEnabled) {
                                logger.debug(ex.getMessage(), ex);
                            }
                        }
                    } else {
                        this.cache.getCachePerfStats().incDeltaFullValuesRequested();
                        cqEvent = new CqEventImpl(cQuery, cqEvent.getBaseOperation(), cqEvent.getQueryOperation(), cqEvent.getKey(), newVal, cqEvent.getDeltaValue(), cqEvent.getQueueManager(), cqEvent.getEventID());
                        if (cqEvent.getThrowable() != null) {
                            cqListeners[lCnt].onError(cqEvent);
                        } else {
                            cqListeners[lCnt].onEvent(cqEvent);
                        }
                        if (fullValue != null) {
                            fullValue[0] = newVal;
                        }
                    }
                }
            }
        // Handle client side exceptions.
        } catch (Exception ex) {
            if (!cache.getCancelCriterion().isCancelInProgress()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.CqService_EXCEPTION_IN_THE_CQLISTENER_OF_THE_CQ_CQNAME_0_ERROR__1, new Object[] { cqName, ex.getMessage() }));
                if (isDebugEnabled) {
                    logger.debug(ex.getMessage(), ex);
                }
            }
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            logger.warn(LocalizedMessage.create(LocalizedStrings.CqService_RUNTIME_EXCEPTION_IN_THE_CQLISTENER_OF_THE_CQ_CQNAME_0_ERROR__1, new Object[] { cqName, t.getLocalizedMessage() }));
            if (isDebugEnabled) {
                logger.debug(t.getMessage(), t);
            }
        }
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) CqListener(org.apache.geode.cache.query.CqListener) Part(org.apache.geode.internal.cache.tier.sockets.Part) 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)

Aggregations

InvalidDeltaException (org.apache.geode.InvalidDeltaException)20 IOException (java.io.IOException)8 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 EventID (org.apache.geode.internal.cache.EventID)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 Part (org.apache.geode.internal.cache.tier.sockets.Part)3 ByteBuffer (java.nio.ByteBuffer)2 CancelException (org.apache.geode.CancelException)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 Region (org.apache.geode.cache.Region)2 ResourceException (org.apache.geode.cache.ResourceException)2 PutOperationContext (org.apache.geode.cache.operations.PutOperationContext)2 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 DeltaSessionAttributeEvent (org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEvent)2 DeltaSessionAttributeEventBatch (org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEventBatch)2 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutput (java.io.DataOutput)1