Search in sources :

Example 1 with PutMessage

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

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DeltaSerializationException (org.apache.geode.DeltaSerializationException)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 PutMessage (org.apache.geode.internal.cache.partitioned.PutMessage)1 StoredObject (org.apache.geode.internal.offheap.StoredObject)1