Search in sources :

Example 26 with EntryDestroyedException

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

the class RegionTestCase method testDestroyEntry.

/**
   * Tests {@link Region#destroy destroying} an entry and attempting to access it afterwards.
   */
@Test
public void testDestroyEntry() throws CacheException {
    String name = this.getUniqueName();
    Object key = name;
    Object value = new Integer(42);
    Region region = createRegion(name);
    try {
        region.destroy(key);
        fail("Should have thrown an EntryNotFoundException");
    } catch (EntryNotFoundException ex) {
    // pass...
    }
    region.put(key, value);
    Region.Entry entry = region.getEntry(key);
    assertNotNull(entry);
    region.destroy(key);
    Region.Entry entry2 = region.getEntry(key);
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Found entry for destroyed key: " + entry2);
    assertNull(entry2);
    if (entry.isLocal()) {
        assertTrue(entry.isDestroyed());
    } else {
        assertFalse(entry.isDestroyed());
    }
    assertEquals(0, region.keySet().size());
    if (entry.isLocal()) {
        try {
            entry.getKey();
            fail("Should have thrown an EntryDestroyedException");
        } catch (EntryDestroyedException ex) {
        // pass...
        }
        try {
            entry.getRegion();
            fail("Should have thrown an EntryDestroyedException");
        } catch (EntryDestroyedException ex) {
        // pass...
        }
        try {
            entry.getStatistics();
            fail("Should have thrown an EntryDestroyedException");
        } catch (EntryDestroyedException ex) {
        // pass...
        }
        try {
            entry.getUserAttribute();
            fail("Should have thrown an EntryDestroyedException");
        } catch (EntryDestroyedException ex) {
        // pass...
        }
        try {
            entry.setUserAttribute("blah");
            fail("Should have thrown an EntryDestroyedException");
        } catch (EntryDestroyedException ex) {
        // pass...
        }
        try {
            entry.getValue();
            fail("Should have thrown an EntryDestroyedException");
        } catch (EntryDestroyedException ex) {
        // pass...
        }
    }
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) Entry(org.apache.geode.cache.Region.Entry) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 27 with EntryDestroyedException

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

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

the class LocalExporter method export.

@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options) throws IOException {
    LocalRegion local = RegionSnapshotServiceImpl.getLocalRegion(region);
    long count = 0;
    for (Entry<K, V> entry : region.entrySet()) {
        try {
            if (options.getFilter() == null || options.getFilter().accept(entry)) {
                sink.write(new SnapshotRecord(local, entry));
                count++;
            }
        } catch (EntryDestroyedException e) {
        // continue to next entry
        }
    }
    return count;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) SnapshotRecord(org.apache.geode.internal.cache.snapshot.SnapshotPacket.SnapshotRecord)

Aggregations

EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)28 Region (org.apache.geode.cache.Region)12 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)5 LRUEntry (org.apache.geode.internal.cache.lru.LRUEntry)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 DiskAccessException (org.apache.geode.cache.DiskAccessException)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Test (org.junit.Test)4 ByteBuf (io.netty.buffer.ByteBuf)3 Entry (java.util.Map.Entry)3 NoSuchElementException (java.util.NoSuchElementException)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 IOException (java.io.IOException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 RollbackException (javax.transaction.RollbackException)2