Search in sources :

Example 1 with IllegalContainerStateException

use of io.pravega.segmentstore.server.IllegalContainerStateException in project pravega by pravega.

the class StreamSegmentContainerTests method testWriteFenceOut.

/**
 * Tests the behavior of the SegmentContainer when another instance of the same container is activated and fences out
 * the first one.
 */
@Test
public void testWriteFenceOut() throws Exception {
    final String segmentName = "SegmentName";
    final Duration shutdownTimeout = Duration.ofSeconds(5);
    @Cleanup TestContext context = createContext();
    val container1 = context.container;
    container1.startAsync().awaitRunning();
    container1.createStreamSegment(segmentName, getSegmentType(segmentName), null, TIMEOUT).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
    // Workaround for pre-SLTS (RollingStorage) known problem when a zombie (fenced-out) instance can still write
    // a header file while shutting down and concurrently with the new instance. This additional step can be retired
    // once RollingStorage is retired.
    waitForSegmentsInStorage(Collections.singleton(NameUtils.getMetadataSegmentName(CONTAINER_ID)), context).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
    @Cleanup val container2 = context.containerFactory.createStreamSegmentContainer(CONTAINER_ID);
    container2.startAsync().awaitRunning();
    AssertExtensions.assertSuppliedFutureThrows("Original container did not reject an append operation after being fenced out.", () -> container1.append(segmentName, new ByteArraySegment(new byte[1]), null, TIMEOUT), ex -> // Write fenced.
    ex instanceof DataLogWriterNotPrimaryException || // Write accepted, but OperationProcessor shuts down while processing it.
    ex instanceof ObjectClosedException || // Write rejected due to Container not running.
    ex instanceof IllegalContainerStateException);
    // Verify we can still write to the second container.
    container2.append(segmentName, 0, new ByteArraySegment(new byte[1]), null, TIMEOUT).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
    // Verify container1 is shutting down (give it some time to complete) and that it ends up in a Failed state.
    ServiceListeners.awaitShutdown(container1, shutdownTimeout, false);
    Assert.assertEquals("Container1 is not in a failed state after fence-out detected.", Service.State.FAILED, container1.state());
}
Also used : lombok.val(lombok.val) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) ByteArraySegment(io.pravega.common.util.ByteArraySegment) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) ObjectClosedException(io.pravega.common.ObjectClosedException) Duration(java.time.Duration) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

ObjectClosedException (io.pravega.common.ObjectClosedException)1 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 IllegalContainerStateException (io.pravega.segmentstore.server.IllegalContainerStateException)1 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)1 Duration (java.time.Duration)1 Cleanup (lombok.Cleanup)1 lombok.val (lombok.val)1 Test (org.junit.Test)1