Search in sources :

Example 16 with StorageNotPrimaryException

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

the class OpenWriteOperationTests method testLargerEpoch.

/**
 * Tests the case when the last file has en epoch larger than ours.
 * Expected outcome: StorageNotPrimaryException and no side effects.
 */
@Test
public void testLargerEpoch() throws Exception {
    @Cleanup val fs = new MockFileSystem();
    val lowContext = newContext(1, fs);
    val highContext = newContext(lowContext.epoch + 1, fs);
    new CreateOperation(SEGMENT_NAME, highContext).call();
    val writeHandle = new OpenWriteOperation(SEGMENT_NAME, highContext).call();
    AssertExtensions.assertThrows("OpenWrite allowed opening a segment that does not have the highest epoch.", new OpenWriteOperation(SEGMENT_NAME, lowContext)::call, ex -> ex instanceof StorageNotPrimaryException);
    Assert.assertEquals("Unexpected number of files in the file system.", 1, fs.getFileCount());
    Assert.assertTrue("Higher epoch file was deleted.", fs.exists(writeHandle.getLastFile().getPath()));
}
Also used : lombok.val(lombok.val) Cleanup(lombok.Cleanup) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) Test(org.junit.Test)

Example 17 with StorageNotPrimaryException

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

the class OpenWriteOperationTests method testConcurrentFenceOutLower.

/**
 * Tests the case when the OpenWriteOperation thinks it is the highest epoch, fences out, but then it finds out
 * it was beaten to it by a higher epoch instance.
 * Expected outcome: StorageNotPrimaryException and no side effects (it should back off).
 */
@Test
public void testConcurrentFenceOutLower() throws Exception {
    @Cleanup val fs = new MockFileSystem();
    val context1 = newContext(1, fs);
    new CreateOperation(SEGMENT_NAME, context1).call();
    val context2 = newContext(context1.epoch + 1, fs);
    val context3 = newContext(context2.epoch + 1, fs);
    Path survivingFilePath = context3.getFileName(SEGMENT_NAME, 0);
    fs.setOnCreate(path -> fs.new CreateNewFileAction(survivingFilePath));
    AssertExtensions.assertThrows("OpenWrite did not fail when a concurrent higher epoch file was created.", new OpenWriteOperation(SEGMENT_NAME, context2)::call, ex -> ex instanceof StorageNotPrimaryException);
    // In a real-world situation, we'd have just one surviving file. However we were not able to successfully carry
    // out the fencing operation, hence no cleanup could be done (testConcurrentFenceOutHigher should check this though).
    Assert.assertEquals("Unexpected number of files in the file system.", 2, fs.getFileCount());
    Assert.assertTrue("Original file was deleted.", fs.exists(context1.getFileName(SEGMENT_NAME, 0)));
    Assert.assertTrue("Higher epoch file was deleted.", fs.exists(survivingFilePath));
}
Also used : lombok.val(lombok.val) Path(org.apache.hadoop.fs.Path) Cleanup(lombok.Cleanup) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) Test(org.junit.Test)

Example 18 with StorageNotPrimaryException

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

the class SealOperationTests method testLastFileEmptyNonReadOnlyFencedOut.

/**
 * Tests the case when the last file was thought to be read-only but it got changed in the background and
 * fenced out by a higher-epoch instance.
 * Expected outcome: StorageNotPrimaryException.
 */
@Test
public void testLastFileEmptyNonReadOnlyFencedOut() throws Exception {
    final String emptySegment = SEGMENT_NAME;
    final String nonEmptySegment = SEGMENT_NAME + "nonempty";
    @Cleanup val fs = new MockFileSystem();
    val context1 = newContext(1, fs);
    val context2 = newContext(context1.epoch + 1, fs);
    new CreateOperation(emptySegment, context1).call();
    val emptySegmentHandle1 = new OpenWriteOperation(emptySegment, context1).call();
    // Part 1: empty segment first file (it will be deleted when OpenWrite is invoked with epoch 2)
    new OpenWriteOperation(emptySegment, context2).call();
    AssertExtensions.assertThrows("SealOperation did not fail when it was fenced out (empty segment).", new SealOperation(emptySegmentHandle1, context1)::run, ex -> ex instanceof StorageNotPrimaryException);
    Assert.assertFalse("Last file in emptySegmentHandle1 was marked as read-only.", emptySegmentHandle1.getLastFile().isReadOnly());
    Assert.assertFalse("Last file in file system (empty segment) was set as 'sealed'.", fs.exists(emptySegmentHandle1.getLastFile().getPath()));
    // Part 1: non-empty segment first file (it will be marked read-only when OpenWrite is invoked with epoch 2)
    new CreateOperation(nonEmptySegment, context1).call();
    val nonEmptySegmentHandle1 = new OpenWriteOperation(nonEmptySegment, context1).call();
    new WriteOperation(nonEmptySegmentHandle1, 0, new ByteArrayInputStream(new byte[1]), 1, context1).run();
    new OpenWriteOperation(nonEmptySegment, context2).call();
    AssertExtensions.assertThrows("SealOperation did not fail when it was fenced out (non-empty segment).", new SealOperation(nonEmptySegmentHandle1, context1)::run, ex -> ex instanceof StorageNotPrimaryException);
    Assert.assertFalse("Last file in nonEmptySegmentHandle1 was marked as read-only.", emptySegmentHandle1.getLastFile().isReadOnly());
    Assert.assertFalse("Last file in file system (empty segment) was set as 'sealed'.", context1.isSealed(nonEmptySegmentHandle1.getLastFile()));
}
Also used : lombok.val(lombok.val) ByteArrayInputStream(java.io.ByteArrayInputStream) Cleanup(lombok.Cleanup) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) Test(org.junit.Test)

Example 19 with StorageNotPrimaryException

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

the class WriteOperationTests method testFenceOutMissingFile.

/**
 * Tests the case when the current file (previously empty) has disappeared due to it being fenced out.
 * Expected behavior: StorageNotPrimaryException with no side effects.
 */
@Test
public void testFenceOutMissingFile() throws Exception {
    @Cleanup val fs = new MockFileSystem();
    val context1 = newContext(1, fs);
    new CreateOperation(SEGMENT_NAME, context1).call();
    val handle1 = new OpenWriteOperation(SEGMENT_NAME, context1).call();
    val context2 = newContext(2, fs);
    val handle2 = new OpenWriteOperation(SEGMENT_NAME, context2).call();
    AssertExtensions.assertThrows("WriteOperation did not fail when it was fenced out by removing a file.", new WriteOperation(handle1, 0, new ByteArrayInputStream(new byte[1]), 1, context1)::run, ex -> ex instanceof StorageNotPrimaryException);
    Assert.assertEquals("Unexpected number of files in the filesystem.", 1, fs.getFileCount());
    Assert.assertEquals("Unexpected size of the file in the filesystem.", 0, fs.getFileStatus(handle2.getLastFile().getPath()).getLen());
}
Also used : lombok.val(lombok.val) ByteArrayInputStream(java.io.ByteArrayInputStream) Cleanup(lombok.Cleanup) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) Test(org.junit.Test)

Example 20 with StorageNotPrimaryException

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

the class WriteOperationTests method testFenceOutReadOnlyFile.

/**
 * Tests the case when the current file (non-empty) has been marked as read-only due to it being fenced out.
 * Expected behavior: StorageNotPrimaryException with no side effects.
 */
@Test
public void testFenceOutReadOnlyFile() throws Exception {
    @Cleanup val fs = new MockFileSystem();
    val context1 = newContext(1, fs);
    new CreateOperation(SEGMENT_NAME, context1).call();
    val handle1 = new OpenWriteOperation(SEGMENT_NAME, context1).call();
    new WriteOperation(handle1, 0, new ByteArrayInputStream(new byte[1]), 1, context1).run();
    val context2 = newContext(2, fs);
    val handle2 = new OpenWriteOperation(SEGMENT_NAME, context2).call();
    AssertExtensions.assertThrows("WriteOperation did not fail when it was fenced out by making a file read-only.", new WriteOperation(handle1, 1, new ByteArrayInputStream(new byte[1]), 1, context1)::run, ex -> ex instanceof StorageNotPrimaryException);
    Assert.assertEquals("Unexpected number of files in the filesystem.", 2, fs.getFileCount());
    Assert.assertEquals("Unexpected size of the first file in the filesystem.", 1, fs.getFileStatus(handle1.getLastFile().getPath()).getLen());
    Assert.assertEquals("Unexpected size of the last file in the filesystem.", 0, fs.getFileStatus(handle2.getLastFile().getPath()).getLen());
}
Also used : lombok.val(lombok.val) ByteArrayInputStream(java.io.ByteArrayInputStream) Cleanup(lombok.Cleanup) StorageNotPrimaryException(io.pravega.segmentstore.storage.StorageNotPrimaryException) Test(org.junit.Test)

Aggregations

StorageNotPrimaryException (io.pravega.segmentstore.storage.StorageNotPrimaryException)29 lombok.val (lombok.val)22 Cleanup (lombok.Cleanup)15 Test (org.junit.Test)15 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)6 Path (org.apache.hadoop.fs.Path)6 FileStatus (org.apache.hadoop.fs.FileStatus)5 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)4 SegmentHandle (io.pravega.segmentstore.storage.SegmentHandle)4 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)3 StorageMetadataWritesFencedOutException (io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException)3 CompletionException (java.util.concurrent.CompletionException)3 StorageFullException (io.pravega.segmentstore.storage.StorageFullException)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 Exceptions (io.pravega.common.Exceptions)1 Timer (io.pravega.common.Timer)1 Futures (io.pravega.common.concurrent.Futures)1