Search in sources :

Example 36 with DiskAccessException

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

the class DiskRegionJUnitTest method testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase.

/**
   * If IOException occurs while updating an entry in an already initialized DiskRegion ,then the
   * bridge servers should not be stopped , if any running as they are no clients connected to it.
   */
@Test
public void testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase() throws Exception {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase");
    props.setOverflow(true);
    props.setRolling(true);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
    CacheServer bs1 = cache.addCacheServer();
    bs1.setPort(0);
    bs1.start();
    region.create("key1", new byte[16]);
    region.create("key2", new byte[16]);
    // Get the oplog handle & hence the underlying file & close it
    UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    oplogFileChannel.close();
    try {
        region.put("key2", new byte[16]);
    } catch (DiskAccessException dae) {
    // OK expected
    }
    ((LocalRegion) region).getDiskStore().waitForClose();
    assertTrue(cache.isClosed());
    region = null;
    List bsRunning = cache.getCacheServers();
    // [anil & bruce] the following assertion was changed to true because
    // a disk access exception in a server should always stop the server
    assertTrue(bsRunning.isEmpty());
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheServer(org.apache.geode.cache.server.CacheServer) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 37 with DiskAccessException

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

the class DiskRegionJUnitTest method testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase.

/**
   * If IOException occurs while initializing a region ,then the bridge servers should not be
   * stopped
   */
@Test
public void testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase() throws Exception {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase");
    props.setOverflow(true);
    props.setRolling(true);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    // just needs to be bigger than 65550
    props.setMaxOplogSize(100000);
    region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
    CacheServer bs1 = cache.addCacheServer();
    bs1.setPort(0);
    bs1.start();
    region.create("key1", new byte[16]);
    region.create("key2", new byte[16]);
    // Get the oplog file path
    UninterruptibleFileChannel oplogFileChnl = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    // corrupt the opfile
    oplogFileChnl.position(2);
    ByteBuffer bf = ByteBuffer.allocate(416);
    for (int i = 0; i < 5; ++i) {
        bf.putInt(i);
    }
    bf.flip();
    // Corrupt the oplogFile
    oplogFileChnl.write(bf);
    // Close the region
    region.close();
    assertTrue(region.isDestroyed());
    try {
        region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL);
        fail("expected DiskAccessException");
    } catch (DiskAccessException dae) {
    // OK expected
    }
    assertTrue(region.isDestroyed());
    region = null;
    List bsRunning = cache.getCacheServers();
    assertTrue(!bsRunning.isEmpty());
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheServer(org.apache.geode.cache.server.CacheServer) ArrayList(java.util.ArrayList) List(java.util.List) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 38 with DiskAccessException

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

the class PersistentPartitionedRegionDUnitTest method testBadSerializationInAsyncThread.

/**
   * Test for bug #49972 - handle a serialization error in the async writer thread.
   */
@Ignore("Bug 50376")
@Test
public void testBadSerializationInAsyncThread() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final int numBuckets = 50;
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            FAIL_IN_THIS_VM = true;
        }
    });
    IgnoredException expected1 = IgnoredException.addIgnoredException("Fatal error from asynch");
    IgnoredException expected2 = IgnoredException.addIgnoredException("ToDataException");
    try {
        int redundancy = 1;
        createPR(vm0, redundancy, -1, 113, false);
        createPR(vm2, redundancy, -1, 113, false);
        // Trigger bucket creation
        createData(vm0, 0, numBuckets, "a");
        createPR(vm1, redundancy, -1, 113, false);
        // write objects which will fail serialization in async writer thread.
        vm0.invoke(new SerializableRunnable() {

            public void run() {
                Cache cache = getCache();
                Region region = cache.getRegion(PR_REGION_NAME);
                try {
                    for (int i = 0; i < numBuckets; i++) {
                        region.put(i, new BadSerializer());
                        // this will trigger a deserialiation (could have also done this put with a function I
                        // guess.
                        region.get(i);
                    }
                } catch (DiskAccessException ex) {
                    if (ex.getMessage().contains("the flusher thread had been terminated")) {
                    // expected
                    } else {
                        throw ex;
                    }
                }
            }
        });
        // Wait for the thread to get hosed.
        Thread.sleep(2000);
        createData(vm1, 0, numBuckets, "b");
        // Try to do puts from vm1, which doesn't have any buckets
        createData(vm1, numBuckets, numBuckets * 2, "b");
        createData(vm1, numBuckets, numBuckets * 2, "c");
        // make sure everything has settle out (these VM's I suppose may be terminated)
        checkData(vm2, 0, numBuckets, "b");
        checkData(vm2, numBuckets, numBuckets * 2, "c");
    } finally {
        expected1.remove();
        expected2.remove();
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DiskAccessException(org.apache.geode.cache.DiskAccessException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) Cache(org.apache.geode.cache.Cache) Ignore(org.junit.Ignore) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 39 with DiskAccessException

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

the class Bug39079DUnitTest method validateRunningBridgeServerList.

private void validateRunningBridgeServerList() throws IOException {
    Region region = getCache().getRegion(REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase);
    try {
        region.create("key1", new byte[16]);
        region.create("key2", new byte[16]);
        // Get the oplog handle & hence the underlying file & close it
        UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
        try {
            oplogFileChannel.close();
            region.put("key2", new byte[16]);
            fail("Expected DiskAccessException");
        } catch (DiskAccessException expected) {
        }
        ((LocalRegion) region).getDiskStore().waitForClose();
        assertTrue(region.getRegionService().isClosed());
        region = null;
        List bsRunning = getCache().getCacheServers();
        assertTrue(bsRunning.isEmpty());
    } finally {
        if (region != null) {
            region.destroyRegion();
        }
    }
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException) Region(org.apache.geode.cache.Region) List(java.util.List)

Example 40 with DiskAccessException

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

the class DiskStoreImpl method createLockFile.

private void createLockFile(String name) throws DiskAccessException {
    File f = new File(getInfoFileDir().getDir(), "DRLK_IF" + name + LOCK_FILE_EXT);
    if (logger.isDebugEnabled()) {
        logger.debug("Creating lock file {}", f);
    }
    FileOutputStream fs = null;
    // 41734: A known NFS issue on Redhat. The thread created the directory,
    // but when it try to lock, it will fail with permission denied or
    // input/output
    // error. To workarround it, introduce 5 times retries.
    int cnt = 0;
    DiskAccessException dae = null;
    do {
        try {
            fs = new FileOutputStream(f);
            this.lockFile = f;
            this.fl = fs.getChannel().tryLock();
            if (fl == null) {
                try {
                    fs.close();
                } catch (IOException ignore) {
                }
                throw new IOException(LocalizedStrings.Oplog_THE_FILE_0_IS_BEING_USED_BY_ANOTHER_PROCESS.toLocalizedString(f));
            }
            f.deleteOnExit();
            dae = null;
            break;
        } catch (IOException | IllegalStateException ex) {
            if (fs != null) {
                try {
                    fs.close();
                } catch (IOException ignore) {
                }
            }
            dae = new DiskAccessException(LocalizedStrings.Oplog_COULD_NOT_LOCK_0.toLocalizedString(f.getPath()), ex, this);
        }
        cnt++;
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } while (cnt < 100);
    if (dae != null) {
        throw dae;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Locked disk store {} for exclusive access in directory: {}", name, getInfoFileDir().getDir());
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) DiskAccessException(org.apache.geode.cache.DiskAccessException) IOException(java.io.IOException) File(java.io.File)

Aggregations

DiskAccessException (org.apache.geode.cache.DiskAccessException)76 IOException (java.io.IOException)44 InterruptedIOException (java.io.InterruptedIOException)17 StoredObject (org.apache.geode.internal.offheap.StoredObject)13 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)11 ByteBuffer (java.nio.ByteBuffer)9 Test (org.junit.Test)8 Version (org.apache.geode.internal.Version)6 File (java.io.File)5 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 IndexManager (org.apache.geode.cache.query.internal.index.IndexManager)5 UninterruptibleFileChannel (org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel)5 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)5 Released (org.apache.geode.internal.offheap.annotations.Released)5 BufferedInputStream (java.io.BufferedInputStream)4 FileInputStream (java.io.FileInputStream)4 CancelException (org.apache.geode.CancelException)4 BytesAndBits (org.apache.geode.internal.cache.persistence.BytesAndBits)4 UninterruptibleRandomAccessFile (org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)4 EOFException (java.io.EOFException)3