Search in sources :

Example 71 with EntryNotFoundException

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

the class LocalRegion method serverDestroy.

/**
   * Destroy an entry on the server given its event.
   * 
   * @since GemFire 5.7
   */
void serverDestroy(EntryEventImpl event, Object expectedOldValue) {
    if (event.getOperation().isDistributed()) {
        ServerRegionProxy mySRP = getServerProxy();
        if (mySRP != null) {
            // send to server
            Object key = event.getKey();
            Object callbackArg = event.getRawCallbackArgument();
            Object result = mySRP.destroy(key, expectedOldValue, event.getOperation(), event, callbackArg);
            if (result instanceof EntryNotFoundException) {
                throw (EntryNotFoundException) result;
            }
        }
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 72 with EntryNotFoundException

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

the class LocalRegion method serverPut.

/**
   * @since GemFire 5.7
   */
void serverPut(EntryEventImpl event, boolean requireOldValue, Object expectedOldValue) {
    if (event.getOperation().isDistributed() && !event.isFromServer()) {
        ServerRegionProxy mySRP = getServerProxy();
        if (mySRP != null) {
            if (event.isBulkOpInProgress()) {
                // this is a put all, ignore this!
                return;
            }
            Operation op = event.getOperation();
            // TODO: is the newEntry flag needed?
            Object key = event.getKey();
            Object value = event.getRawNewValue();
            // serverPut is called by cacheWriteBeforePut so the new value will not yet be off-heap
            Object callbackArg = event.getRawCallbackArgument();
            boolean isCreate = event.isCreate();
            Object result = mySRP.put(key, value, event.getDeltaBytes(), event, op, requireOldValue, expectedOldValue, callbackArg, isCreate);
            // bug #42296, serverProxy returns null when cache is closing
            getCancelCriterion().checkCancelInProgress(null);
            // to apply the operation and need to throw an exception
            if (op.guaranteesOldValue()) {
                if (op != Operation.REPLACE || requireOldValue) {
                    event.setConcurrentMapOldValue(result);
                }
                if (op == Operation.PUT_IF_ABSENT) {
                    if (result != null) {
                        // customers don't see this exception
                        throw new EntryNotFoundException("entry existed for putIfAbsent");
                    }
                } else if (op == Operation.REPLACE) {
                    if (requireOldValue && result == null) {
                        throw new EntryNotFoundException("entry not found for replace");
                    } else if (!requireOldValue) {
                        if (!(Boolean) result) {
                            // customers don't see this exception
                            throw new EntryNotFoundException("entry found with wrong value");
                        }
                    }
                }
            }
        }
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) StoredObject(org.apache.geode.internal.offheap.StoredObject) Operation(org.apache.geode.cache.Operation)

Example 73 with EntryNotFoundException

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

the class LocalRegion method createExpiryTask.

/**
   * If custom expiration returns non-null expiration attributes then create a CustomEntryExpiryTask
   * for this region and the given entry and return it. Otherwise if the region is configured for
   * expiration then create an EntryExpiryTask for this region and the given entry and return it.
   * Null is returned if the expiration attributes indicate that expiration is disabled.
   */
private EntryExpiryTask createExpiryTask(RegionEntry regionEntry) {
    if (regionEntry == null || regionEntry.isDestroyedOrRemoved()) {
        return null;
    }
    if (this.customEntryIdleTimeout != null || this.customEntryTimeToLive != null) {
        ExpiryRegionEntry expiryRegionEntry = new ExpiryRegionEntry(this, regionEntry);
        ExpirationAttributes ttlAttributes = null;
        ExpirationAttributes idleAttributes = null;
        final RegionAttributes<?, ?> regionAttributes = this.getAttributes();
        final CustomExpiry<?, ?> customTTL = regionAttributes.getCustomEntryTimeToLive();
        if (customTTL != null) {
            try {
                ttlAttributes = customTTL.getExpiry(expiryRegionEntry);
                if (ttlAttributes != null) {
                    this.checkEntryTimeoutAction("timeToLive", ttlAttributes.getAction());
                }
            } catch (RegionDestroyedException ignore) {
            // Ignore - #42273
            } catch (EntryNotFoundException ignore) {
            // Ignore - #51933
            } catch (EntryDestroyedException ignore) {
            // Ignore - #51933
            } catch (Exception e) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.EntryExpiryTask_ERROR_CALCULATING_EXPIRATION_0, e.getMessage()), e);
            }
        }
        if (ttlAttributes == null) {
            ttlAttributes = regionAttributes.getEntryTimeToLive();
        }
        CustomExpiry<?, ?> customIdle = regionAttributes.getCustomEntryIdleTimeout();
        if (customIdle != null) {
            try {
                idleAttributes = customIdle.getExpiry(expiryRegionEntry);
                if (idleAttributes != null) {
                    this.checkEntryTimeoutAction("idleTimeout", idleAttributes.getAction());
                }
            } catch (RegionDestroyedException ignore) {
            // Ignore - #42273
            } catch (EntryNotFoundException ignore) {
            // Ignore - #51933
            } catch (EntryDestroyedException ignore) {
            // Ignore - #51933
            } catch (Exception e) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.EntryExpiryTask_ERROR_CALCULATING_EXPIRATION_0, e.getMessage()), e);
            }
        }
        if (idleAttributes == null) {
            idleAttributes = regionAttributes.getEntryIdleTimeout();
        }
        final boolean ttlDisabled = ttlAttributes == null || ttlAttributes.getTimeout() == 0;
        final boolean idleDisabled = idleAttributes == null || idleAttributes.getTimeout() == 0;
        if (ttlDisabled && idleDisabled) {
            return null;
        } else if ((ttlDisabled || ttlAttributes.equals(regionAttributes.getEntryTimeToLive())) && (idleDisabled || idleAttributes.equals(regionAttributes.getEntryIdleTimeout()))) {
            // no need for custom since we can just use the region's expiration attributes.
            return new EntryExpiryTask(this, regionEntry);
        } else {
            return new CustomEntryExpiryTask(this, regionEntry, ttlAttributes, idleAttributes);
        }
    } else if (isEntryExpiryPossible()) {
        return new EntryExpiryTask(this, regionEntry);
    } else {
        return null;
    }
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException)

Example 74 with EntryNotFoundException

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

the class TXState method txWriteExistingEntry.

/**
   * Write an existing entry. This form takes an expectedOldValue which, if not null, must be equal
   * to the current value of the entry. If it is not, an EntryNotFoundException is thrown.
   * 
   * @param event
   * @param expectedOldValue
   * @return the tx entry object
   * @throws EntryNotFoundException
   */
private TXEntryState txWriteExistingEntry(final EntryEventImpl event, Object expectedOldValue) throws EntryNotFoundException {
    assert !event.isExpiration();
    final Object entryKey = event.getKey();
    final LocalRegion region = event.getRegion();
    final Operation op = event.getOperation();
    TXEntryState tx = txReadEntry(event.getKeyInfo(), region, true, expectedOldValue, true);
    assert tx != null;
    if (tx.existsLocally()) {
        final boolean invalidatingInvalidEntry = op.isInvalidate() && Token.isInvalid(tx.getValueInVM(entryKey));
        // Ignore invalidating an invalid entry
        if (!invalidatingInvalidEntry) {
            tx.updateForWrite(nextModSerialNum());
        }
    } else if (region.isProxy() && !op.isLocal() && !tx.hasOp()) {
        // Distributed operations on proxy regions need to be done
        // even if the entry does not exist locally.
        // But only if we don't already have a tx operation (once we have an op
        // then we honor tx.existsLocally since the tx has storage unlike the proxy).
        // We must not throw EntryNotFoundException in this case
        tx.updateForWrite(nextModSerialNum());
    } else {
        throw new EntryNotFoundException(entryKey.toString());
    }
    return tx;
}
Also used : EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ServerRegionOperation(org.apache.geode.internal.cache.tx.TransactionalOperation.ServerRegionOperation) Operation(org.apache.geode.cache.Operation)

Example 75 with EntryNotFoundException

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

the class TXState method getEntryOnRemote.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.InternalDataView#getEntryOnRemote(java.lang.Object,
   * org.apache.geode.internal.cache.LocalRegion)
   */
public Entry getEntryOnRemote(KeyInfo key, LocalRegion localRegion, boolean allowTombstones) throws DataLocationException {
    PartitionedRegion pr = (PartitionedRegion) localRegion;
    Region.Entry txval = getEntry(key, pr, allowTombstones);
    if (txval == null) {
        throw new EntryNotFoundException(LocalizedStrings.PartitionedRegionDataStore_ENTRY_NOT_FOUND.toLocalizedString());
    } else {
        NonLocalRegionEntry nlre = new NonLocalRegionEntry(txval, localRegion);
        LocalRegion dataReg = localRegion.getDataRegionForRead(key);
        return new EntrySnapshot(nlre, dataReg, (LocalRegion) txval.getRegion(), allowTombstones);
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region)

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