use of org.apache.geode.internal.cache.versions.VersionSource in project geode by apache.
the class VersionedObjectList method fromData.
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
final boolean isDebugEnabled_VOL = logger.isTraceEnabled(LogMarker.VERSIONED_OBJECT_LIST);
int flags = in.readByte();
this.hasKeys = (flags & 0x01) == 0x01;
boolean hasObjects = (flags & 0x02) == 0x02;
boolean hasTags = (flags & 0x04) == 0x04;
this.regionIsVersioned = (flags & 0x08) == 0x08;
this.serializeValues = (flags & 0x10) == 0x10;
boolean persistent = (flags & 0x20) == 0x20;
if (isDebugEnabled_VOL) {
logger.trace(LogMarker.VERSIONED_OBJECT_LIST, "deserializing a VersionedObjectList with flags 0x{}", Integer.toHexString(flags));
}
if (this.hasKeys) {
int size = (int) InternalDataSerializer.readUnsignedVL(in);
this.keys = new ArrayList(size);
if (isDebugEnabled_VOL) {
logger.trace(LogMarker.VERSIONED_OBJECT_LIST, "reading {} keys", size);
}
for (int i = 0; i < size; i++) {
this.keys.add(DataSerializer.readObject(in));
}
}
if (hasObjects) {
int size = (int) InternalDataSerializer.readUnsignedVL(in);
if (isDebugEnabled_VOL) {
logger.trace(LogMarker.VERSIONED_OBJECT_LIST, "reading {} objects", size);
}
this.objects = new ArrayList(size);
this.objectTypeArray = new byte[size];
for (int i = 0; i < size; i++) {
readObject(i, in);
}
} else {
this.objects = new ArrayList();
}
if (hasTags) {
int size = (int) InternalDataSerializer.readUnsignedVL(in);
if (isDebugEnabled_VOL) {
logger.trace(LogMarker.VERSIONED_OBJECT_LIST, "reading {} version tags", size);
}
this.versionTags = new ArrayList<VersionTag>(size);
List<VersionSource> ids = new ArrayList<VersionSource>(size);
for (int i = 0; i < size; i++) {
byte entryType = in.readByte();
switch(entryType) {
case FLAG_NULL_TAG:
this.versionTags.add(null);
break;
case FLAG_FULL_TAG:
this.versionTags.add(VersionTag.create(persistent, in));
break;
case FLAG_TAG_WITH_NEW_ID:
VersionTag tag = VersionTag.create(persistent, in);
ids.add(tag.getMemberID());
this.versionTags.add(tag);
break;
case FLAG_TAG_WITH_NUMBER_ID:
tag = VersionTag.create(persistent, in);
int idNumber = (int) InternalDataSerializer.readUnsignedVL(in);
tag.setMemberID(ids.get(idNumber));
this.versionTags.add(tag);
break;
}
}
} else {
this.versionTags = new ArrayList<VersionTag>();
}
}
use of org.apache.geode.internal.cache.versions.VersionSource in project geode by apache.
the class VersionedObjectList method toData.
void toData(DataOutput out, int startIndex, int numEntries, boolean sendKeys, boolean sendObjects) throws IOException {
int flags = 0;
boolean hasObjects = false;
boolean hasTags = false;
if (sendKeys && this.hasKeys) {
flags |= 0x01;
}
if (sendObjects && !this.objects.isEmpty()) {
flags |= 0x02;
hasObjects = true;
}
if (this.versionTags.size() > 0) {
flags |= 0x04;
hasTags = true;
for (VersionTag tag : this.versionTags) {
if (tag != null) {
if (tag instanceof DiskVersionTag) {
flags |= 0x20;
}
break;
}
}
}
if (this.regionIsVersioned) {
flags |= 0x08;
}
if (this.serializeValues) {
flags |= 0x10;
}
if (logger.isTraceEnabled(LogMarker.VERSIONED_OBJECT_LIST)) {
logger.trace(LogMarker.VERSIONED_OBJECT_LIST, "serializing {} with flags 0x{} startIndex={} numEntries={}", this, Integer.toHexString(flags), startIndex, numEntries);
}
out.writeByte(flags);
if (sendKeys && hasKeys) {
int numToWrite = numEntries;
if (numToWrite + startIndex > this.keys.size()) {
numToWrite = Math.max(0, this.keys.size() - startIndex);
}
InternalDataSerializer.writeUnsignedVL(numToWrite, out);
int index = startIndex;
for (int i = 0; i < numToWrite; i++, index++) {
DataSerializer.writeObject(this.keys.get(index), out);
}
}
if (sendObjects && hasObjects) {
int numToWrite = numEntries;
if (numToWrite + startIndex > this.objects.size()) {
numToWrite = Math.max(0, this.objects.size() - startIndex);
}
InternalDataSerializer.writeUnsignedVL(numToWrite, out);
int idx = 0;
int index = startIndex;
for (int i = 0; i < numToWrite; i++, index++) {
writeObject(this.objects.get(index), idx++, out);
}
}
if (hasTags) {
int numToWrite = numEntries;
if (numToWrite + startIndex > this.versionTags.size()) {
numToWrite = Math.max(0, this.versionTags.size() - startIndex);
}
InternalDataSerializer.writeUnsignedVL(numToWrite, out);
Map<VersionSource, Integer> ids = new HashMap<VersionSource, Integer>(numToWrite);
int idCount = 0;
int index = startIndex;
for (int i = 0; i < numToWrite; i++, index++) {
VersionTag tag = this.versionTags.get(index);
if (tag == null) {
out.writeByte(FLAG_NULL_TAG);
} else {
VersionSource id = tag.getMemberID();
if (id == null) {
out.writeByte(FLAG_FULL_TAG);
InternalDataSerializer.invokeToData(tag, out);
} else {
Integer idNumber = ids.get(id);
if (idNumber == null) {
out.writeByte(FLAG_TAG_WITH_NEW_ID);
idNumber = Integer.valueOf(idCount++);
ids.put(id, idNumber);
InternalDataSerializer.invokeToData(tag, out);
} else {
out.writeByte(FLAG_TAG_WITH_NUMBER_ID);
tag.toData(out, false);
tag.setMemberID(id);
InternalDataSerializer.writeUnsignedVL(idNumber, out);
}
}
}
}
}
}
use of org.apache.geode.internal.cache.versions.VersionSource in project geode by apache.
the class DiskStoreImpl method shouldClear.
private boolean shouldClear(LocalRegion r, RegionVersionVector rvv, AsyncDiskEntry ade) {
if (ade.region != r) {
return false;
}
// If no RVV, remove all of the async items for this region.
if (rvv == null) {
return true;
}
// entries contained in the RVV
if (ade.versionOnly) {
return rvv.contains(ade.tag.getMemberID(), ade.tag.getRegionVersion());
} else {
VersionStamp stamp = ade.de.getVersionStamp();
VersionSource member = stamp.getMemberID();
if (member == null) {
// For overflow only regions, the version member may be null
// because that represents the local internal distributed member
member = r.getVersionMember();
}
return rvv.contains(member, stamp.getRegionVersion());
}
}
use of org.apache.geode.internal.cache.versions.VersionSource in project geode by apache.
the class Oplog method serializeVersionTag.
byte[] serializeVersionTag(VersionStamp stamp) throws IOException {
int entryVersion = stamp.getEntryVersion();
long regionVersion = stamp.getRegionVersion();
VersionSource versionMember = stamp.getMemberID();
long timestamp = stamp.getVersionTimeStamp();
int dsId = stamp.getDistributedSystemId();
return serializeVersionTag(entryVersion, regionVersion, versionMember, timestamp, dsId);
}
use of org.apache.geode.internal.cache.versions.VersionSource in project geode by apache.
the class Oplog method serializeVersionTag.
void serializeVersionTag(VersionHolder tag, DataOutput out) throws IOException {
int entryVersion = tag.getEntryVersion();
long regionVersion = tag.getRegionVersion();
VersionSource versionMember = tag.getMemberID();
long timestamp = tag.getVersionTimeStamp();
int dsId = tag.getDistributedSystemId();
serializeVersionTag(entryVersion, regionVersion, versionMember, timestamp, dsId, out);
}
Aggregations