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()));
}
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));
}
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()));
}
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());
}
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());
}
Aggregations