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