Search in sources :

Example 1 with DiskRegion

use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.

the class MemberMBeanBridge method addRegion.

public void addRegion(Region region) {
    if (region.getAttributes().getPartitionAttributes() != null) {
        addPartionRegionStats(((PartitionedRegion) region).getPrStats());
    }
    LocalRegion l = (LocalRegion) region;
    if (l.getEvictionController() != null) {
        LRUStatistics stats = l.getEvictionController().getLRUHelper().getStats();
        if (stats != null) {
            addLRUStats(stats);
        }
    }
    DiskRegion dr = l.getDiskRegion();
    if (dr != null) {
        for (DirectoryHolder dh : dr.getDirectories()) {
            addDirectoryStats(dh.getDiskDirectoryStats());
        }
    }
}
Also used : DiskRegion(org.apache.geode.internal.cache.DiskRegion) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DirectoryHolder(org.apache.geode.internal.cache.DirectoryHolder)

Example 2 with DiskRegion

use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.

@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect the DS before sending a prepare message
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        getSystem().disconnect();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    try {
        createPersistentRegion(vm1);
    } catch (Exception e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    closeRegion(vm0);
    // This wait for VM0 to come back
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    waitForBlockedInitialization(vm1);
    createPersistentRegion(vm0);
    async1.getResult();
    checkForEntry(vm1);
    vm0.invoke(new SerializableRunnable("check for offline members") {

        public void run() {
            Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
            PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
            DiskRegion dr = region.getDiskRegion();
            assertEquals(Collections.emptySet(), dr.getOfflineMembers());
            assertEquals(1, dr.getOnlineMembers().size());
        }
    });
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DiskRegion(org.apache.geode.internal.cache.DiskRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 3 with DiskRegion

use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.

the class DiskRegionDUnitTest method testLRUCapacityController.

/**
   * Tests disk overflow with an entry-based {@link LRUCapacityController}.
   */
@Test
public void testLRUCapacityController() throws CacheException {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1000, EvictionAction.OVERFLOW_TO_DISK));
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    factory.setDiskSynchronous(true);
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    Region region = createRegion(name, factory.create());
    DiskRegion dr = ((LocalRegion) region).getDiskRegion();
    DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    flush(region);
    assertEquals(0, diskStats.getWrites());
    assertEquals(0, diskStats.getReads());
    assertEquals(0, lruStats.getEvictions());
    // Put in larger stuff until we start evicting
    for (int i = 1; i <= 1000; i++) {
        // System.out.println("total " + i + ", evictions " +
        // lruStats.getEvictions());
        Object key = new Integer(i);
        Object value = String.valueOf(i);
        region.put(key, value);
        assertEquals(i, lruStats.getCounter());
        assertEquals(0, lruStats.getEvictions());
        assertEquals("On iteration " + i, 0, diskStats.getWrites());
        assertEquals(0, diskStats.getReads());
        assertEquals(0, diskStats.getNumOverflowOnDisk());
    }
    assertEquals(0, diskStats.getWrites());
    assertEquals(0, diskStats.getReads());
    assertEquals(0, diskStats.getNumOverflowOnDisk());
    // Add a new value
    region.put(new Integer(1000 + 1), String.valueOf(1000 + 1));
    assertEquals(1000, lruStats.getCounter());
    assertEquals(1, lruStats.getEvictions());
    assertEquals(1, diskStats.getWrites());
    assertEquals(0, diskStats.getReads());
    assertEquals(1, diskStats.getNumOverflowOnDisk());
    assertEquals(1000, diskStats.getNumEntriesInVM());
    // Add another new value
    region.put(new Integer(1000 + 2), String.valueOf(1000 + 2));
    assertEquals(1000, lruStats.getCounter());
    assertEquals(2, lruStats.getEvictions());
    assertEquals(2, diskStats.getWrites());
    assertEquals(0, diskStats.getReads());
    assertEquals(2, diskStats.getNumOverflowOnDisk());
    assertEquals(1000, diskStats.getNumEntriesInVM());
    // Replace a value
    region.put(new Integer(1000), String.valueOf(1000));
    assertEquals(1000, lruStats.getCounter());
    assertEquals(2, lruStats.getEvictions());
    assertEquals(2, diskStats.getWrites());
    assertEquals(0, diskStats.getReads());
    assertEquals(2, diskStats.getNumOverflowOnDisk());
    assertEquals(1000, diskStats.getNumEntriesInVM());
}
Also used : DiskRegionStats(org.apache.geode.internal.cache.DiskRegionStats) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with DiskRegion

use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.

the class DiskRegionDUnitTest method testValues.

/**
   * Tests iterating over all of the values when some have been overflowed.
   */
@Test
public void testValues() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    Region region = createRegion(name, factory.create());
    // DiskRegion dr = ((LocalRegion) region).getDiskRegion();
    // DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    // Put in larger stuff until we start evicting
    int total;
    for (total = 0; lruStats.getEvictions() <= 0; total++) {
        int[] array = new int[250];
        array[0] = total;
        region.put(new Integer(total), array);
    }
    BitSet bits = new BitSet();
    Collection values = region.values();
    assertEquals(total, values.size());
    for (Iterator iter = values.iterator(); iter.hasNext(); ) {
        Object value = iter.next();
        assertNotNull(value);
        int[] array = (int[]) value;
        int i = array[0];
        assertFalse("Bit " + i + " is already set", bits.get(i));
        bits.set(i);
    }
}
Also used : BitSet(java.util.BitSet) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) Iterator(java.util.Iterator) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) File(java.io.File) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with DiskRegion

use of org.apache.geode.internal.cache.DiskRegion in project geode by apache.

the class DiskRegionDUnitTest method testRegionEntryValues.

// testSwitchOut is no longer valid
// the test was not written correctly to recover
// and if it was it would now fail with a split brain
// testSwitchIn is no longer valid
// we no longer switchIn files if GII aborts.
/**
   * Tests getting the {@linkplain org.apache.geode.cache.Region.Entry#getValue values} of region
   * entries that have been overflowed.
   */
@Test
public void testRegionEntryValues() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { d });
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    Region region = createRegion(name, factory.create());
    // DiskRegion dr = ((LocalRegion) region).getDiskRegion();
    // DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);
    // Put in larger stuff until we start evicting
    int total;
    for (total = 0; lruStats.getEvictions() <= 0; total++) {
        int[] array = new int[250];
        array[0] = total;
        region.put(new Integer(total), array);
    }
    // BitSet bits = new BitSet();
    Set values = region.entrySet(false);
    assertEquals(total, values.size());
    for (Iterator iter = values.iterator(); iter.hasNext(); ) {
        Region.Entry entry = (Region.Entry) iter.next();
        Integer key = (Integer) entry.getKey();
        int[] value = (int[]) entry.getValue();
        assertNotNull(value);
        assertEquals("Key/value" + key, key.intValue(), value[0]);
    }
}
Also used : Set(java.util.Set) BitSet(java.util.BitSet) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) Iterator(java.util.Iterator) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DiskRegion (org.apache.geode.internal.cache.DiskRegion)18 LocalRegion (org.apache.geode.internal.cache.LocalRegion)17 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)15 AttributesFactory (org.apache.geode.cache.AttributesFactory)14 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)14 Test (org.junit.Test)14 File (java.io.File)13 DiskStore (org.apache.geode.cache.DiskStore)13 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)13 Region (org.apache.geode.cache.Region)11 DiskRegionStats (org.apache.geode.internal.cache.DiskRegionStats)8 Cache (org.apache.geode.cache.Cache)3 Host (org.apache.geode.test.dunit.Host)3 VM (org.apache.geode.test.dunit.VM)3 BitSet (java.util.BitSet)2 Iterator (java.util.Iterator)2 EntryEvent (org.apache.geode.cache.EntryEvent)2 ObjectSizer (org.apache.geode.cache.util.ObjectSizer)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 DirectoryHolder (org.apache.geode.internal.cache.DirectoryHolder)2