Search in sources :

Example 16 with VersionSource

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>();
    }
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) ArrayList(java.util.ArrayList) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Example 17 with VersionSource

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);
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag)

Example 18 with VersionSource

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());
    }
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp)

Example 19 with VersionSource

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);
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource)

Example 20 with VersionSource

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);
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource)

Aggregations

VersionSource (org.apache.geode.internal.cache.versions.VersionSource)34 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)16 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)13 Entry (org.apache.geode.cache.Region.Entry)10 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)10 Test (org.junit.Test)10 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)6 Host (org.apache.geode.test.dunit.Host)5 VM (org.apache.geode.test.dunit.VM)5 HashMap (java.util.HashMap)4 Cache (org.apache.geode.cache.Cache)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Region (org.apache.geode.cache.Region)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 Map (java.util.Map)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 PRLocallyDestroyedException (org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException)3