Search in sources :

Example 21 with CustomEntryConcurrentHashMap

use of org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap in project geode by apache.

the class AbstractRegionMap method copyRecoveredEntries.

public void copyRecoveredEntries(RegionMap rm) {
    // We need to sort the tombstones before scheduling them,
    // so that they will be in the correct order.
    OrderedTombstoneMap<RegionEntry> tombstones = new OrderedTombstoneMap<RegionEntry>();
    if (rm != null) {
        CustomEntryConcurrentHashMap<Object, Object> other = ((AbstractRegionMap) rm)._getMap();
        Iterator<Map.Entry<Object, Object>> it = other.entrySetWithReusableEntries().iterator();
        while (it.hasNext()) {
            Map.Entry<Object, Object> me = it.next();
            // This removes the RegionEntry from "rm" but it does not decrement its
            it.remove();
            // refcount to an offheap value.
            RegionEntry oldRe = (RegionEntry) me.getValue();
            Object key = me.getKey();
            @Retained @Released Object value = oldRe._getValueRetain((RegionEntryContext) ((AbstractRegionMap) rm)._getOwnerObject(), true);
            try {
                if (value == Token.NOT_AVAILABLE) {
                    // fix for bug 43993
                    value = null;
                }
                if (value == Token.TOMBSTONE && !_getOwner().getConcurrencyChecksEnabled()) {
                    continue;
                }
                RegionEntry newRe = getEntryFactory().createEntry((RegionEntryContext) _getOwnerObject(), key, value);
                // TODO: passing value to createEntry causes a problem with the disk stats.
                // The disk stats have already been set to track oldRe.
                // So when we call createEntry we probably want to give it REMOVED_PHASE1
                // and then set the value in copyRecoveredEntry it a way that does not
                // change the disk stats. This also depends on DiskEntry.Helper.initialize not changing
                // the stats for REMOVED_PHASE1
                copyRecoveredEntry(oldRe, newRe);
                // newRe is now in this._getMap().
                if (newRe.isTombstone()) {
                    VersionTag tag = newRe.getVersionStamp().asVersionTag();
                    tombstones.put(tag, newRe);
                } else {
                    _getOwner().updateSizeOnCreate(key, _getOwner().calculateRegionEntryValueSize(newRe));
                }
                incEntryCount(1);
                lruEntryUpdate(newRe);
            } finally {
                OffHeapHelper.release(value);
                if (oldRe instanceof OffHeapRegionEntry) {
                    ((OffHeapRegionEntry) oldRe).release();
                }
            }
            lruUpdateCallback();
        }
    } else {
        for (Iterator<RegionEntry> iter = regionEntries().iterator(); iter.hasNext(); ) {
            RegionEntry re = iter.next();
            if (re.isTombstone()) {
                if (re.getVersionStamp() == null) {
                    // bug #50992 - recovery from versioned to
                    // non-versioned
                    iter.remove();
                    continue;
                } else {
                    tombstones.put(re.getVersionStamp().asVersionTag(), re);
                }
            } else {
                _getOwner().updateSizeOnCreate(re.getKey(), _getOwner().calculateRegionEntryValueSize(re));
            }
        }
        incEntryCount(size());
        // Since lru was not being done during recovery call it now.
        lruUpdateCallback();
    }
    // Schedule all of the tombstones, now that we have sorted them
    Map.Entry<VersionTag, RegionEntry> entry;
    while ((entry = tombstones.take()) != null) {
        // refresh the tombstone so it doesn't time out too soon
        _getOwner().scheduleTombstone(entry.getValue(), entry.getKey());
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) LRUEntry(org.apache.geode.internal.cache.lru.LRUEntry) Retained(org.apache.geode.internal.offheap.annotations.Retained) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) StoredObject(org.apache.geode.internal.offheap.StoredObject) Map(java.util.Map) CustomEntryConcurrentHashMap(org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap)

Example 22 with CustomEntryConcurrentHashMap

use of org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap in project geode by apache.

the class ConcurrentHashMapJUnitTest method testPutIfAbsent2_NullPointerException.

/**
   * putIfAbsent(x, null) throws NPE
   */
@Test
public void testPutIfAbsent2_NullPointerException() {
    try {
        CustomEntryConcurrentHashMap c = new CustomEntryConcurrentHashMap(5);
        c.putIfAbsent("whatever", null);
        shouldThrow();
    } catch (NullPointerException e) {
    }
}
Also used : CustomEntryConcurrentHashMap(org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 23 with CustomEntryConcurrentHashMap

use of org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap in project geode by apache.

the class ConcurrentHashMapJUnitTest method testValues.

/**
   * values collection contains all values
   */
@Test
public void testValues() {
    CustomEntryConcurrentHashMap map = map5();
    Collection s = map.values();
    assertEquals(5, s.size());
    assertTrue(s.contains("A"));
    assertTrue(s.contains("B"));
    assertTrue(s.contains("C"));
    assertTrue(s.contains("D"));
    assertTrue(s.contains("E"));
}
Also used : Collection(java.util.Collection) CustomEntryConcurrentHashMap(org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 24 with CustomEntryConcurrentHashMap

use of org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap in project geode by apache.

the class ConcurrentHashMapJUnitTest method testRemove1_NullPointerException.

/**
   * remove(null) throws NPE
   */
@Test
public void testRemove1_NullPointerException() {
    try {
        CustomEntryConcurrentHashMap c = new CustomEntryConcurrentHashMap(5);
        c.put("sadsdf", "asdads");
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException e) {
    }
}
Also used : CustomEntryConcurrentHashMap(org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 25 with CustomEntryConcurrentHashMap

use of org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap in project geode by apache.

the class ConcurrentHashMapJUnitTest method testReplace_NullPointerException.

/**
   * replace(null, x) throws NPE
   */
@Test
public void testReplace_NullPointerException() {
    try {
        CustomEntryConcurrentHashMap c = new CustomEntryConcurrentHashMap(5);
        c.replace(null, "whatever");
        shouldThrow();
    } catch (NullPointerException e) {
    }
}
Also used : CustomEntryConcurrentHashMap(org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CustomEntryConcurrentHashMap (org.apache.geode.internal.util.concurrent.CustomEntryConcurrentHashMap)46 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)44 Test (org.junit.Test)44 Set (java.util.Set)4 Map (java.util.Map)3 Collection (java.util.Collection)2 Enumeration (java.util.Enumeration)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LRUEntry (org.apache.geode.internal.cache.lru.LRUEntry)1 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)1 StoredObject (org.apache.geode.internal.offheap.StoredObject)1 Released (org.apache.geode.internal.offheap.annotations.Released)1 Retained (org.apache.geode.internal.offheap.annotations.Retained)1