use of org.apache.bookkeeper.meta.exceptions.MetadataException in project bookkeeper by apache.
the class ZKMetadataDriverBase method initialize.
@SneakyThrows(InterruptedException.class)
protected void initialize(AbstractConfiguration<?> conf, StatsLogger statsLogger, RetryPolicy zkRetryPolicy, Optional<Object> optionalCtx) throws MetadataException {
this.conf = conf;
this.acls = ZkUtils.getACLs(conf);
if (optionalCtx.isPresent() && optionalCtx.get() instanceof ZooKeeper) {
this.ledgersRootPath = conf.getZkLedgersRootPath();
log.info("Initialize zookeeper metadata driver with external zookeeper client : ledgersRootPath = {}.", ledgersRootPath);
// if an external zookeeper is added, use the zookeeper instance
this.zk = (ZooKeeper) (optionalCtx.get());
this.ownZKHandle = false;
} else {
final String metadataServiceUriStr;
try {
metadataServiceUriStr = conf.getMetadataServiceUri();
} catch (ConfigurationException e) {
log.error("Failed to retrieve metadata service uri from configuration", e);
throw new MetadataException(Code.INVALID_METADATA_SERVICE_URI, e);
}
URI metadataServiceUri = URI.create(metadataServiceUriStr);
// get the initialize root path
this.ledgersRootPath = metadataServiceUri.getPath();
final String bookieRegistrationPath = ledgersRootPath + "/" + AVAILABLE_NODE;
final String bookieReadonlyRegistrationPath = bookieRegistrationPath + "/" + READONLY;
// construct the zookeeper
final String zkServers = getZKServersFromServiceUri(metadataServiceUri);
log.info("Initialize zookeeper metadata driver at metadata service uri {} :" + " zkServers = {}, ledgersRootPath = {}.", metadataServiceUriStr, zkServers, ledgersRootPath);
try {
this.zk = ZooKeeperClient.newBuilder().connectString(zkServers).sessionTimeoutMs(conf.getZkTimeout()).operationRetryPolicy(zkRetryPolicy).requestRateLimit(conf.getZkRequestRateLimit()).statsLogger(statsLogger).build();
if (null == zk.exists(bookieReadonlyRegistrationPath, false)) {
try {
zk.create(bookieReadonlyRegistrationPath, EMPTY_BYTE_ARRAY, acls, CreateMode.PERSISTENT);
} catch (KeeperException.NodeExistsException e) {
// this node is just now created by someone.
} catch (KeeperException.NoNodeException e) {
// the cluster hasn't been initialized
}
}
} catch (IOException | KeeperException e) {
log.error("Failed to create zookeeper client to {}", zkServers, e);
MetadataException me = new MetadataException(Code.METADATA_SERVICE_ERROR, "Failed to create zookeeper client to " + zkServers, e);
me.fillInStackTrace();
throw me;
}
this.ownZKHandle = true;
}
// once created the zookeeper client, create the layout manager and registration client
this.layoutManager = new ZkLayoutManager(zk, ledgersRootPath, acls);
}
use of org.apache.bookkeeper.meta.exceptions.MetadataException in project bookkeeper by apache.
the class Bookie method instantiateMetadataDriver.
/**
* Instantiate the metadata driver for the Bookie.
*/
private MetadataBookieDriver instantiateMetadataDriver(ServerConfiguration conf) throws BookieException {
try {
String metadataServiceUriStr = conf.getMetadataServiceUri();
if (null == metadataServiceUriStr) {
return null;
}
MetadataBookieDriver driver = MetadataDrivers.getBookieDriver(URI.create(metadataServiceUriStr));
driver.initialize(conf, () -> {
stateManager.forceToUnregistered();
// schedule a re-register operation
stateManager.registerBookie(false);
}, statsLogger);
return driver;
} catch (MetadataException me) {
throw new MetadataStoreException("Failed to initialize metadata bookie driver", me);
} catch (ConfigurationException e) {
throw new BookieIllegalOpException(e);
}
}
use of org.apache.bookkeeper.meta.exceptions.MetadataException in project bookkeeper by apache.
the class FileSystemUpgrade method upgrade.
public static void upgrade(ServerConfiguration conf) throws BookieException.UpgradeException, InterruptedException {
LOG.info("Upgrading...");
try {
runFunctionWithRegistrationManager(conf, rm -> {
try {
upgrade(conf, rm);
} catch (UpgradeException e) {
throw new UncheckedExecutionException(e.getMessage(), e);
}
return null;
});
} catch (MetadataException e) {
throw new UpgradeException(e);
} catch (ExecutionException e) {
throw new UpgradeException(e.getCause());
}
LOG.info("Done");
}
use of org.apache.bookkeeper.meta.exceptions.MetadataException in project bookkeeper by apache.
the class FileSystemUpgrade method rollback.
public static void rollback(ServerConfiguration conf) throws BookieException.UpgradeException, InterruptedException {
LOG.info("Rolling back upgrade...");
try {
runFunctionWithRegistrationManager(conf, rm -> {
try {
rollback(conf, rm);
} catch (UpgradeException e) {
throw new UncheckedExecutionException(e.getMessage(), e);
}
return null;
});
} catch (MetadataException e) {
throw new UpgradeException(e);
} catch (ExecutionException e) {
throw new UpgradeException(e.getCause());
}
LOG.info("Done");
}
Aggregations