Search in sources :

Example 11 with EntryDestroyedException

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

the class RegionTestCase method testLocalDestroyEntry.

/**
   * Tests {@link Region#localDestroy locally destroying} an entry and attempting to access it
   * afterwards. (Not too useful with a <code>LOCAL</code> region.)
   */
@Test
public void testLocalDestroyEntry() throws CacheException {
    if (!supportsLocalDestroyAndLocalInvalidate()) {
        return;
    }
    String name = this.getUniqueName();
    Object key = name;
    Object value = new Integer(42);
    Region region = createRegion(name);
    boolean isMirrored = getRegionAttributes().getMirrorType().isMirrored();
    try {
        region.localDestroy(key);
        if (isMirrored)
            fail("Should have thrown an IllegalStateException");
        fail("Should have thrown an EntryNotFoundException");
    } catch (EntryNotFoundException ex) {
    // pass...
    } catch (IllegalStateException ex) {
        if (!isMirrored)
            throw ex;
        else
            // abort test
            return;
    }
    region.put(key, value);
    Region.Entry entry = region.getEntry(key);
    assertNotNull(entry);
    region.localDestroy(key);
    assertNull(region.getEntry(key));
    assertTrue(entry.isDestroyed());
    assertEquals(0, region.keySet().size());
    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 12 with EntryDestroyedException

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

the class LuceneEventListener method getValue.

private Object getValue(Region.Entry entry) {
    final EntrySnapshot es = (EntrySnapshot) entry;
    Object value;
    try {
        value = es == null ? null : es.getRawValue(true);
    } catch (EntryDestroyedException e) {
        value = null;
    }
    return value;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 13 with EntryDestroyedException

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

the class CompactRangeIndex method getSizeEstimate.

public int getSizeEstimate(Object key, int operator, int matchLevel) throws TypeMismatchException {
    // Get approx size;
    int size = 0;
    if (key == null) {
        key = IndexManager.NULL;
    }
    long start = updateIndexUseStats(false);
    try {
        switch(operator) {
            case OQLLexerTokenTypes.TOK_EQ:
                {
                    key = TypeUtils.indexKeyFor(key);
                    key = getPdxStringForIndexedPdxKeys(key);
                    size = indexStore.size(key);
                    break;
                }
            case OQLLexerTokenTypes.TOK_NE_ALT:
            case OQLLexerTokenTypes.TOK_NE:
                size = this.region.size();
                key = TypeUtils.indexKeyFor(key);
                key = getPdxStringForIndexedPdxKeys(key);
                size -= indexStore.size(key);
                break;
            case OQLLexerTokenTypes.TOK_LE:
            case OQLLexerTokenTypes.TOK_LT:
                if (matchLevel <= 0 && (key instanceof Number)) {
                    int totalSize = indexStore.size();
                    if (CompactRangeIndex.testHook != null) {
                        CompactRangeIndex.testHook.hook(1);
                    }
                    if (totalSize > 1) {
                        Number keyAsNum = (Number) key;
                        int x = 0;
                        IndexStoreEntry firstEntry = null;
                        CloseableIterator<IndexStoreEntry> iter1 = null;
                        CloseableIterator<IndexStoreEntry> iter2 = null;
                        try {
                            iter1 = indexStore.iterator(null);
                            if (iter1.hasNext()) {
                                firstEntry = iter1.next();
                                IndexStoreEntry lastEntry = null;
                                iter2 = indexStore.descendingIterator(null);
                                if (iter2.hasNext()) {
                                    lastEntry = iter2.next();
                                }
                                if (firstEntry != null && lastEntry != null) {
                                    Number first = (Number) firstEntry.getDeserializedKey();
                                    Number last = (Number) lastEntry.getDeserializedKey();
                                    if (first.doubleValue() != last.doubleValue()) {
                                        // Shobhit: Now without ReadLoack on index we can end up with 0
                                        // in denominator if the numbers are floating-point and
                                        // truncated with conversion to long, and the first and last
                                        // truncate to the same long, so safest calculation is to
                                        // convert to doubles.
                                        x = (int) (((keyAsNum.doubleValue() - first.doubleValue()) * totalSize) / (last.doubleValue() - first.doubleValue()));
                                    }
                                }
                                if (x < 0) {
                                    x = 0;
                                }
                                size = x;
                            }
                        } finally {
                            if (iter1 != null) {
                                iter1.close();
                            }
                            if (iter2 != null) {
                                iter1.close();
                            }
                        }
                    } else {
                        // not attempting to differentiate between LT & LE
                        size = indexStore.size(key) > 0 ? 1 : 0;
                    }
                } else {
                    size = Integer.MAX_VALUE;
                }
                break;
            case OQLLexerTokenTypes.TOK_GE:
            case OQLLexerTokenTypes.TOK_GT:
                if (matchLevel <= 0 && (key instanceof Number)) {
                    int totalSize = indexStore.size();
                    if (CompactRangeIndex.testHook != null) {
                        CompactRangeIndex.testHook.hook(2);
                    }
                    if (totalSize > 1) {
                        Number keyAsNum = (Number) key;
                        int x = 0;
                        IndexStoreEntry firstEntry = null;
                        CloseableIterator<IndexStoreEntry> iter1 = null;
                        CloseableIterator<IndexStoreEntry> iter2 = null;
                        try {
                            iter1 = indexStore.iterator(null);
                            if (iter1.hasNext()) {
                                firstEntry = iter1.next();
                            }
                            IndexStoreEntry lastEntry = null;
                            iter2 = indexStore.descendingIterator(null);
                            if (iter2.hasNext()) {
                                lastEntry = iter2.next();
                            }
                            if (firstEntry != null && lastEntry != null) {
                                Number first = (Number) firstEntry.getDeserializedKey();
                                Number last = (Number) lastEntry.getDeserializedKey();
                                if (first.doubleValue() != last.doubleValue()) {
                                    // Shobhit: Now without ReadLoack on index we can end up with 0
                                    // in denominator if the numbers are floating-point and
                                    // truncated with conversion to long, and the first and last
                                    // truncate to the same long, so safest calculation is to
                                    // convert to doubles.
                                    x = (int) (((last.doubleValue() - keyAsNum.doubleValue()) * totalSize) / (last.doubleValue() - first.doubleValue()));
                                }
                            }
                            if (x < 0) {
                                x = 0;
                            }
                            size = x;
                        } finally {
                            if (iter1 != null) {
                                iter1.close();
                            }
                        }
                    } else {
                        // not attempting to differentiate between GT & GE
                        size = indexStore.size(key) > 0 ? 1 : 0;
                    }
                } else {
                    size = Integer.MAX_VALUE;
                }
                break;
        }
    } catch (EntryDestroyedException ignore) {
        return Integer.MAX_VALUE;
    } finally {
        updateIndexUseEndStats(start, false);
    }
    return size;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) MemoryIndexStoreEntry(org.apache.geode.cache.query.internal.index.MemoryIndexStore.MemoryIndexStoreEntry) IndexStoreEntry(org.apache.geode.cache.query.internal.index.IndexStore.IndexStoreEntry)

Example 14 with EntryDestroyedException

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

the class ColocationHelper method checkMembersColocation.

/**
   * An utility to make sure that a member contains all of the partitioned regions that are
   * colocated with a given region on other members. TODO rebalance - this is rather inefficient,
   * and probably all this junk should be in the advisor.
   */
public static boolean checkMembersColocation(PartitionedRegion partitionedRegion, InternalDistributedMember member) {
    List<PartitionRegionConfig> colocatedRegions = new ArrayList<PartitionRegionConfig>();
    List<PartitionRegionConfig> tempcolocatedRegions = new ArrayList<PartitionRegionConfig>();
    Region prRoot = PartitionedRegionHelper.getPRRoot(partitionedRegion.getCache());
    PartitionRegionConfig regionConfig = (PartitionRegionConfig) prRoot.get(partitionedRegion.getRegionIdentifier());
    // The region was probably concurrently destroyed
    if (regionConfig == null) {
        return false;
    }
    tempcolocatedRegions.add(regionConfig);
    colocatedRegions.addAll(tempcolocatedRegions);
    PartitionRegionConfig prConf = null;
    do {
        PartitionRegionConfig tempToBeColocatedWith = tempcolocatedRegions.remove(0);
        for (Iterator itr = prRoot.keySet().iterator(); itr.hasNext(); ) {
            String prName = (String) itr.next();
            try {
                prConf = (PartitionRegionConfig) prRoot.get(prName);
            } catch (EntryDestroyedException ignore) {
                continue;
            }
            if (prConf == null) {
                // merge so I added this check and continue
                continue;
            }
            if (prConf.getColocatedWith() != null) {
                if (prConf.getColocatedWith().equals(tempToBeColocatedWith.getFullPath()) || (Region.SEPARATOR + prConf.getColocatedWith()).equals(tempToBeColocatedWith.getFullPath())) {
                    colocatedRegions.add(prConf);
                    tempcolocatedRegions.add(prConf);
                }
            }
        }
    } while (!tempcolocatedRegions.isEmpty());
    PartitionRegionConfig tempColocatedWith = regionConfig;
    prConf = null;
    while (true) {
        String colocatedWithRegionName = tempColocatedWith.getColocatedWith();
        if (colocatedWithRegionName == null)
            break;
        else {
            prConf = (PartitionRegionConfig) prRoot.get(getRegionIdentifier(colocatedWithRegionName));
            if (prConf == null) {
                break;
            }
            colocatedRegions.add(tempColocatedWith);
            tempColocatedWith = prConf;
        }
    }
    // We don't need a hostname because the equals method doesn't check it.
    for (PartitionRegionConfig config : colocatedRegions) {
        if (config.isColocationComplete() && !config.containsMember(member)) {
            return false;
        }
    }
    // with this region have been created.
    if (hasOfflineColocatedChildRegions(partitionedRegion)) {
        return false;
    }
    return true;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Example 15 with EntryDestroyedException

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

the class ColocationHelper method getColocatedChildRegions.

/**
   * A utility method to retrieve all child partitioned regions that are directly colocated to the
   * specified partitioned region.<br>
   * <p>
   * For example, shipmentPR is colocated with orderPR and orderPR is colocated with customerPR.
   * <br>
   * getColocatedChildRegions(customerPR) will return List{orderPR}<br>
   * getColocatedChildRegions(orderPR) will return List{shipmentPR}<br>
   * getColocatedChildRegions(shipmentPR) will return empty List{}<br>
   * 
   * @return list of all child partitioned regions colocated with the region
   * @since GemFire 5.8Beta
   */
public static List<PartitionedRegion> getColocatedChildRegions(PartitionedRegion partitionedRegion) {
    List<PartitionedRegion> colocatedChildRegions = new ArrayList<PartitionedRegion>();
    Region prRoot = PartitionedRegionHelper.getPRRoot(partitionedRegion.getCache());
    PartitionRegionConfig prConf = null;
    // final List allPRNamesList = new ArrayList(prRoot.keySet());
    Iterator itr = prRoot.keySet().iterator();
    while (itr.hasNext()) {
        try {
            String prName = (String) itr.next();
            if (prName.equals(partitionedRegion.getRegionIdentifier())) {
                // region can't be a child of itself
                continue;
            }
            try {
                prConf = (PartitionRegionConfig) prRoot.get(prName);
            } catch (EntryDestroyedException ignore) {
                continue;
            }
            if (prConf == null) {
                // merge so I added this check and continue
                continue;
            }
            int prID = prConf.getPRId();
            PartitionedRegion prRegion = PartitionedRegion.getPRFromId(prID);
            if (prRegion != null) {
                if (prRegion.getColocatedWith() != null) {
                    if (prRegion.getColocatedWith().equals(partitionedRegion.getFullPath()) || ("/" + prRegion.getColocatedWith()).equals(partitionedRegion.getFullPath())) {
                        // only regions directly colocatedWith partitionedRegion are
                        // added to the list...
                        prRegion.waitOnBucketMetadataInitialization();
                        colocatedChildRegions.add(prRegion);
                    }
                }
            }
        } catch (PRLocallyDestroyedException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("PRLocallyDestroyedException : Region ={} is locally destroyed on this node", prConf.getPRId(), e);
            }
        } catch (RegionDestroyedException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("RegionDestroyedException : Region ={} is destroyed.", prConf.getPRId(), e);
            }
        }
    }
    // Fix for 44484 - Make the list of colocated child regions
    // is always in the same order on all nodes.
    Collections.sort(colocatedChildRegions, new Comparator<PartitionedRegion>() {

        @Override
        public int compare(PartitionedRegion o1, PartitionedRegion o2) {
            if (o1.isShadowPR() == o2.isShadowPR()) {
                return o1.getFullPath().compareTo(o2.getFullPath());
            }
            if (o1.isShadowPR()) {
                return 1;
            }
            return -1;
        }
    });
    return colocatedChildRegions;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) Region(org.apache.geode.cache.Region)

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