Search in sources :

Example 31 with DiskAccessException

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

the class Oplog method copyForwardModifyForCompact.

private void copyForwardModifyForCompact(DiskRegionView dr, DiskEntry entry, BytesAndBitsForCompactor wrapper) {
    if (getOplogSet().getChild() != this) {
        getOplogSet().getChild().copyForwardModifyForCompact(dr, entry, wrapper);
    } else {
        DiskId did = entry.getDiskId();
        boolean exceptionOccurred = false;
        int len = did.getValueLength();
        try {
            // TODO: compaction needs to get version?
            byte userBits = wrapper.getBits();
            ValueWrapper vw;
            if (wrapper.getOffHeapData() != null) {
                vw = new DiskEntry.Helper.OffHeapValueWrapper(wrapper.getOffHeapData());
            } else {
                vw = new DiskEntry.Helper.CompactorValueWrapper(wrapper.getBytes(), wrapper.getValidLength());
            }
            // Compactor always says to do an async basicModify so that its writes
            // will be grouped. This is not a true async write; just a grouped one.
            basicModify(dr, entry, vw, userBits, true, true);
        } catch (IOException ex) {
            exceptionOccurred = true;
            getParent().getCancelCriterion().checkCancelInProgress(ex);
            throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0.toLocalizedString(this.diskFile.getPath()), ex, getParent());
        } catch (InterruptedException ie) {
            exceptionOccurred = true;
            Thread.currentThread().interrupt();
            getParent().getCancelCriterion().checkCancelInProgress(ie);
            throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0_DUE_TO_FAILURE_IN_ACQUIRING_READ_LOCK_FOR_ASYNCH_WRITING.toLocalizedString(this.diskFile.getPath()), ie, getParent());
        } finally {
            if (wrapper.getOffHeapData() != null) {
                wrapper.setOffHeapData(null, (byte) 0);
            }
            if (exceptionOccurred) {
                did.setValueLength(len);
            }
        }
    }
}
Also used : BlobHelper(org.apache.geode.internal.util.BlobHelper) ReferenceCountHelper(org.apache.geode.internal.offheap.ReferenceCountHelper) OffHeapHelper(org.apache.geode.internal.offheap.OffHeapHelper) ValueWrapper(org.apache.geode.internal.cache.DiskEntry.Helper.ValueWrapper) DiskAccessException(org.apache.geode.cache.DiskAccessException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 32 with DiskAccessException

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

the class Oplog method remove.

/**
   * Removes the key/value pair with the given id on disk.
   * 
   * @param entry DiskEntry object on which remove operation is called
   */
public void remove(LocalRegion region, DiskEntry entry, boolean async, boolean isClear) {
    DiskRegion dr = region.getDiskRegion();
    if (getOplogSet().getChild() != this) {
        getOplogSet().getChild().remove(region, entry, async, isClear);
    } else {
        DiskId did = entry.getDiskId();
        boolean exceptionOccurred = false;
        byte prevUsrBit = did.getUserBits();
        int len = did.getValueLength();
        try {
            basicRemove(dr, entry, async, isClear);
        } catch (IOException ex) {
            exceptionOccurred = true;
            getParent().getCancelCriterion().checkCancelInProgress(ex);
            throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0.toLocalizedString(this.diskFile.getPath()), ex, dr.getName());
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            region.getCancelCriterion().checkCancelInProgress(ie);
            exceptionOccurred = true;
            throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0_DUE_TO_FAILURE_IN_ACQUIRING_READ_LOCK_FOR_ASYNCH_WRITING.toLocalizedString(this.diskFile.getPath()), ie, dr.getName());
        } finally {
            if (exceptionOccurred) {
                did.setValueLength(len);
                did.setUserBits(prevUsrBit);
            }
        }
    }
}
Also used : DiskAccessException(org.apache.geode.cache.DiskAccessException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 33 with DiskAccessException

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

the class DiskRegOplogSwtchingAndRollerJUnitTest method testDiskFullExcep.

// end of testGetEvictedEntry
/**
   * DiskRegNoDiskAccessExceptionTest: tests that while rolling is set to true DiskAccessException
   * doesn't occur even when amount of put data exceeds the max dir sizes.
   */
@Test
public void testDiskFullExcep() {
    boolean exceptionOccurred = false;
    int[] diskDirSize1 = new int[4];
    diskDirSize1[0] = 1048576;
    diskDirSize1[1] = 1048576;
    diskDirSize1[2] = 1048576;
    diskDirSize1[3] = 1048576;
    diskProps.setDiskDirsAndSizes(dirs, diskDirSize1);
    diskProps.setPersistBackup(true);
    diskProps.setRolling(true);
    diskProps.setMaxOplogSize(1000000000);
    diskProps.setBytesThreshold(1000000);
    diskProps.setTimeInterval(1500000);
    region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, diskProps);
    DiskStore ds = cache.findDiskStore(((LocalRegion) region).getDiskStoreName());
    // int[] diskSizes1 = ((LocalRegion)region).getDiskDirSizes();
    assertTrue(ds != null);
    int[] diskSizes1 = null;
    diskSizes1 = ds.getDiskDirSizes();
    assertTrue("diskSizes != 1048576 ", diskSizes1[0] == 1048576);
    assertTrue("diskSizes != 1048576 ", diskSizes1[1] == 1048576);
    assertTrue("diskSizes != 1048576 ", diskSizes1[2] == 1048576);
    assertTrue("diskSizes != 1048576 ", diskSizes1[3] == 1048576);
    final byte[] value = new byte[1024];
    Arrays.fill(value, (byte) 77);
    try {
        for (int i = 0; i < 7000; i++) {
            region.put("" + i, value);
        }
    } catch (DiskAccessException e) {
        logWriter.error("exception not expected", e);
        exceptionOccurred = true;
    }
    if (exceptionOccurred) {
        fail("FAILED::DiskAccessException is Not expected here !!");
    }
// region.close(); // closes disk file which will flush all buffers
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) DiskAccessException(org.apache.geode.cache.DiskAccessException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 34 with DiskAccessException

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

the class DiskRegionJUnitTest method entryInvalidateInSynchPersistTypeForIOExceptionCase.

/**
   * If IOException occurs while invalidating an entry in a persist only synch mode,
   * DiskAccessException should occur & region should be destroyed
   * 
   * @throws Exception
   */
private void entryInvalidateInSynchPersistTypeForIOExceptionCase(Region region) throws Exception {
    region.create("key1", "value1");
    // Get the oplog handle & hence the underlying file & close it
    UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    oplogFileChannel.close();
    try {
        region.invalidate("key1");
        fail("Should have encountered DiskAccessException");
    } catch (DiskAccessException dae) {
    // OK
    }
    ((LocalRegion) region).getDiskStore().waitForClose();
    assertTrue(cache.isClosed());
    region = null;
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException)

Example 35 with DiskAccessException

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

the class DiskRegionJUnitTest method entryCreateInSynchPersistTypeForIOExceptionCase.

/**
   * 
   * If IOException occurs while creating an entry in a persist only synch mode, DiskAccessException
   * should occur & region should be destroyed
   * 
   * @throws Exception
   */
private void entryCreateInSynchPersistTypeForIOExceptionCase(Region region) throws Exception {
    // Get the oplog handle & hence the underlying file & close it
    UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    oplogFileChannel.close();
    try {
        region.create("key1", "value1");
        fail("Should have encountered DiskAccessException");
    } catch (DiskAccessException dae) {
    // OK
    }
    ((LocalRegion) region).getDiskStore().waitForClose();
    assertTrue(cache.isClosed());
    region = null;
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) DiskAccessException(org.apache.geode.cache.DiskAccessException)

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