Search in sources :

Example 1 with StorageFullException

use of io.pravega.segmentstore.storage.StorageFullException in project pravega by pravega.

the class ChunkedSegmentStorageTests method testFullStorage.

@Test
public void testFullStorage() throws Exception {
    @Cleanup TestContext testContext = getTestContext(ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().maxSafeStorageSize(1000).build());
    Assert.assertFalse(testContext.chunkedSegmentStorage.isSafeMode());
    val h = testContext.chunkedSegmentStorage.create("test", TIMEOUT).get();
    testContext.chunkedSegmentStorage.write(h, 0, new ByteArrayInputStream(new byte[10]), 10, TIMEOUT).get();
    testContext.chunkedSegmentStorage.create("segment", TIMEOUT).get();
    testContext.chunkedSegmentStorage.create("_system/something", TIMEOUT).get();
    // Simulate storage full.
    ((AbstractInMemoryChunkStorage) testContext.chunkStorage).setUsedSizeToReturn(1000);
    testContext.chunkedSegmentStorage.updateStorageStats().join();
    Assert.assertTrue(testContext.chunkedSegmentStorage.isSafeMode());
    // These operations should pass
    Assert.assertEquals(10, testContext.chunkedSegmentStorage.getStreamSegmentInfo("test", TIMEOUT).get().getLength());
    checkDataRead("test", testContext, 0, 10);
    val h3 = testContext.chunkedSegmentStorage.create("A", TIMEOUT).get();
    testContext.chunkedSegmentStorage.seal(h3, TIMEOUT).get();
    testContext.chunkedSegmentStorage.delete(h3, TIMEOUT).get();
    testContext.chunkedSegmentStorage.write(SegmentStorageHandle.writeHandle("_system/something"), 0, new ByteArrayInputStream(new byte[10]), 10, TIMEOUT).get();
    // These operations should fail
    AssertExtensions.assertFutureThrows("write() should throw an exception", testContext.chunkedSegmentStorage.write(h, 10, new ByteArrayInputStream(new byte[10]), 10, TIMEOUT), ex -> ex instanceof StorageFullException);
    AssertExtensions.assertFutureThrows("conact() should throw an exception", testContext.chunkedSegmentStorage.concat(h, 10, "A", TIMEOUT), ex -> ex instanceof StorageFullException);
    // Remove storage full
    ((AbstractInMemoryChunkStorage) testContext.chunkStorage).setUsedSizeToReturn(50);
    testContext.chunkedSegmentStorage.updateStorageStats().join();
    Assert.assertFalse(testContext.chunkedSegmentStorage.isSafeMode());
    testContext.chunkedSegmentStorage.write(SegmentStorageHandle.writeHandle("test"), 10, new ByteArrayInputStream(new byte[10]), 10, TIMEOUT).get();
    testContext.chunkedSegmentStorage.write(SegmentStorageHandle.writeHandle("segment"), 0, new ByteArrayInputStream(new byte[10]), 10, TIMEOUT).get();
    testContext.chunkedSegmentStorage.write(SegmentStorageHandle.writeHandle("_system/something"), 10, new ByteArrayInputStream(new byte[10]), 10, TIMEOUT).get();
    Assert.assertEquals(20, testContext.chunkedSegmentStorage.getStreamSegmentInfo("test", TIMEOUT).get().getLength());
    Assert.assertEquals(10, testContext.chunkedSegmentStorage.getStreamSegmentInfo("segment", TIMEOUT).get().getLength());
    Assert.assertEquals(20, testContext.chunkedSegmentStorage.getStreamSegmentInfo("_system/something", TIMEOUT).get().getLength());
    checkDataRead("test", testContext, 0, 20);
    checkDataRead("segment", testContext, 0, 10);
    val h4 = testContext.chunkedSegmentStorage.create("B", TIMEOUT).get();
    testContext.chunkedSegmentStorage.delete(h4, TIMEOUT).get();
    testContext.chunkedSegmentStorage.seal(SegmentStorageHandle.writeHandle("segment"), TIMEOUT).get();
    testContext.chunkedSegmentStorage.concat(SegmentStorageHandle.writeHandle("test"), 20, "segment", TIMEOUT).get();
}
Also used : lombok.val(lombok.val) ByteArrayInputStream(java.io.ByteArrayInputStream) StorageFullException(io.pravega.segmentstore.storage.StorageFullException) Cleanup(lombok.Cleanup) AbstractInMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.AbstractInMemoryChunkStorage) Test(org.junit.Test)

Example 2 with StorageFullException

use of io.pravega.segmentstore.storage.StorageFullException in project pravega by pravega.

the class ConcatOperation method handleException.

private Void handleException(Throwable e) {
    log.debug("{} concat - exception op={}, target={}, source={}, offset={}.", chunkedSegmentStorage.getLogPrefix(), System.identityHashCode(this), targetHandle.getSegmentName(), sourceSegment, offset);
    val ex = Exceptions.unwrap(e);
    if (ex instanceof StorageMetadataWritesFencedOutException) {
        throw new CompletionException(new StorageNotPrimaryException(targetHandle.getSegmentName(), ex));
    }
    if (ex instanceof ChunkStorageFullException) {
        throw new CompletionException(new StorageFullException(targetHandle.getSegmentName(), ex));
    }
    throw new CompletionException(ex);
}
Also used : lombok.val(lombok.val) CompletionException(java.util.concurrent.CompletionException) StorageFullException(io.pravega.segmentstore.storage.StorageFullException) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) StorageMetadataWritesFencedOutException(io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException)

Example 3 with StorageFullException

use of io.pravega.segmentstore.storage.StorageFullException in project pravega by pravega.

the class WriteOperation method handleException.

private Object handleException(Throwable e) {
    log.debug("{} write - exception op={}, segment={}, offset={}, length={}.", chunkedSegmentStorage.getLogPrefix(), System.identityHashCode(this), handle.getSegmentName(), offset, length);
    val ex = Exceptions.unwrap(e);
    if (ex instanceof StorageMetadataWritesFencedOutException) {
        throw new CompletionException(new StorageNotPrimaryException(handle.getSegmentName(), ex));
    }
    if (ex instanceof ChunkStorageFullException) {
        throw new CompletionException(new StorageFullException(handle.getSegmentName(), ex));
    }
    throw new CompletionException(ex);
}
Also used : lombok.val(lombok.val) CompletionException(java.util.concurrent.CompletionException) StorageFullException(io.pravega.segmentstore.storage.StorageFullException) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) StorageMetadataWritesFencedOutException(io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException)

Aggregations

StorageFullException (io.pravega.segmentstore.storage.StorageFullException)3 lombok.val (lombok.val)3 StorageNotPrimaryException (io.pravega.segmentstore.storage.StorageNotPrimaryException)2 StorageMetadataWritesFencedOutException (io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException)2 CompletionException (java.util.concurrent.CompletionException)2 AbstractInMemoryChunkStorage (io.pravega.segmentstore.storage.mocks.AbstractInMemoryChunkStorage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1