Search in sources :

Example 6 with IndexManager

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

the class AbstractRegionEntry method destroy.

/**
   * @throws EntryNotFoundException if expectedOldValue is not null and is not equal to current
   *         value
   */
@Override
@Released
public boolean destroy(LocalRegion region, EntryEventImpl event, boolean inTokenMode, boolean cacheWrite, @Unretained Object expectedOldValue, boolean forceDestroy, boolean removeRecoveredEntry) throws CacheWriterException, EntryNotFoundException, TimeoutException, RegionClearedException {
    // A design decision was made to not retrieve the old value from the disk
    // if the entry has been evicted to only have the CacheListener afterDestroy
    // method ignore it. We don't want to pay the performance penalty. The
    // getValueInVM method does not retrieve the value from disk if it has been
    // evicted. Instead, it uses the NotAvailable token.
    //
    // If the region is a WAN queue region, the old value is actually used by the
    // afterDestroy callback on a secondary. It is not needed on a primary.
    // Since the destroy that sets WAN_QUEUE_TOKEN always originates on the primary
    // we only pay attention to WAN_QUEUE_TOKEN if the event is originRemote.
    //
    // We also read old value from disk or buffer
    // in the case where there is a non-null expectedOldValue
    // see PartitionedRegion#remove(Object key, Object value)
    ReferenceCountHelper.skipRefCountTracking();
    @Retained @Released Object curValue = _getValueRetain(region, true);
    ReferenceCountHelper.unskipRefCountTracking();
    boolean proceed;
    try {
        if (curValue == null) {
            curValue = Token.NOT_AVAILABLE;
        }
        if (curValue == Token.NOT_AVAILABLE) {
            // the state of the transmitting cache's entry & should be used here
            if (event.getCallbackArgument() != null && event.getCallbackArgument().equals(RegionQueue.WAN_QUEUE_TOKEN) && event.isOriginRemote()) {
                // check originRemote for bug 40508
                // curValue = getValue(region); can cause deadlock if GII is occurring
                curValue = getValueOnDiskOrBuffer(region);
            } else {
                FilterProfile fp = region.getFilterProfile();
                if (fp != null && (fp.getCqCount() > 0 || expectedOldValue != null)) {
                    // curValue = getValue(region); can cause deadlock will fault in the value
                    // and will confuse LRU.
                    curValue = getValueOnDiskOrBuffer(region);
                }
            }
        }
        if (expectedOldValue != null) {
            if (!checkExpectedOldValue(expectedOldValue, curValue, region)) {
                throw new EntryNotFoundException(LocalizedStrings.AbstractRegionEntry_THE_CURRENT_VALUE_WAS_NOT_EQUAL_TO_EXPECTED_VALUE.toLocalizedString());
            }
        }
        if (inTokenMode && event.hasOldValue()) {
            proceed = true;
        } else {
            proceed = event.setOldValue(curValue, curValue instanceof GatewaySenderEventImpl) || removeRecoveredEntry || forceDestroy || region.getConcurrencyChecksEnabled() || (event.getOperation() == Operation.REMOVE && (curValue == null || curValue == Token.LOCAL_INVALID || curValue == Token.INVALID));
        }
    } finally {
        OffHeapHelper.releaseWithNoTracking(curValue);
    }
    if (proceed) {
        // after the entry not found exception above.
        if (!removeRecoveredEntry) {
            region.generateAndSetVersionTag(event, this);
        }
        if (cacheWrite) {
            region.cacheWriteBeforeDestroy(event, expectedOldValue);
            if (event.getRegion().getServerProxy() != null) {
                // server will return a version tag
                // update version information (may throw ConcurrentCacheModificationException)
                VersionStamp stamp = getVersionStamp();
                if (stamp != null) {
                    stamp.processVersionTag(event);
                }
            }
        }
        region.recordEvent(event);
        // RegionEntry (the old value) is invalid
        if (!region.isProxy() && !isInvalid()) {
            IndexManager indexManager = region.getIndexManager();
            if (indexManager != null) {
                try {
                    if (isValueNull()) {
                        @Released Object value = getValueOffHeapOrDiskWithoutFaultIn(region);
                        try {
                            Object preparedValue = prepareValueForCache(region, value, false);
                            _setValue(preparedValue);
                            releaseOffHeapRefIfRegionBeingClosedOrDestroyed(region, preparedValue);
                        } finally {
                            OffHeapHelper.release(value);
                        }
                    }
                    indexManager.updateIndexes(this, IndexManager.REMOVE_ENTRY, IndexProtocol.OTHER_OP);
                } catch (QueryException e) {
                    throw new IndexMaintenanceException(e);
                }
            }
        }
        boolean removeEntry = false;
        VersionTag v = event.getVersionTag();
        if (region.concurrencyChecksEnabled && !removeRecoveredEntry && !event.isFromRILocalDestroy()) {
            // Destroy will write a tombstone instead
            if (v == null || !v.hasValidVersion()) {
                // localDestroy and eviction and ops received with no version tag
                // should create a tombstone using the existing version stamp, as should
                // (bug #45245) responses from servers that do not have valid version information
                VersionStamp stamp = this.getVersionStamp();
                if (stamp != null) {
                    // proxy has no stamps
                    v = stamp.asVersionTag();
                    event.setVersionTag(v);
                }
            }
            removeEntry = v == null || !v.hasValidVersion();
        } else {
            removeEntry = true;
        }
        if (removeEntry) {
            boolean isThisTombstone = isTombstone();
            if (inTokenMode && !event.getOperation().isEviction()) {
                setValue(region, Token.DESTROYED);
            } else {
                removePhase1(region, false);
            }
            if (isThisTombstone) {
                region.unscheduleTombstone(this);
            }
        } else {
            makeTombstone(region, v);
        }
        return true;
    } else {
        return false;
    }
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) QueryException(org.apache.geode.cache.query.QueryException) Released(org.apache.geode.internal.offheap.annotations.Released) Retained(org.apache.geode.internal.offheap.annotations.Retained) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) StoredObject(org.apache.geode.internal.offheap.StoredObject) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) Released(org.apache.geode.internal.offheap.annotations.Released)

Example 7 with IndexManager

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

the class AbstractRegion method setIndexManager.

/**
   * This method call is guarded by imSync lock created for each region. Set IndexManger for region.
   */
public IndexManager setIndexManager(IndexManager indexManager) {
    checkReadiness();
    IndexManager oldIdxManager = this.indexManager;
    this.indexManager = indexManager;
    return oldIdxManager;
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager)

Example 8 with IndexManager

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

the class QueryObserverCallbackJUnitTest method tearDown.

@After
public void tearDown() throws Exception {
    CacheUtils.closeCache();
    IndexManager indexManager = ((LocalRegion) region).getIndexManager();
    if (indexManager != null)
        indexManager.destroy();
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) LocalRegion(org.apache.geode.internal.cache.LocalRegion) After(org.junit.After)

Example 9 with IndexManager

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

the class CompiledJunctionInternalsJUnitTest method tearDown.

@After
public void tearDown() throws Exception {
    CacheUtils.closeCache();
    IndexManager indexManager = ((LocalRegion) region).getIndexManager();
    if (indexManager != null)
        indexManager.destroy();
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) LocalRegion(org.apache.geode.internal.cache.LocalRegion) After(org.junit.After)

Example 10 with IndexManager

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

the class PartitionedRegion method removeIndex.

/**
   * Removes a particular index on this partitioned regions instance.
   * 
   * @param ind Index to be removed.
   * 
   */
public int removeIndex(Index ind, boolean remotelyOriginated) throws CacheException, ForceReattemptException {
    int numBuckets = 0;
    IndexTask indexTask = null;
    Object prIndex = null;
    if (ind != null) {
        indexTask = new IndexTask(ind.getName());
        prIndex = this.indexes.get(indexTask);
    }
    // not in create phase, its created successfully).
    if (prIndex == null || !(prIndex instanceof Index)) {
        logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_THIS_INDEX__0_IS_NOT_ON_THIS_PARTITONED_REGION___1, new Object[] { ind, this }));
        return numBuckets;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Remove index called, IndexName: {} Index: {}  Will be removing all the bucket indexes.", ind.getName(), ind);
    }
    Index index1 = this.indexManager.getIndex(ind.getName());
    if (index1 != null) {
        this.indexManager.removeIndex(index1);
    }
    // marking the index invalid.
    if (prIndex != null) {
        PartitionedIndex index = (PartitionedIndex) prIndex;
        index.acquireIndexWriteLockForRemove();
    }
    this.indexes.remove(indexTask);
    // For releasing the write lock after removal.
    try {
        synchronized (prIndex) {
            List allBucketIndex = ((PartitionedIndex) prIndex).getBucketIndexes();
            Iterator it = allBucketIndex.iterator();
            if (logger.isDebugEnabled()) {
                logger.debug("Will be removing indexes on : {} buckets", allBucketIndex.size());
            }
            while (it.hasNext()) {
                Index in = (Index) it.next();
                LocalRegion region = ((LocalRegion) in.getRegion());
                region.waitForData();
                IndexManager indMng = region.getIndexManager();
                indMng.removeIndex(in);
                if (logger.isDebugEnabled()) {
                    logger.debug("Removed index : {} on bucket {}", in, region);
                }
                numBuckets++;
                ((PartitionedIndex) prIndex).removeFromBucketIndexes(region, in);
            }
        // while
        }
    } finally {
        ((PartitionedIndex) prIndex).releaseIndexWriteLockForRemove();
    }
    if (!remotelyOriginated) {
        // send remove index message.
        RemoveIndexesMessage.RemoveIndexesResponse response;
        logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_SENDING_REMOVEINDEX_MESSAGE_TO_ALL_THE_PARTICIPATING_PRS));
        response = (RemoveIndexesMessage.RemoveIndexesResponse) RemoveIndexesMessage.send(this, ind, false);
        if (response != null) {
            response.waitForResults();
            logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_DONE_WATING_FOR_REMOVE_INDEX));
            if (logger.isDebugEnabled()) {
                logger.debug("Total number of buckets which removed indexs , locally : {} and remotely removed : {} and the total number of remote buckets : {}", numBuckets, response.getRemoteRemovedIndexes(), response.getTotalRemoteBuckets());
            }
        }
    }
    return numBuckets;
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) RemoveIndexesMessage(org.apache.geode.internal.cache.partitioned.RemoveIndexesMessage) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List)

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