Search in sources :

Example 16 with IndexManager

use of org.apache.geode.cache.query.internal.index.IndexManager in project geode by apache.

the class EntryEventImpl method setNewValueInRegion.

@Retained(ENTRY_EVENT_NEW_VALUE)
private void setNewValueInRegion(final LocalRegion owner, final RegionEntry reentry, Object oldValueForDelta) throws RegionClearedException {
    boolean wasTombstone = reentry.isTombstone();
    // not be applied. This is possible if the event originated locally.
    if (this.deltaBytes != null && this.newValue == null) {
        processDeltaBytes(oldValueForDelta);
    }
    if (owner != null) {
        owner.generateAndSetVersionTag(this, reentry);
    } else {
        this.region.generateAndSetVersionTag(this, reentry);
    }
    Object v = this.newValue;
    if (v == null) {
        v = isLocalInvalid() ? Token.LOCAL_INVALID : Token.INVALID;
    } else {
        this.region.regionInvalid = false;
    }
    reentry.setValueResultOfSearch(this.op.isNetSearch());
    // in the primary.
    if (v instanceof org.apache.geode.Delta && region.isUsedForPartitionedRegionBucket()) {
        int vSize;
        Object ov = basicGetOldValue();
        if (ov instanceof CachedDeserializable && !GemFireCacheImpl.DELTAS_RECALCULATE_SIZE) {
            vSize = ((CachedDeserializable) ov).getValueSizeInBytes();
        } else {
            vSize = CachedDeserializableFactory.calcMemSize(v, region.getObjectSizer(), false);
        }
        v = CachedDeserializableFactory.create(v, vSize);
        basicSetNewValue(v);
    }
    Object preparedV = reentry.prepareValueForCache(this.region, v, this, false);
    if (preparedV != v) {
        v = preparedV;
        if (v instanceof StoredObject) {
            if (!((StoredObject) v).isCompressed()) {
                // fix bug 52109
                // If we put it off heap and it is not compressed then remember that value.
                // Otherwise we want to remember the decompressed value in the event.
                basicSetNewValue(v);
            }
        }
    }
    boolean isTombstone = (v == Token.TOMBSTONE);
    boolean success = false;
    boolean calledSetValue = false;
    try {
        setNewValueBucketSize(owner, v);
        if ((this.op.isUpdate() && !reentry.isInvalid()) || this.op.isInvalidate()) {
            IndexManager idxManager = IndexUtils.getIndexManager(this.region, false);
            if (idxManager != null) {
                try {
                    idxManager.updateIndexes(reentry, IndexManager.REMOVE_ENTRY, this.op.isUpdate() ? IndexProtocol.BEFORE_UPDATE_OP : IndexProtocol.OTHER_OP);
                } catch (QueryException e) {
                    throw new IndexMaintenanceException(e);
                }
            }
        }
        calledSetValue = true;
        // already called prepareValueForCache
        reentry.setValueWithTombstoneCheck(v, this);
        success = true;
    } finally {
        if (!success && reentry instanceof OffHeapRegionEntry && v instanceof StoredObject) {
            OffHeapRegionEntryHelper.releaseEntry((OffHeapRegionEntry) reentry, (StoredObject) v);
        }
    }
    if (logger.isTraceEnabled()) {
        if (v instanceof CachedDeserializable) {
            logger.trace("EntryEventImpl.setNewValueInRegion: put CachedDeserializable({},{})", this.getKey(), ((CachedDeserializable) v).getStringForm());
        } else {
            logger.trace("EntryEventImpl.setNewValueInRegion: put({},{})", this.getKey(), StringUtils.forceToString(v));
        }
    }
    if (!isTombstone && wasTombstone) {
        owner.unscheduleTombstone(reentry);
    }
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) QueryException(org.apache.geode.cache.query.QueryException) StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Aggregations

IndexManager (org.apache.geode.cache.query.internal.index.IndexManager)16 StoredObject (org.apache.geode.internal.offheap.StoredObject)7 DiskAccessException (org.apache.geode.cache.DiskAccessException)5 Released (org.apache.geode.internal.offheap.annotations.Released)5 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)3 After (org.junit.After)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 Region (org.apache.geode.cache.Region)2 Index (org.apache.geode.cache.query.Index)2 IndexMaintenanceException (org.apache.geode.cache.query.IndexMaintenanceException)2 QueryException (org.apache.geode.cache.query.QueryException)2