Search in sources :

Example 1 with DataLogWriterNotPrimaryException

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

the class BookKeeperLog method persistMetadata.

/**
 * Persists the given metadata into ZooKeeper.
 *
 * @param metadata The LogMetadata to persist. At the end of this method, this metadata will have its Version updated
 *                 to the one in ZooKeeper.
 * @param create   Whether to create (true) or update (false) the data in ZooKeeper.
 * @throws DataLogWriterNotPrimaryException If the metadata update failed (if we were asked to create and the node
 *                                          already exists or if we had to update and there was a version mismatch).
 * @throws DurableDataLogException          If another kind of exception occurred.
 */
private void persistMetadata(LogMetadata metadata, boolean create) throws DurableDataLogException {
    try {
        byte[] serializedMetadata = LogMetadata.SERIALIZER.serialize(metadata).getCopy();
        if (create) {
            this.zkClient.create().creatingParentsIfNeeded().forPath(this.logNodePath, serializedMetadata);
            // Set version to 0 as that will match the ZNode's version.
            metadata.withUpdateVersion(0);
        } else {
            this.zkClient.setData().withVersion(metadata.getUpdateVersion()).forPath(this.logNodePath, serializedMetadata);
            // Increment the version to keep up with the ZNode's value (after writing it to ZK).
            metadata.withUpdateVersion(metadata.getUpdateVersion() + 1);
        }
    } catch (KeeperException.NodeExistsException | KeeperException.BadVersionException keeperEx) {
        // We were fenced out. Clean up and throw appropriate exception.
        throw new DataLogWriterNotPrimaryException(String.format("Unable to acquire exclusive write lock for log (path = '%s%s').", this.zkClient.getNamespace(), this.logNodePath), keeperEx);
    } catch (Exception generalEx) {
        // General exception. Clean up and rethrow appropriate exception.
        throw new DataLogInitializationException(String.format("Unable to update ZNode for path '%s%s'.", this.zkClient.getNamespace(), this.logNodePath), generalEx);
    }
    log.info("{} Metadata persisted ({}).", this.traceObjectId, metadata);
}
Also used : DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) ObjectClosedException(io.pravega.common.ObjectClosedException) DataLogNotAvailableException(io.pravega.segmentstore.storage.DataLogNotAvailableException) DataLogInitializationException(io.pravega.segmentstore.storage.DataLogInitializationException) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) DataLogDisabledException(io.pravega.segmentstore.storage.DataLogDisabledException) KeeperException(org.apache.zookeeper.KeeperException) CancellationException(java.util.concurrent.CancellationException) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) BKException(org.apache.bookkeeper.client.BKException) WriteFailureException(io.pravega.segmentstore.storage.WriteFailureException) WriteTooLongException(io.pravega.segmentstore.storage.WriteTooLongException) DataLogInitializationException(io.pravega.segmentstore.storage.DataLogInitializationException)

Example 2 with DataLogWriterNotPrimaryException

use of io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException 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 Duration shutdownTimeout = Duration.ofSeconds(5);
    @Cleanup TestContext context = new TestContext();
    val container1 = context.container;
    container1.startAsync().awaitRunning();
    val segmentNames = createSegments(context);
    @Cleanup val container2 = context.containerFactory.createStreamSegmentContainer(CONTAINER_ID);
    container2.startAsync().awaitRunning();
    AssertExtensions.assertThrows("Original container did not reject an append operation after being fenced out.", () -> container1.append(segmentNames.get(0), new byte[1], null, TIMEOUT), ex -> ex instanceof DataLogWriterNotPrimaryException);
    // Verify we can still write to the second container.
    container2.append(segmentNames.get(0), 0, 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());
    Assert.assertTrue("Container1 did not fail with the correct exception.", Exceptions.unwrap(container1.failureCause()) instanceof DataLogWriterNotPrimaryException);
}
Also used : lombok.val(lombok.val) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) Duration(java.time.Duration) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 3 with DataLogWriterNotPrimaryException

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

the class DurableLogTests method testAddWithDataLogWriterNotPrimaryException.

/**
 * Tests the ability of the DurableLog to handle a DataLogWriterNotPrimaryException.
 */
@Test
public void testAddWithDataLogWriterNotPrimaryException() throws Exception {
    int streamSegmentCount = 1;
    int appendsPerStreamSegment = 1;
    // Setup a DurableLog and start it.
    @Cleanup ContainerSetup setup = new ContainerSetup(executorService());
    @Cleanup DurableLog durableLog = setup.createDurableLog();
    durableLog.startAsync().awaitRunning();
    HashSet<Long> streamSegmentIds = createStreamSegmentsInMetadata(streamSegmentCount, setup.metadata);
    List<Operation> operations = generateOperations(streamSegmentIds, new HashMap<>(), appendsPerStreamSegment, METADATA_CHECKPOINT_EVERY, false, false);
    ErrorInjector<Exception> aSyncErrorInjector = new ErrorInjector<>(count -> true, () -> new CompletionException(new DataLogWriterNotPrimaryException("intentional")));
    setup.dataLog.get().setAppendErrorInjectors(null, aSyncErrorInjector);
    // Process all generated operations.
    List<OperationWithCompletion> completionFutures = processOperations(operations, durableLog);
    // Wait for all such operations to complete. We are expecting exceptions, so verify that we do.
    AssertExtensions.assertThrows("No operations failed.", OperationWithCompletion.allOf(completionFutures)::join, ex -> ex instanceof IOException || ex instanceof DataLogWriterNotPrimaryException);
    // Verify that the OperationProcessor automatically shuts down and that it has the right failure cause.
    ServiceListeners.awaitShutdown(durableLog, TIMEOUT, false);
    Assert.assertEquals("DurableLog is not in a failed state after fence-out detected.", Service.State.FAILED, durableLog.state());
    Assert.assertTrue("DurableLog did not fail with the correct exception.", Exceptions.unwrap(durableLog.failureCause()) instanceof DataLogWriterNotPrimaryException);
}
Also used : DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) ErrorInjector(io.pravega.test.common.ErrorInjector) StorageMetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation) ProbeOperation(io.pravega.segmentstore.server.logs.operations.ProbeOperation) Operation(io.pravega.segmentstore.server.logs.operations.Operation) StreamSegmentMapOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation) MetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation) StorageOperation(io.pravega.segmentstore.server.logs.operations.StorageOperation) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) IOException(java.io.IOException) Cleanup(lombok.Cleanup) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) TimeoutException(java.util.concurrent.TimeoutException) DataLogNotAvailableException(io.pravega.segmentstore.storage.DataLogNotAvailableException) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) ContainerOfflineException(io.pravega.segmentstore.server.ContainerOfflineException) CompletionException(java.util.concurrent.CompletionException) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) StreamSegmentException(io.pravega.segmentstore.contracts.StreamSegmentException) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) DataLogDisabledException(io.pravega.segmentstore.storage.DataLogDisabledException) IntentionalException(io.pravega.test.common.IntentionalException) IOException(java.io.IOException) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Example 4 with DataLogWriterNotPrimaryException

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

the class OperationProcessorTests method testWithDataLogNotPrimaryException.

/**
 * Tests the ability of the OperationProcessor handle a DataLogWriterNotPrimaryException.
 */
@Test
public void testWithDataLogNotPrimaryException() throws Exception {
    int streamSegmentCount = 1;
    int appendsPerStreamSegment = 1;
    @Cleanup TestContext context = new TestContext();
    // Generate some test data (no need to complicate ourselves with Transactions here; that is tested in the no-failure test).
    HashSet<Long> streamSegmentIds = createStreamSegmentsInMetadata(streamSegmentCount, context.metadata);
    List<Operation> operations = generateOperations(streamSegmentIds, new HashMap<>(), appendsPerStreamSegment, METADATA_CHECKPOINT_EVERY, false, false);
    // Setup an OperationProcessor and start it.
    @Cleanup TestDurableDataLog dataLog = TestDurableDataLog.create(CONTAINER_ID, MAX_DATA_LOG_APPEND_SIZE, executorService());
    dataLog.initialize(TIMEOUT);
    @Cleanup OperationProcessor operationProcessor = new OperationProcessor(context.metadata, context.stateUpdater, dataLog, getNoOpCheckpointPolicy(), executorService());
    operationProcessor.startAsync().awaitRunning();
    ErrorInjector<Exception> aSyncErrorInjector = new ErrorInjector<>(count -> true, () -> new CompletionException(new DataLogWriterNotPrimaryException("intentional")));
    dataLog.setAppendErrorInjectors(null, aSyncErrorInjector);
    // Process all generated operations.
    List<OperationWithCompletion> completionFutures = processOperations(operations, operationProcessor);
    // Wait for all such operations to complete. We are expecting exceptions, so verify that we do.
    AssertExtensions.assertThrows("No operations failed.", OperationWithCompletion.allOf(completionFutures)::join, ex -> ex instanceof IOException || ex instanceof DataLogWriterNotPrimaryException);
    // Verify that the OperationProcessor automatically shuts down and that it has the right failure cause.
    ServiceListeners.awaitShutdown(operationProcessor, TIMEOUT, false);
    Assert.assertEquals("OperationProcessor is not in a failed state after fence-out detected.", Service.State.FAILED, operationProcessor.state());
    Assert.assertTrue("OperationProcessor did not fail with the correct exception.", operationProcessor.failureCause() instanceof DataLogWriterNotPrimaryException);
}
Also used : DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) TestDurableDataLog(io.pravega.segmentstore.server.TestDurableDataLog) ErrorInjector(io.pravega.test.common.ErrorInjector) ProbeOperation(io.pravega.segmentstore.server.logs.operations.ProbeOperation) Operation(io.pravega.segmentstore.server.logs.operations.Operation) StorageOperation(io.pravega.segmentstore.server.logs.operations.StorageOperation) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) IOException(java.io.IOException) Cleanup(lombok.Cleanup) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) ObjectClosedException(io.pravega.common.ObjectClosedException) StreamSegmentException(io.pravega.segmentstore.contracts.StreamSegmentException) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) IntentionalException(io.pravega.test.common.IntentionalException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Aggregations

DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)4 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)3 Cleanup (lombok.Cleanup)3 Test (org.junit.Test)3 ObjectClosedException (io.pravega.common.ObjectClosedException)2 StreamSegmentException (io.pravega.segmentstore.contracts.StreamSegmentException)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)2 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)2 Operation (io.pravega.segmentstore.server.logs.operations.Operation)2 ProbeOperation (io.pravega.segmentstore.server.logs.operations.ProbeOperation)2 StorageOperation (io.pravega.segmentstore.server.logs.operations.StorageOperation)2 StreamSegmentAppendOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation)2 DataLogDisabledException (io.pravega.segmentstore.storage.DataLogDisabledException)2 DataLogNotAvailableException (io.pravega.segmentstore.storage.DataLogNotAvailableException)2 ErrorInjector (io.pravega.test.common.ErrorInjector)2 IntentionalException (io.pravega.test.common.IntentionalException)2 IOException (java.io.IOException)2 CancellationException (java.util.concurrent.CancellationException)2 CompletionException (java.util.concurrent.CompletionException)2 RetriesExhaustedException (io.pravega.common.util.RetriesExhaustedException)1