Search in sources :

Example 16 with DLInterruptedException

use of org.apache.distributedlog.exceptions.DLInterruptedException in project bookkeeper by apache.

the class ZKMetadataAccessor method createOrUpdateMetadata.

/**
 * Creates or update the metadata stored at the node associated with the
 * name and URI.
 * @param metadata opaque metadata to be stored for the node
 * @throws IOException
 */
@Override
public void createOrUpdateMetadata(byte[] metadata) throws IOException {
    checkClosedOrInError("createOrUpdateMetadata");
    String zkPath = getZKPath();
    LOG.debug("Setting application specific metadata on {}", zkPath);
    try {
        Stat currentStat = writerZKC.get().exists(zkPath, false);
        if (currentStat == null) {
            if (metadata.length > 0) {
                Utils.zkCreateFullPathOptimistic(writerZKC, zkPath, metadata, writerZKC.getDefaultACL(), CreateMode.PERSISTENT);
            }
        } else {
            writerZKC.get().setData(zkPath, metadata, currentStat.getVersion());
        }
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new DLInterruptedException("Interrupted on creating or updating container metadata", ie);
    } catch (Exception exc) {
        throw new IOException("Exception creating or updating container metadata", exc);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) IOException(java.io.IOException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) AlreadyClosedException(org.apache.distributedlog.exceptions.AlreadyClosedException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) IOException(java.io.IOException)

Example 17 with DLInterruptedException

use of org.apache.distributedlog.exceptions.DLInterruptedException in project bookkeeper by apache.

the class LedgerAllocatorPool method initializePool.

private void initializePool() throws IOException {
    try {
        List<String> allocators;
        try {
            allocators = zkc.get().getChildren(poolPath, false);
        } catch (KeeperException.NoNodeException e) {
            logger.info("Allocator Pool {} doesn't exist. Creating it.", poolPath);
            ZkUtils.createFullPathOptimistic(zkc.get(), poolPath, new byte[0], zkc.getDefaultACL(), CreateMode.PERSISTENT);
            allocators = zkc.get().getChildren(poolPath, false);
        }
        if (null == allocators) {
            allocators = new ArrayList<String>();
        }
        if (allocators.size() < corePoolSize) {
            createAllocators(corePoolSize - allocators.size());
            allocators = zkc.get().getChildren(poolPath, false);
        }
        initializeAllocators(allocators);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new DLInterruptedException("Interrupted when ensuring " + poolPath + " created : ", ie);
    } catch (KeeperException ke) {
        throw new IOException("Encountered zookeeper exception when initializing pool " + poolPath + " : ", ke);
    }
}
Also used : DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) IOException(java.io.IOException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)17 IOException (java.io.IOException)12 AsyncCallback (org.apache.zookeeper.AsyncCallback)6 Stat (org.apache.zookeeper.data.Stat)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)3 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)3 ZKException (org.apache.distributedlog.exceptions.ZKException)3 KeeperException (org.apache.zookeeper.KeeperException)3 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)2 BookkeeperInternalCallbacks (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks)2 ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)2 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)2