Search in sources :

Example 21 with EntryNotFoundException

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

the class LocalRegion method localDestroyNoCallbacks.

/**
   * WARNING: this method is overridden in subclasses.
   */
protected void localDestroyNoCallbacks(Object key) {
    if (logger.isDebugEnabled()) {
        logger.debug("localDestroyNoCallbacks key={}", key);
    }
    checkReadiness();
    validateKey(key);
    @Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_DESTROY, key, false, getMyId(), false, /* generateCallbacks */
    true);
    try {
        // expectedOldValue
        basicDestroy(event, false, null);
    } catch (CacheWriterException e) {
        // cache writer not called
        throw new Error(LocalizedStrings.LocalRegion_CACHE_WRITER_SHOULD_NOT_HAVE_BEEN_CALLED_FOR_LOCALDESTROY.toLocalizedString(), e);
    } catch (TimeoutException e) {
        // no distributed lock
        throw new Error(LocalizedStrings.LocalRegion_NO_DISTRIBUTED_LOCK_SHOULD_HAVE_BEEN_ATTEMPTED_FOR_LOCALDESTROY.toLocalizedString(), e);
    } catch (EntryNotFoundException ignore) {
    // not a problem
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireError(org.apache.geode.InternalGemFireError) CacheWriterException(org.apache.geode.cache.CacheWriterException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 22 with EntryNotFoundException

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

the class RemoteInvalidateMessage method operateOnRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   * 
   * @throws EntryExistsException
   */
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    final Object key = getKey();
    @Released final EntryEventImpl event = EntryEventImpl.create(r, getOperation(), key, null, /* newValue */
    getCallbackArg(), this.useOriginRemote, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.bridgeContext != null) {
            event.setContext(this.bridgeContext);
        }
        event.setCausedByMessage(this);
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        Assert.assertTrue(eventId != null);
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.possibleDuplicate);
        // for cqs, which needs old value based on old value being sent on wire.
        boolean eventShouldHaveOldValue = getHasOldValue();
        if (eventShouldHaveOldValue) {
            if (getOldValueIsSerialized()) {
                event.setSerializedOldValue(getOldValueBytes());
            } else {
                event.setOldValue(getOldValueBytes());
            }
        }
        boolean sendReply = true;
        try {
            r.checkReadiness();
            r.checkForLimitedOrNoAccess();
            r.basicInvalidate(event);
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "remoteInvalidated key: {}", key);
            }
            sendReply(getSender(), this.processorId, dm, /* ex */
            null, event.getRegion(), event.getVersionTag(), startTime);
            sendReply = false;
        } catch (EntryNotFoundException eee) {
            // failed = true;
            if (logger.isDebugEnabled()) {
                logger.debug("operateOnRegion caught EntryNotFoundException");
            }
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(eee), r, null, startTime);
            // this prevents us from acking later
            sendReply = false;
        } catch (PrimaryBucketException pbe) {
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
            return false;
        }
        return sendReply;
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 23 with EntryNotFoundException

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

the class RemoteDestroyMessage method distribute.

public static boolean distribute(EntryEventImpl event, Object expectedOldValue, boolean onlyPersistent) {
    boolean successful = false;
    DistributedRegion r = (DistributedRegion) event.getRegion();
    Collection replicates = onlyPersistent ? r.getCacheDistributionAdvisor().adviseInitializedPersistentMembers().keySet() : r.getCacheDistributionAdvisor().adviseInitializedReplicates();
    if (replicates.isEmpty()) {
        return false;
    }
    if (replicates.size() > 1) {
        ArrayList l = new ArrayList(replicates);
        Collections.shuffle(l);
        replicates = l;
    }
    int attempts = 0;
    for (Iterator<InternalDistributedMember> it = replicates.iterator(); it.hasNext(); ) {
        InternalDistributedMember replicate = it.next();
        try {
            attempts++;
            final boolean posDup = (attempts > 1);
            RemoteDestroyReplyProcessor processor = send(replicate, event.getRegion(), event, expectedOldValue, DistributionManager.SERIAL_EXECUTOR, false, posDup);
            processor.waitForCacheException();
            VersionTag versionTag = processor.getVersionTag();
            if (versionTag != null) {
                event.setVersionTag(versionTag);
                if (event.getRegion().getVersionVector() != null) {
                    event.getRegion().getVersionVector().recordVersion(versionTag.getMemberID(), versionTag);
                }
            }
            event.setInhibitDistribution(true);
            return true;
        } catch (EntryNotFoundException e) {
            throw new EntryNotFoundException("" + event.getKey());
        } catch (TransactionDataNotColocatedException enfe) {
            throw enfe;
        } catch (CancelException e) {
            event.getRegion().getCancelCriterion().checkCancelInProgress(e);
        } catch (CacheException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("RemoteDestroyMessage caught CacheException during distribution", e);
            }
            // not a cancel-exception, so don't complain any more about it
            successful = true;
        } catch (RemoteOperationException e) {
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "RemoteDestroyMessage caught an unexpected exception during distribution", e);
            }
        }
    }
    return successful;
}
Also used : CacheException(org.apache.geode.cache.CacheException) ArrayList(java.util.ArrayList) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Collection(java.util.Collection) CancelException(org.apache.geode.CancelException)

Example 24 with EntryNotFoundException

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

the class RemoteDestroyMessage method operateOnRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released EntryEventImpl event = null;
    try {
        if (this.bridgeContext != null) {
            event = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
            getCallbackArg(), false, /* originRemote */
            eventSender, true);
            event.setContext(this.bridgeContext);
            // for cq processing and client notification by BS.
            if (this.hasOldValue) {
                if (this.oldValueIsSerialized) {
                    event.setSerializedOldValue(getOldValueBytes());
                } else {
                    event.setOldValue(getOldValueBytes());
                }
            }
        } else // bridgeContext != null
        {
            event = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
            getCallbackArg(), this.useOriginRemote, eventSender, true, /* generateCallbacks */
            false);
        }
        event.setCausedByMessage(this);
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        // for cq processing and client notification by BS.
        if (this.hasOldValue) {
            if (this.oldValueIsSerialized) {
                event.setSerializedOldValue(getOldValueBytes());
            } else {
                event.setOldValue(getOldValueBytes());
            }
        }
        Assert.assertTrue(eventId != null);
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.possibleDuplicate);
        try {
            r.getDataView().destroyOnRemote(event, true, this.expectedOldValue);
            sendReply(dm, event.getVersionTag());
        } catch (CacheWriterException cwe) {
            sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
            return false;
        } catch (EntryNotFoundException eee) {
            if (logger.isDebugEnabled()) {
                logger.debug("operateOnRegion caught EntryNotFoundException", eee);
            }
            ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
        } catch (DataLocationException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("operateOnRegion caught DataLocationException");
            }
            ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(e), getReplySender(dm), r.isInternalRegion());
        }
        return false;
    } finally {
        if (event != null) {
            event.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 25 with EntryNotFoundException

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

the class CacheClientUpdater method handleDestroy.

/**
   * locally destroy an entry
   * 
   * @param clientMessage message describing the entry
   */
private void handleDestroy(Message clientMessage) {
    String regionName = null;
    Object key = null;
    final boolean isDebugEnabled = logger.isDebugEnabled();
    try {
        this.isOpCompleted = false;
        // Retrieve the data from the local-destroy message parts
        if (isDebugEnabled) {
            logger.debug("Received destroy 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());
        }
        regionName = regionNamePart.getString();
        key = keyPart.getStringOrObject();
        Part isInterestListPassedPart = clientMessage.getPart(partCnt++);
        Part hasCqsPart = clientMessage.getPart(partCnt++);
        boolean withInterest = ((Boolean) isInterestListPassedPart.getObject()).booleanValue();
        boolean withCQs = ((Boolean) hasCqsPart.getObject()).booleanValue();
        Object callbackArgument = callbackArgumentPart.getObject();
        if (isDebugEnabled) {
            logger.debug("Destroying 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)) {
            EventID eventId = null;
            try {
                Part eid = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
                eventId = (EventID) eid.getObject();
                try {
                    region.basicBridgeClientDestroy(eventId.getDistributedMember(), key, callbackArgument, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, eventId, versionTag);
                } catch (ConcurrentCacheModificationException ignore) {
                // allow CQs to be processed
                }
                this.isOpCompleted = true;
                if (isDebugEnabled) {
                    logger.debug("Destroyed entry for region: {} key: {} callbackArgument: {}", regionName, key, callbackArgument);
                }
            } catch (EntryNotFoundException ignore) {
                if (isDebugEnabled && !quitting()) {
                    logger.debug("Already destroyed entry for region: {} key: {} callbackArgument: {} eventId={}", regionName, key, callbackArgument, eventId.expensiveToString());
                }
                this.isOpCompleted = true;
            }
        }
        if (withCQs) {
            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(), clientMessage.getMessageType(), key, null);
            this.isOpCompleted = true;
        }
    } catch (Exception e) {
        String message = LocalizedStrings.CacheClientUpdater_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_ATTEMPTING_TO_DESTROY_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)

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