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;
}
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);
}
}
}
}
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();
}
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();
}
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);
}
}
Aggregations