Search in sources :

Example 6 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class AbstractRegionEntry method fillInValue.

@Override
public boolean fillInValue(LocalRegion region, @Retained(ABSTRACT_REGION_ENTRY_FILL_IN_VALUE) InitialImageOperation.Entry entry, ByteArrayDataInput in, DM mgr) {
    // starting default value
    entry.setSerialized(false);
    @Retained(ABSTRACT_REGION_ENTRY_FILL_IN_VALUE) final Object v;
    if (isTombstone()) {
        v = Token.TOMBSTONE;
    } else {
        // OFFHEAP: need to incrc, copy bytes, decrc
        v = getValue(region);
        if (v == null) {
            return false;
        }
    }
    // fix for bug 31059
    entry.setLastModified(mgr, getLastModified());
    if (v == Token.INVALID) {
        entry.setInvalid();
    } else if (v == Token.LOCAL_INVALID) {
        entry.setLocalInvalid();
    } else if (v == Token.TOMBSTONE) {
        entry.setTombstone();
    } else if (v instanceof CachedDeserializable) {
        // don't serialize here if it is not already serialized
        CachedDeserializable cd = (CachedDeserializable) v;
        if (!cd.isSerialized()) {
            entry.value = cd.getDeserializedForReading();
        } else {
            Object tmp = cd.getValue();
            if (tmp instanceof byte[]) {
                entry.value = tmp;
            } else {
                try {
                    HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
                    BlobHelper.serializeTo(tmp, hdos);
                    hdos.trim();
                    entry.value = hdos;
                } catch (IOException e) {
                    throw new IllegalArgumentException(LocalizedStrings.AbstractRegionEntry_AN_IOEXCEPTION_WAS_THROWN_WHILE_SERIALIZING.toLocalizedString(), e);
                }
            }
            entry.setSerialized(true);
        }
    } else if (v instanceof byte[]) {
        entry.value = v;
    } else {
        Object preparedValue = v;
        if (preparedValue != null) {
            preparedValue = prepareValueForGII(preparedValue);
            if (preparedValue == null) {
                return false;
            }
        }
        try {
            HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
            BlobHelper.serializeTo(preparedValue, hdos);
            hdos.trim();
            entry.value = hdos;
            entry.setSerialized(true);
        } catch (IOException e) {
            throw new IllegalArgumentException(LocalizedStrings.AbstractRegionEntry_AN_IOEXCEPTION_WAS_THROWN_WHILE_SERIALIZING.toLocalizedString(), e);
        }
    }
    return true;
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) StoredObject(org.apache.geode.internal.offheap.StoredObject) IOException(java.io.IOException)

Example 7 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class BucketRegion method setDeltaIfNeeded.

private void setDeltaIfNeeded(EntryEventImpl event) {
    if (this.partitionedRegion.getSystem().getConfig().getDeltaPropagation() && event.getOperation().isUpdate() && event.getDeltaBytes() == null) {
        @Unretained Object rawNewValue = event.getRawNewValue();
        if (!(rawNewValue instanceof CachedDeserializable)) {
            return;
        }
        CachedDeserializable cd = (CachedDeserializable) rawNewValue;
        if (!cd.isSerialized()) {
            // it is a byte[]; not a Delta
            return;
        }
        Object instance = cd.getValue();
        if (instance instanceof org.apache.geode.Delta && ((org.apache.geode.Delta) instance).hasDelta()) {
            try {
                HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
                long start = DistributionStats.getStatTime();
                ((org.apache.geode.Delta) instance).toDelta(hdos);
                event.setDeltaBytes(hdos.toByteArray());
                this.partitionedRegion.getCachePerfStats().endDeltaPrepared(start);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new DeltaSerializationException(LocalizedStrings.DistributionManager_CAUGHT_EXCEPTION_WHILE_SENDING_DELTA.toLocalizedString(), e);
            }
        }
    }
}
Also used : org.apache.geode(org.apache.geode) IOException(java.io.IOException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) LockObject(org.apache.geode.internal.cache.partitioned.LockObject) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Example 8 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class Oplog method serializeVersionTag.

private byte[] serializeVersionTag(int entryVersion, long regionVersion, VersionSource versionMember, long timestamp, int dsId) throws IOException {
    HeapDataOutputStream out = new HeapDataOutputStream(4 + 8 + 4 + 8 + 4, Version.CURRENT);
    serializeVersionTag(entryVersion, regionVersion, versionMember, timestamp, dsId, out);
    return out.toByteArray();
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Example 9 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class Oplog method serializeRVVs.

private byte[] serializeRVVs(Map<Long, AbstractDiskRegion> drMap, boolean gcRVV) throws IOException {
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    // Filter out any regions that do not have versioning enabled
    drMap = new HashMap<Long, AbstractDiskRegion>(drMap);
    for (Iterator<Map.Entry<Long, AbstractDiskRegion>> itr = drMap.entrySet().iterator(); itr.hasNext(); ) {
        Map.Entry<Long, AbstractDiskRegion> regionEntry = itr.next();
        AbstractDiskRegion dr = regionEntry.getValue();
        if (!dr.getFlags().contains(DiskRegionFlag.IS_WITH_VERSIONING)) {
            itr.remove();
        }
    }
    // Write the size first
    InternalDataSerializer.writeUnsignedVL(drMap.size(), out);
    // Now write regions RVV.
    for (Map.Entry<Long, AbstractDiskRegion> regionEntry : drMap.entrySet()) {
        // For each region, write the RVV for the region.
        Long diskRegionID = regionEntry.getKey();
        AbstractDiskRegion dr = regionEntry.getValue();
        RegionVersionVector rvv = dr.getRegionVersionVector();
        if (logger.isTraceEnabled(LogMarker.PERSIST_WRITES)) {
            logger.trace(LogMarker.PERSIST_WRITES, "serializeRVVs: isGCRVV={} drId={} rvv={} oplog#{}", gcRVV, diskRegionID, rvv.fullToString(), getOplogId());
        }
        // Write the disk region id
        InternalDataSerializer.writeUnsignedVL(diskRegionID, out);
        if (gcRVV) {
            // For the GC RVV, we will just write the GC versions
            Map<VersionSource, Long> memberToVersion = rvv.getMemberToGCVersion();
            InternalDataSerializer.writeUnsignedVL(memberToVersion.size(), out);
            for (Entry<VersionSource, Long> memberEntry : memberToVersion.entrySet()) {
                // For each member, write the canonicalized member id,
                // and the version number for that member
                VersionSource member = memberEntry.getKey();
                Long gcVersion = memberEntry.getValue();
                int id = getParent().getDiskInitFile().getOrCreateCanonicalId(member);
                InternalDataSerializer.writeUnsignedVL(id, out);
                InternalDataSerializer.writeUnsignedVL(gcVersion, out);
            }
        } else {
            DataSerializer.writeBoolean(dr.getRVVTrusted(), out);
            // Otherwise, we will write the version and exception list for each
            // member
            Map<VersionSource, RegionVersionHolder> memberToVersion = rvv.getMemberToVersion();
            InternalDataSerializer.writeUnsignedVL(memberToVersion.size(), out);
            for (Map.Entry<VersionSource, RegionVersionHolder> memberEntry : memberToVersion.entrySet()) {
                // For each member, right the canonicalized member id,
                // and the version number with exceptions for that member
                VersionSource member = memberEntry.getKey();
                RegionVersionHolder versionHolder = memberEntry.getValue();
                int id = getParent().getDiskInitFile().getOrCreateCanonicalId(member);
                InternalDataSerializer.writeUnsignedVL(id, out);
                synchronized (versionHolder) {
                    InternalDataSerializer.invokeToData(versionHolder, out);
                }
            }
        }
    }
    return out.toByteArray();
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder) Entry(java.util.Map.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 10 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream 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

HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)134 Test (org.junit.Test)55 IOException (java.io.IOException)40 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)36 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)33 DataInputStream (java.io.DataInputStream)29 ByteArrayInputStream (java.io.ByteArrayInputStream)23 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 DiskAccessException (org.apache.geode.cache.DiskAccessException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 PdxSerializerObject (org.apache.geode.internal.PdxSerializerObject)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 Version (org.apache.geode.internal.Version)8 DataInput (java.io.DataInput)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7 OutputStream (java.io.OutputStream)6 Properties (java.util.Properties)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5