Search in sources :

Example 1 with MetadataException

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);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) URI(java.net.URI) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException) KeeperException(org.apache.zookeeper.KeeperException) ZkLayoutManager(org.apache.bookkeeper.meta.ZkLayoutManager) SneakyThrows(lombok.SneakyThrows)

Example 2 with MetadataException

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);
    }
}
Also used : MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MetadataBookieDriver(org.apache.bookkeeper.meta.MetadataBookieDriver) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException) BookieIllegalOpException(org.apache.bookkeeper.bookie.BookieException.BookieIllegalOpException)

Example 3 with MetadataException

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");
}
Also used : UpgradeException(org.apache.bookkeeper.bookie.BookieException.UpgradeException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException)

Example 4 with MetadataException

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");
}
Also used : UpgradeException(org.apache.bookkeeper.bookie.BookieException.UpgradeException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException)

Aggregations

MetadataException (org.apache.bookkeeper.meta.exceptions.MetadataException)4 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 ExecutionException (java.util.concurrent.ExecutionException)2 UpgradeException (org.apache.bookkeeper.bookie.BookieException.UpgradeException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 IOException (java.io.IOException)1 URI (java.net.URI)1 SneakyThrows (lombok.SneakyThrows)1 BookieIllegalOpException (org.apache.bookkeeper.bookie.BookieException.BookieIllegalOpException)1 MetadataStoreException (org.apache.bookkeeper.bookie.BookieException.MetadataStoreException)1 MetadataBookieDriver (org.apache.bookkeeper.meta.MetadataBookieDriver)1 ZkLayoutManager (org.apache.bookkeeper.meta.ZkLayoutManager)1 KeeperException (org.apache.zookeeper.KeeperException)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1