Search in sources :

Example 36 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 37 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 38 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)

Example 39 with EntryNotFoundException

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

the class SerialGatewaySenderQueue method optimalGet.

/**
   * Does a get that gets the value without fault values in from disk.
   */
private AsyncEvent optimalGet(Long k) {
    // Get the object at that key (to remove the index).
    LocalRegion lr = (LocalRegion) this.region;
    Object o = null;
    try {
        o = lr.getValueInVMOrDiskWithoutFaultIn(k);
        if (o != null && o instanceof CachedDeserializable) {
            o = ((CachedDeserializable) o).getDeserializedValue(lr, lr.getRegionEntry(k));
        }
    } catch (EntryNotFoundException ok) {
    // just return null;
    }
    // bug #46023 do not return a destroyed entry marker
    if (o == Token.TOMBSTONE) {
        o = null;
    }
    return (AsyncEvent) o;
}
Also used : CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent)

Example 40 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)

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