Search in sources :

Example 1 with DeltaSerializationException

use of org.apache.geode.DeltaSerializationException 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 2 with DeltaSerializationException

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

the class LocalRegion method extractDeltaIntoEvent.

private void extractDeltaIntoEvent(Object value, EntryEventImpl event) {
    // 11. Wrap any checked exception in InternalGemFireException before throwing it.
    try {
        // How costly is this if check?
        if (getSystem().getConfig().getDeltaPropagation() && value instanceof Delta) {
            boolean extractDelta = false;
            if (!this.hasServerProxy()) {
                if (this instanceof PartitionedRegion) {
                    if (((PartitionedRegion) this).getRedundantCopies() > 0) {
                        extractDelta = true;
                    } else {
                        InternalDistributedMember ids = (InternalDistributedMember) PartitionRegionHelper.getPrimaryMemberForKey(this, event.getKey());
                        if (ids != null) {
                            extractDelta = !this.getSystem().getMemberId().equals(ids.getId()) || hasAdjunctRecipientsNeedingDelta(event);
                        } else {
                            extractDelta = true;
                        }
                    }
                } else if (this instanceof DistributedRegion && !((DistributedRegion) this).scope.isDistributedNoAck() && !((CacheDistributionAdvisee) this).getCacheDistributionAdvisor().adviseCacheOp().isEmpty()) {
                    extractDelta = true;
                }
                if (!extractDelta && ClientHealthMonitor.getInstance() != null) {
                    extractDelta = ClientHealthMonitor.getInstance().hasDeltaClients();
                }
            } else if (HandShake.isDeltaEnabledOnServer()) {
                // This is a client region
                extractDelta = true;
            }
            if (extractDelta && ((org.apache.geode.Delta) value).hasDelta()) {
                HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
                long start = DistributionStats.getStatTime();
                try {
                    ((org.apache.geode.Delta) value).toDelta(hdos);
                } catch (RuntimeException re) {
                    throw re;
                } catch (Exception e) {
                    throw new DeltaSerializationException(LocalizedStrings.DistributionManager_CAUGHT_EXCEPTION_WHILE_SENDING_DELTA.toLocalizedString(), e);
                }
                event.setDeltaBytes(hdos.toByteArray());
                this.getCachePerfStats().endDeltaPrepared(start);
            }
        }
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new InternalGemFireException(e);
    }
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Delta(org.apache.geode.Delta) DeltaSerializationException(org.apache.geode.DeltaSerializationException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Aggregations

DeltaSerializationException (org.apache.geode.DeltaSerializationException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 CancelException (org.apache.geode.CancelException)1 Delta (org.apache.geode.Delta)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 CacheException (org.apache.geode.cache.CacheException)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 CacheRuntimeException (org.apache.geode.cache.CacheRuntimeException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 DiskAccessException (org.apache.geode.cache.DiskAccessException)1 EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)1