Search in sources :

Example 1 with DataLogInitializationException

use of io.pravega.segmentstore.storage.DataLogInitializationException 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 DataLogInitializationException

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

the class BookKeeperLog method loadMetadata.

// endregion
// region Metadata Management
/**
 * Loads the metadata for the current log, as stored in ZooKeeper.
 *
 * @return A new LogMetadata object with the desired information, or null if no such node exists.
 * @throws DataLogInitializationException If an Exception (other than NoNodeException) occurred.
 */
@VisibleForTesting
LogMetadata loadMetadata() throws DataLogInitializationException {
    try {
        Stat storingStatIn = new Stat();
        byte[] serializedMetadata = this.zkClient.getData().storingStatIn(storingStatIn).forPath(this.logNodePath);
        LogMetadata result = LogMetadata.SERIALIZER.deserialize(serializedMetadata);
        result.withUpdateVersion(storingStatIn.getVersion());
        return result;
    } catch (KeeperException.NoNodeException nne) {
        // Node does not exist: this is the first time we are accessing this log.
        log.warn("{}: No ZNode found for path '{}{}'. This is OK if this is the first time accessing this log.", this.traceObjectId, this.zkClient.getNamespace(), this.logNodePath);
        return null;
    } catch (Exception ex) {
        throw new DataLogInitializationException(String.format("Unable to load ZNode contents for path '%s%s'.", this.zkClient.getNamespace(), this.logNodePath), ex);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException) 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) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ObjectClosedException (io.pravega.common.ObjectClosedException)2 RetriesExhaustedException (io.pravega.common.util.RetriesExhaustedException)2 DataLogDisabledException (io.pravega.segmentstore.storage.DataLogDisabledException)2 DataLogInitializationException (io.pravega.segmentstore.storage.DataLogInitializationException)2 DataLogNotAvailableException (io.pravega.segmentstore.storage.DataLogNotAvailableException)2 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)2 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)2 WriteFailureException (io.pravega.segmentstore.storage.WriteFailureException)2 WriteTooLongException (io.pravega.segmentstore.storage.WriteTooLongException)2 CancellationException (java.util.concurrent.CancellationException)2 BKException (org.apache.bookkeeper.client.BKException)2 KeeperException (org.apache.zookeeper.KeeperException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stat (org.apache.zookeeper.data.Stat)1