Search in sources :

Example 1 with Versionable

use of org.apache.geode.internal.util.Versionable in project geode by apache.

the class AbstractRegionEntry method initialImageInit.

@Override
public boolean initialImageInit(final LocalRegion region, final long lastModified, final Object newValue, final boolean create, final boolean wasRecovered, final boolean acceptedVersionTag) throws RegionClearedException {
    // note that the caller has already write synced this RegionEntry
    boolean result = false;
    // if it has been destroyed then don't do anything
    Token vTok = getValueAsToken();
    if (acceptedVersionTag || create || (vTok != Token.DESTROYED || vTok != Token.TOMBSTONE)) {
        // OFFHEAP noop
        Object newValueToWrite = newValue;
        // OFFHEAP noop
        boolean putValue = acceptedVersionTag || create || (newValueToWrite != Token.LOCAL_INVALID && (wasRecovered || (vTok == Token.LOCAL_INVALID)));
        if (region.isUsedForPartitionedRegionAdmin() && newValueToWrite instanceof CachedDeserializable) {
            // Special case for partitioned region meta data
            // We do not need the RegionEntry on this case.
            // Because the pr meta data region will not have an LRU.
            newValueToWrite = ((CachedDeserializable) newValueToWrite).getDeserializedValue(region, null);
            if (!create && newValueToWrite instanceof Versionable) {
                // Heap value should always be deserialized at this point // OFFHEAP will not be
                // deserialized
                final Object oldValue = getValueInVM(region);
                // BUGFIX for 35029. If oldValue is null the newValue should be put.
                if (oldValue == null) {
                    putValue = true;
                } else if (oldValue instanceof Versionable) {
                    Versionable nv = (Versionable) newValueToWrite;
                    Versionable ov = (Versionable) oldValue;
                    putValue = nv.isNewerThan(ov);
                }
            }
        }
        if (putValue) {
            // and current value is recovered
            if (create || acceptedVersionTag) {
                // At this point, since we now always recover from disk first,
                // we only care about "isCreate" since "isRecovered" is impossible
                // if we had a regionInvalidate or regionClear
                ImageState imageState = region.getImageState();
                // this method is called during loadSnapshot as well as getInitialImage
                if (imageState.getRegionInvalidated()) {
                    if (newValueToWrite != Token.TOMBSTONE) {
                        newValueToWrite = Token.INVALID;
                    }
                } else if (imageState.getClearRegionFlag()) {
                    boolean entryOK = false;
                    RegionVersionVector rvv = imageState.getClearRegionVersionVector();
                    if (rvv != null) {
                        // a filtered clear
                        VersionSource id = getVersionStamp().getMemberID();
                        if (id == null) {
                            id = region.getVersionMember();
                        }
                        if (!rvv.contains(id, getVersionStamp().getRegionVersion())) {
                            entryOK = true;
                        }
                    }
                    if (!entryOK) {
                        // If the region has been issued cleared during
                        // the GII , then those entries loaded before this one would have
                        // been cleared from the Map due to clear operation & for the
                        // currententry whose key may have escaped the clearance , will be
                        // cleansed by the destroy token.
                        // TODO: never used
                        newValueToWrite = Token.DESTROYED;
                        imageState.addDestroyedEntry(this.getKey());
                        throw new RegionClearedException(LocalizedStrings.AbstractRegionEntry_DURING_THE_GII_PUT_OF_ENTRY_THE_REGION_GOT_CLEARED_SO_ABORTING_THE_OPERATION.toLocalizedString());
                    }
                }
            }
            setValue(region, this.prepareValueForCache(region, newValueToWrite, false));
            result = true;
            if (newValueToWrite != Token.TOMBSTONE) {
                if (create) {
                    region.getCachePerfStats().incCreates();
                }
                region.updateStatsForPut(this, lastModified, false);
            }
            if (logger.isTraceEnabled()) {
                if (newValueToWrite instanceof CachedDeserializable) {
                    logger.trace("ProcessChunk: region={}; put a CachedDeserializable ({},{})", region.getFullPath(), getKey(), ((CachedDeserializable) newValueToWrite).getStringForm());
                } else {
                    logger.trace("ProcessChunk: region={}; put({},{})", region.getFullPath(), getKey(), StringUtils.forceToString(newValueToWrite));
                }
            }
        }
    }
    return result;
}
Also used : Versionable(org.apache.geode.internal.util.Versionable) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) StoredObject(org.apache.geode.internal.offheap.StoredObject) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

Aggregations

RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)1 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)1 StoredObject (org.apache.geode.internal.offheap.StoredObject)1 Versionable (org.apache.geode.internal.util.Versionable)1