Search in sources :

Example 11 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class AbstractRegionMap method destroy.

public boolean destroy(EntryEventImpl event, boolean inTokenMode, boolean duringRI, boolean cacheWrite, boolean isEviction, Object expectedOldValue, boolean removeRecoveredEntry) throws CacheWriterException, EntryNotFoundException, TimeoutException {
    final LocalRegion owner = _getOwner();
    if (owner == null) {
        Assert.assertTrue(false, // "fix" for bug 32440
        "The owner for RegionMap " + this + " is null for event " + event);
    }
    boolean retry = true;
    lockForCacheModification(owner, event);
    try {
        while (retry) {
            retry = false;
            boolean opCompleted = false;
            boolean doPart3 = false;
            // We need to acquire the region entry while holding the lock to avoid #45620.
            // The outer try/finally ensures that the lock will be released without fail.
            // I'm avoiding indenting just to preserve the ability
            // to track diffs since the code is fairly complex.
            RegionEntry re = getOrCreateRegionEntry(owner, event, Token.REMOVED_PHASE1, null, true, true);
            RegionEntry tombstone = null;
            boolean haveTombstone = false;
            /*
         * Execute the test hook runnable inline (not threaded) if it is not null.
         */
            if (null != testHookRunnableFor48182) {
                testHookRunnableFor48182.run();
            }
            try {
                if (logger.isTraceEnabled(LogMarker.LRU_TOMBSTONE_COUNT) && !(owner instanceof HARegion)) {
                    logger.trace(LogMarker.LRU_TOMBSTONE_COUNT, "ARM.destroy() inTokenMode={}; duringRI={}; riLocalDestroy={}; withRepl={}; fromServer={}; concurrencyEnabled={}; isOriginRemote={}; isEviction={}; operation={}; re={}", inTokenMode, duringRI, event.isFromRILocalDestroy(), owner.dataPolicy.withReplication(), event.isFromServer(), owner.concurrencyChecksEnabled, event.isOriginRemote(), isEviction, event.getOperation(), re);
                }
                if (event.isFromRILocalDestroy()) {
                    // for RI local-destroy we don't want to keep tombstones.
                    // In order to simplify things we just set this recovery
                    // flag to true to force the entry to be removed
                    removeRecoveredEntry = true;
                }
                // for a tombstone here and, if found, pretend for a bit that the entry is null
                if (re != null && re.isTombstone() && !removeRecoveredEntry) {
                    tombstone = re;
                    haveTombstone = true;
                    re = null;
                }
                IndexManager oqlIndexManager = owner.getIndexManager();
                if (re == null) {
                    // we need to create an entry if in token mode or if we've received
                    // a destroy from a peer or WAN gateway and we need to retain version
                    // information for concurrency checks
                    boolean retainForConcurrency = (!haveTombstone && (owner.dataPolicy.withReplication() || event.isFromServer()) && owner.concurrencyChecksEnabled && (event.isOriginRemote() || /* destroy received from other must create tombstone */
                    event.isFromWANAndVersioned() || /* wan event must create a tombstone */
                    event.isBridgeEvent()));
                    /*
                                                 * event from client must create a tombstone so
                                                 * client has a version #
                                                 */
                    if (inTokenMode || retainForConcurrency) {
                        // removeRecoveredEntry should be false in this case
                        RegionEntry newRe = getEntryFactory().createEntry(owner, event.getKey(), Token.REMOVED_PHASE1);
                        // happened in parallel as it also does index INIT.
                        if (oqlIndexManager != null) {
                            oqlIndexManager.waitForIndexInit();
                        }
                        try {
                            synchronized (newRe) {
                                RegionEntry oldRe = putEntryIfAbsent(event.getKey(), newRe);
                                while (!opCompleted && oldRe != null) {
                                    synchronized (oldRe) {
                                        if (oldRe.isRemovedPhase2()) {
                                            owner.getCachePerfStats().incRetries();
                                            _getMap().remove(event.getKey(), oldRe);
                                            oldRe = putEntryIfAbsent(event.getKey(), newRe);
                                        } else {
                                            event.setRegionEntry(oldRe);
                                            // is being added to transaction state.
                                            if (isEviction) {
                                                if (!confirmEvictionDestroy(oldRe)) {
                                                    opCompleted = false;
                                                    return opCompleted;
                                                }
                                            }
                                            try {
                                                // if concurrency checks are enabled, destroy will
                                                // set the version tag
                                                boolean destroyed = destroyEntry(oldRe, event, inTokenMode, cacheWrite, expectedOldValue, false, removeRecoveredEntry);
                                                if (destroyed) {
                                                    if (retainForConcurrency) {
                                                        owner.basicDestroyBeforeRemoval(oldRe, event);
                                                    }
                                                    owner.basicDestroyPart2(oldRe, event, inTokenMode, false, /* conflict with clear */
                                                    duringRI, true);
                                                    lruEntryDestroy(oldRe);
                                                    doPart3 = true;
                                                }
                                            } catch (RegionClearedException rce) {
                                                // Ignore. The exception will ensure that we do not update
                                                // the LRU List
                                                owner.basicDestroyPart2(oldRe, event, inTokenMode, true, /* conflict with clear */
                                                duringRI, true);
                                                doPart3 = true;
                                            } catch (ConcurrentCacheModificationException ccme) {
                                                VersionTag tag = event.getVersionTag();
                                                if (tag != null && tag.isTimeStampUpdated()) {
                                                    // Notify gateways of new time-stamp.
                                                    owner.notifyTimestampsToGateways(event);
                                                }
                                                throw ccme;
                                            }
                                            re = oldRe;
                                            opCompleted = true;
                                        }
                                    }
                                // synchronized oldRe
                                }
                                // while
                                if (!opCompleted) {
                                    // happens if we didn't get completed with oldRe in the above while loop.
                                    try {
                                        re = newRe;
                                        event.setRegionEntry(newRe);
                                        try {
                                            // set the version tag
                                            if (isEviction) {
                                                opCompleted = false;
                                                return opCompleted;
                                            }
                                            opCompleted = destroyEntry(newRe, event, inTokenMode, cacheWrite, expectedOldValue, true, removeRecoveredEntry);
                                            if (opCompleted) {
                                                // This is a new entry that was created because we are in
                                                // token mode or are accepting a destroy operation by adding
                                                // a tombstone. There is no oldValue, so we don't need to
                                                // call updateSizeOnRemove
                                                // owner.recordEvent(event);
                                                // native clients need to know if the
                                                event.setIsRedestroyedEntry(true);
                                                // entry didn't exist
                                                if (retainForConcurrency) {
                                                    owner.basicDestroyBeforeRemoval(oldRe, event);
                                                }
                                                owner.basicDestroyPart2(newRe, event, inTokenMode, false, /* conflict with clear */
                                                duringRI, true);
                                                doPart3 = true;
                                            }
                                        } catch (RegionClearedException rce) {
                                            // Ignore. The exception will ensure that we do not update
                                            // the LRU List
                                            opCompleted = true;
                                            EntryLogger.logDestroy(event);
                                            owner.basicDestroyPart2(newRe, event, inTokenMode, true, /* conflict with clear */
                                            duringRI, true);
                                            doPart3 = true;
                                        } catch (ConcurrentCacheModificationException ccme) {
                                            VersionTag tag = event.getVersionTag();
                                            if (tag != null && tag.isTimeStampUpdated()) {
                                                // Notify gateways of new time-stamp.
                                                owner.notifyTimestampsToGateways(event);
                                            }
                                            throw ccme;
                                        }
                                    // Note no need for LRU work since the entry is destroyed
                                    // and will be removed when gii completes
                                    } finally {
                                        if (!opCompleted && !haveTombstone) /* to fix bug 51583 do this for all operations */
                                        {
                                            removeEntry(event.getKey(), newRe, false);
                                        }
                                        if (!opCompleted && isEviction) {
                                            removeEntry(event.getKey(), newRe, false);
                                        }
                                    }
                                }
                            // !opCompleted
                            }
                        // synchronized newRe
                        } finally {
                            if (oqlIndexManager != null) {
                                oqlIndexManager.countDownIndexUpdaters();
                            }
                        }
                    } else // inTokenMode or tombstone creation
                    {
                        if (!isEviction || owner.concurrencyChecksEnabled) {
                            // The following ensures that there is not a concurrent operation
                            // on the entry and leaves behind a tombstone if concurrencyChecksEnabled.
                            // It fixes bug #32467 by propagating the destroy to the server even though
                            // the entry isn't in the client
                            RegionEntry newRe = haveTombstone ? tombstone : getEntryFactory().createEntry(owner, event.getKey(), Token.REMOVED_PHASE1);
                            synchronized (newRe) {
                                if (haveTombstone && !tombstone.isTombstone()) {
                                    // we have to check this again under synchronization since it may have changed
                                    retry = true;
                                    // retryEntry = tombstone; // leave this in place for debugging
                                    continue;
                                }
                                re = (RegionEntry) _getMap().putIfAbsent(event.getKey(), newRe);
                                if (re != null && re != tombstone) {
                                    // concurrent change - try again
                                    retry = true;
                                    // retryEntry = tombstone; // leave this in place for debugging
                                    continue;
                                } else if (!isEviction) {
                                    boolean throwex = false;
                                    EntryNotFoundException ex = null;
                                    try {
                                        if (!cacheWrite) {
                                            throwex = true;
                                        } else {
                                            try {
                                                if (!removeRecoveredEntry) {
                                                    throwex = !owner.bridgeWriteBeforeDestroy(event, expectedOldValue);
                                                }
                                            } catch (EntryNotFoundException e) {
                                                throwex = true;
                                                ex = e;
                                            }
                                        }
                                        if (throwex) {
                                            if (!event.isOriginRemote() && !event.getOperation().isLocal() && (// if this is a replayed client
                                            event.isFromBridgeAndVersioned() || // version
                                            event.isFromWANAndVersioned())) {
                                                // in peers
                                                if (logger.isDebugEnabled()) {
                                                    logger.debug("ARM.destroy is allowing wan/client destroy of {} to continue", event.getKey());
                                                }
                                                throwex = false;
                                                event.setIsRedestroyedEntry(true);
                                                // distributing this destroy op.
                                                if (re == null) {
                                                    re = newRe;
                                                }
                                                doPart3 = true;
                                            }
                                        }
                                        if (throwex) {
                                            if (ex == null) {
                                                // Fix for 48182, check cache state and/or region state before sending
                                                // entry not found.
                                                // this is from the server and any exceptions will propogate to the client
                                                owner.checkEntryNotFound(event.getKey());
                                            } else {
                                                throw ex;
                                            }
                                        }
                                    } finally {
                                        // either remove the entry or leave a tombstone
                                        try {
                                            if (!event.isOriginRemote() && event.getVersionTag() != null && owner.concurrencyChecksEnabled) {
                                                // this shouldn't fail since we just created the entry.
                                                // it will either generate a tag or apply a server's version tag
                                                processVersionTag(newRe, event);
                                                if (doPart3) {
                                                    owner.generateAndSetVersionTag(event, newRe);
                                                }
                                                try {
                                                    owner.recordEvent(event);
                                                    newRe.makeTombstone(owner, event.getVersionTag());
                                                } catch (RegionClearedException e) {
                                                // that's okay - when writing a tombstone into a disk, the
                                                // region has been cleared (including this tombstone)
                                                }
                                                opCompleted = true;
                                            // lruEntryCreate(newRe);
                                            } else if (!haveTombstone) {
                                                try {
                                                    assert newRe != tombstone;
                                                    newRe.setValue(owner, Token.REMOVED_PHASE2);
                                                    removeEntry(event.getKey(), newRe, false);
                                                } catch (RegionClearedException e) {
                                                // that's okay - we just need to remove the new entry
                                                }
                                            } else if (event.getVersionTag() != null) {
                                                // haveTombstone - update the
                                                // tombstone version info
                                                processVersionTag(tombstone, event);
                                                if (doPart3) {
                                                    owner.generateAndSetVersionTag(event, newRe);
                                                }
                                                // version tag
                                                try {
                                                    tombstone.setValue(owner, Token.TOMBSTONE);
                                                } catch (RegionClearedException e) {
                                                // that's okay - when writing a tombstone into a disk, the
                                                // region has been cleared (including this tombstone)
                                                }
                                                owner.recordEvent(event);
                                                owner.rescheduleTombstone(tombstone, event.getVersionTag());
                                                owner.basicDestroyPart2(tombstone, event, inTokenMode, true, /* conflict with clear */
                                                duringRI, true);
                                                opCompleted = true;
                                            }
                                        } catch (ConcurrentCacheModificationException ccme) {
                                            VersionTag tag = event.getVersionTag();
                                            if (tag != null && tag.isTimeStampUpdated()) {
                                                // Notify gateways of new time-stamp.
                                                owner.notifyTimestampsToGateways(event);
                                            }
                                            throw ccme;
                                        }
                                    }
                                }
                            }
                        // synchronized(newRe)
                        }
                    }
                } else // no current entry
                {
                    // current entry exists
                    if (oqlIndexManager != null) {
                        oqlIndexManager.waitForIndexInit();
                    }
                    try {
                        synchronized (re) {
                            // if the entry is a tombstone and the event is from a peer or a client
                            // then we allow the operation to be performed so that we can update the
                            // version stamp. Otherwise we would retain an old version stamp and may allow
                            // an operation that is older than the destroy() to be applied to the cache
                            // Bug 45170: If removeRecoveredEntry, we treat tombstone as regular entry to be
                            // deleted
                            boolean createTombstoneForConflictChecks = (owner.concurrencyChecksEnabled && (event.isOriginRemote() || event.getContext() != null || removeRecoveredEntry));
                            if (!re.isRemoved() || createTombstoneForConflictChecks) {
                                if (re.isRemovedPhase2()) {
                                    _getMap().remove(event.getKey(), re);
                                    owner.getCachePerfStats().incRetries();
                                    retry = true;
                                    continue;
                                }
                                if (!event.isOriginRemote() && event.getOperation().isExpiration()) {
                                    // used by a tx.
                                    if (re.isInUseByTransaction()) {
                                        opCompleted = false;
                                        return opCompleted;
                                    }
                                }
                                event.setRegionEntry(re);
                                // See comment above about eviction checks
                                if (isEviction) {
                                    assert expectedOldValue == null;
                                    if (!confirmEvictionDestroy(re)) {
                                        opCompleted = false;
                                        return opCompleted;
                                    }
                                }
                                boolean removed = false;
                                try {
                                    opCompleted = destroyEntry(re, event, inTokenMode, cacheWrite, expectedOldValue, false, removeRecoveredEntry);
                                    if (opCompleted) {
                                        // It is very, very important for Partitioned Regions to keep
                                        // the entry in the map until after distribution occurs so that other
                                        // threads performing a create on this entry wait until the destroy
                                        // distribution is finished.
                                        // keeping backup copies consistent. Fix for bug 35906.
                                        // -- mthomas 07/02/2007 <-- how about that date, kinda cool eh?
                                        owner.basicDestroyBeforeRemoval(re, event);
                                        // do this before basicDestroyPart2 to fix bug 31786
                                        if (!inTokenMode) {
                                            if (re.getVersionStamp() == null) {
                                                re.removePhase2();
                                                removeEntry(event.getKey(), re, true, event, owner);
                                                removed = true;
                                            }
                                        }
                                        if (inTokenMode && !duringRI) {
                                            event.inhibitCacheListenerNotification(true);
                                        }
                                        doPart3 = true;
                                        owner.basicDestroyPart2(re, event, inTokenMode, false, /* conflict with clear */
                                        duringRI, true);
                                        // if (!re.isTombstone() || isEviction) {
                                        lruEntryDestroy(re);
                                    // } else {
                                    // lruEntryUpdate(re);
                                    // lruUpdateCallback = true;
                                    // }
                                    } else {
                                        if (!inTokenMode) {
                                            EntryLogger.logDestroy(event);
                                            owner.recordEvent(event);
                                            if (re.getVersionStamp() == null) {
                                                re.removePhase2();
                                                removeEntry(event.getKey(), re, true, event, owner);
                                                lruEntryDestroy(re);
                                            } else {
                                                if (re.isTombstone()) {
                                                    // again, so we need to reschedule the tombstone's expiration
                                                    if (event.isOriginRemote()) {
                                                        owner.rescheduleTombstone(re, re.getVersionStamp().asVersionTag());
                                                    }
                                                }
                                            }
                                            lruEntryDestroy(re);
                                            opCompleted = true;
                                        }
                                    }
                                } catch (RegionClearedException rce) {
                                    // Ignore. The exception will ensure that we do not update
                                    // the LRU List
                                    opCompleted = true;
                                    owner.recordEvent(event);
                                    if (inTokenMode && !duringRI) {
                                        event.inhibitCacheListenerNotification(true);
                                    }
                                    owner.basicDestroyPart2(re, event, inTokenMode, true, /* conflict with clear */
                                    duringRI, true);
                                    doPart3 = true;
                                } finally {
                                    if (re.isRemoved() && !re.isTombstone()) {
                                        if (!removed) {
                                            removeEntry(event.getKey(), re, true, event, owner);
                                        }
                                    }
                                }
                            } else // !isRemoved
                            {
                                // already removed
                                if (re.isTombstone() && event.getVersionTag() != null) {
                                    // if we're dealing with a tombstone and this is a remote event
                                    // (e.g., from cache client update thread) we need to update
                                    // the tombstone's version information
                                    // TODO use destroyEntry() here
                                    processVersionTag(re, event);
                                    try {
                                        re.makeTombstone(owner, event.getVersionTag());
                                    } catch (RegionClearedException e) {
                                    // that's okay - when writing a tombstone into a disk, the
                                    // region has been cleared (including this tombstone)
                                    }
                                }
                                if (expectedOldValue != null) {
                                    // if re is removed then there is no old value, so return false
                                    return false;
                                }
                                if (!inTokenMode && !isEviction) {
                                    owner.checkEntryNotFound(event.getKey());
                                }
                            }
                        }
                    // synchronized re
                    } catch (ConcurrentCacheModificationException ccme) {
                        VersionTag tag = event.getVersionTag();
                        if (tag != null && tag.isTimeStampUpdated()) {
                            // Notify gateways of new time-stamp.
                            owner.notifyTimestampsToGateways(event);
                        }
                        throw ccme;
                    } finally {
                        if (oqlIndexManager != null) {
                            oqlIndexManager.countDownIndexUpdaters();
                        }
                    }
                // No need to call lruUpdateCallback since the only lru action
                // we may have taken was lruEntryDestroy. This fixes bug 31759.
                }
                // current entry exists
                if (opCompleted) {
                    EntryLogger.logDestroy(event);
                }
                return opCompleted;
            } finally {
                try {
                    // do NOT distribute.
                    if (event.isConcurrencyConflict() && (event.getVersionTag() != null && event.getVersionTag().isGatewayTag())) {
                        doPart3 = false;
                    }
                    // distribution and listener notification
                    if (doPart3) {
                        owner.basicDestroyPart3(re, event, inTokenMode, duringRI, true, expectedOldValue);
                    }
                } finally {
                    if (opCompleted) {
                        if (re != null) {
                            // we only want to cancel if concurrency-check is not enabled
                            // re(regionentry) will be null when concurrency-check is enable and removeTombstone
                            // method
                            // will call cancelExpiryTask on regionEntry
                            owner.cancelExpiryTask(re);
                        }
                    }
                }
            }
        }
    // retry loop
    } finally {
        // failsafe on the read lock...see comment above
        releaseCacheModificationLock(owner, event);
    }
    return false;
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)

Example 12 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException 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 13 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class CacheClientUpdater method handleInvalidate.

/**
   * Invalidate an entry
   * 
   * @param clientMessage message describing the entry
   */
private void handleInvalidate(Message clientMessage) {
    String regionName = null;
    Object key = null;
    final boolean isDebugEnabled = logger.isDebugEnabled();
    try {
        this.isOpCompleted = false;
        // Retrieve the data from the local-invalidate message parts
        if (isDebugEnabled) {
            logger.debug("Received invalidate message of length ({} bytes)", clientMessage.getPayloadLength());
        }
        int partCnt = 0;
        Part regionNamePart = clientMessage.getPart(partCnt++);
        Part keyPart = clientMessage.getPart(partCnt++);
        Part callbackArgumentPart = clientMessage.getPart(partCnt++);
        VersionTag versionTag = (VersionTag) clientMessage.getPart(partCnt++).getObject();
        if (versionTag != null) {
            versionTag.replaceNullIDs((InternalDistributedMember) this.endpoint.getMemberId());
        }
        Part isInterestListPassedPart = clientMessage.getPart(partCnt++);
        Part hasCqsPart = clientMessage.getPart(partCnt++);
        regionName = regionNamePart.getString();
        key = keyPart.getStringOrObject();
        Object callbackArgument = callbackArgumentPart.getObject();
        boolean withInterest = (Boolean) isInterestListPassedPart.getObject();
        boolean withCQs = (Boolean) hasCqsPart.getObject();
        if (isDebugEnabled) {
            logger.debug("Invalidating entry for region: {} key: {} callbackArgument: {} withInterest={} withCQs={} version={}", regionName, key, callbackArgument, withInterest, withCQs, versionTag);
        }
        LocalRegion region = (LocalRegion) this.cacheHelper.getRegion(regionName);
        if (region == null) {
            if (isDebugEnabled && !quitting()) {
                logger.debug("Region named {} does not exist", regionName);
            }
        } else {
            if (region.hasServerProxy() && (withInterest || !withCQs)) {
                try {
                    Part eid = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
                    EventID eventId = (EventID) eid.getObject();
                    try {
                        region.basicBridgeClientInvalidate(eventId.getDistributedMember(), key, callbackArgument, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, eventId, versionTag);
                    } catch (ConcurrentCacheModificationException ignore) {
                    // allow CQs to be processed
                    }
                    this.isOpCompleted = true;
                    // fix for 36615
                    this.qManager.getState().incrementInvalidatedStats();
                    if (isDebugEnabled) {
                        logger.debug("Invalidated entry for region: {} key: {} callbackArgument: {}", regionName, key, callbackArgument);
                    }
                } catch (EntryNotFoundException ignore) {
                    if (isDebugEnabled && !quitting()) {
                        logger.debug("Already invalidated entry for region: {} key: {} callbackArgument: {}", regionName, key, callbackArgument);
                    }
                    this.isOpCompleted = true;
                }
            }
        }
        if (withCQs) {
            // The client may have been registered to receive invalidates for
            // create and updates operations. Get the actual region operation.
            Part regionOpType = clientMessage.getPart(partCnt++);
            Part numCqsPart = clientMessage.getPart(partCnt++);
            if (isDebugEnabled) {
                logger.debug("Received message has CQ Event. Number of cqs interested in the event : {}", numCqsPart.getInt() / 2);
            }
            partCnt = processCqs(clientMessage, partCnt, numCqsPart.getInt(), regionOpType.getInt(), key, null);
            this.isOpCompleted = true;
        }
    } catch (Exception e) {
        final String message = LocalizedStrings.CacheClientUpdater_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_ATTEMPTING_TO_INVALIDATE_ENTRY_REGION_0_KEY_1.toLocalizedString(regionName, key);
        handleException(message, e);
    }
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) EventID(org.apache.geode.internal.cache.EventID) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Endpoint(org.apache.geode.cache.client.internal.Endpoint) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) SSLException(javax.net.ssl.SSLException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Example 14 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class ParallelGatewaySenderQueue method destroyEventFromQueue.

private void destroyEventFromQueue(PartitionedRegion prQ, int bucketId, Object key) {
    boolean isPrimary = prQ.getRegionAdvisor().getBucketAdvisor(bucketId).isPrimary();
    BucketRegionQueue brq = getBucketRegionQueueByBucketId(prQ, bucketId);
    // before destroying a key from it
    try {
        if (brq != null) {
            brq.destroyKey(key);
        }
        stats.decQueueSize();
    } catch (EntryNotFoundException e) {
        if (!this.sender.isBatchConflationEnabled() && logger.isDebugEnabled()) {
            logger.debug("ParallelGatewaySenderQueue#remove: Got EntryNotFoundException while removing key {} for {} for bucket = {} for GatewaySender {}", key, this, bucketId, this.sender);
        }
    } catch (ForceReattemptException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Bucket :{} moved to other member", bucketId);
        }
    } catch (PrimaryBucketException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Primary bucket :{} moved to other member", bucketId);
        }
    } catch (RegionDestroyedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Caught RegionDestroyedException attempting to remove key {} from bucket {} in {}", key, bucketId, prQ.getFullPath());
        }
    }
    addRemovedEvent(prQ, bucketId, key);
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException)

Example 15 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class DeleteCommand method processBinaryCommand.

private ByteBuffer processBinaryCommand(RequestReader request, Cache cache) {
    ByteBuffer buffer = request.getRequest();
    ByteBuffer response = request.getResponse();
    KeyWrapper key = getKey(buffer, HEADER_LENGTH);
    Region<Object, ValueWrapper> r = getMemcachedRegion(cache);
    try {
        r.destroy(key);
        if (isQuiet()) {
            return null;
        }
        response.putShort(POSITION_RESPONSE_STATUS, ResponseStatus.NO_ERROR.asShort());
    } catch (EntryNotFoundException e) {
        response.putShort(POSITION_RESPONSE_STATUS, ResponseStatus.KEY_NOT_FOUND.asShort());
    } catch (Exception e) {
        response = handleBinaryException(key, request, response, "delete", e);
    }
    if (getLogger().fineEnabled()) {
        getLogger().fine("delete:key:" + key);
    }
    return response;
}
Also used : KeyWrapper(org.apache.geode.internal.memcached.KeyWrapper) ValueWrapper(org.apache.geode.internal.memcached.ValueWrapper) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ByteBuffer(java.nio.ByteBuffer) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException)

Aggregations

EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)78 Region (org.apache.geode.cache.Region)27 LocalRegion (org.apache.geode.internal.cache.LocalRegion)20 Test (org.junit.Test)18 CacheException (org.apache.geode.cache.CacheException)14 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)13 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)13 Released (org.apache.geode.internal.offheap.annotations.Released)12 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)10 StoredObject (org.apache.geode.internal.offheap.StoredObject)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 CacheWriterException (org.apache.geode.cache.CacheWriterException)8 Entry (org.apache.geode.cache.Region.Entry)8 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)8 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)8 Host (org.apache.geode.test.dunit.Host)8