Search in sources :

Example 1 with MetadataStoreException

use of org.apache.bookkeeper.bookie.BookieException.MetadataStoreException 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 2 with MetadataStoreException

use of org.apache.bookkeeper.bookie.BookieException.MetadataStoreException in project bookkeeper by apache.

the class ZKRegistrationManager method readCookie.

@Override
public Versioned<byte[]> readCookie(String bookieId) throws BookieException {
    String zkPath = getCookiePath(bookieId);
    try {
        Stat stat = zk.exists(zkPath, false);
        byte[] data = zk.getData(zkPath, false, stat);
        // sets stat version from ZooKeeper
        LongVersion version = new LongVersion(stat.getVersion());
        return new Versioned<>(data, version);
    } catch (NoNodeException nne) {
        throw new CookieNotFoundException(bookieId);
    } catch (KeeperException | InterruptedException e) {
        throw new MetadataStoreException("Failed to read cookie for bookie " + bookieId);
    }
}
Also used : MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) Stat(org.apache.zookeeper.data.Stat) Versioned(org.apache.bookkeeper.versioning.Versioned) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) LongVersion(org.apache.bookkeeper.versioning.LongVersion) CookieNotFoundException(org.apache.bookkeeper.bookie.BookieException.CookieNotFoundException) BKInterruptedException(org.apache.bookkeeper.client.BKException.BKInterruptedException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with MetadataStoreException

use of org.apache.bookkeeper.bookie.BookieException.MetadataStoreException in project bookkeeper by apache.

the class ZKRegistrationManager method getClusterInstanceId.

@Override
public String getClusterInstanceId() throws BookieException {
    String instanceId = null;
    try {
        if (zk.exists(ledgersRootPath, null) == null) {
            log.error("BookKeeper metadata doesn't exist in zookeeper. " + "Has the cluster been initialized? " + "Try running bin/bookkeeper shell metaformat");
            throw new KeeperException.NoNodeException("BookKeeper metadata");
        }
        try {
            byte[] data = zk.getData(ledgersRootPath + "/" + INSTANCEID, false, null);
            instanceId = new String(data, UTF_8);
        } catch (KeeperException.NoNodeException e) {
            log.info("INSTANCEID not exists in zookeeper. Not considering it for data verification");
        }
    } catch (KeeperException | InterruptedException e) {
        throw new MetadataStoreException("Failed to get cluster instance id", e);
    }
    return instanceId;
}
Also used : MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) BKInterruptedException(org.apache.bookkeeper.client.BKException.BKInterruptedException) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with MetadataStoreException

use of org.apache.bookkeeper.bookie.BookieException.MetadataStoreException in project bookkeeper by apache.

the class ZKRegistrationManager method isBookieRegistered.

@Override
public boolean isBookieRegistered(String bookieId) throws BookieException {
    String regPath = bookieRegistrationPath + "/" + bookieId;
    String readonlyRegPath = bookieReadonlyRegistrationPath + "/" + bookieId;
    try {
        return ((null != zk.exists(regPath, false)) || (null != zk.exists(readonlyRegPath, false)));
    } catch (KeeperException e) {
        log.error("ZK exception while checking registration ephemeral znodes for BookieId: {}", bookieId, e);
        throw new MetadataStoreException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        log.error("InterruptedException while checking registration ephemeral znodes for BookieId: {}", bookieId, e);
        throw new MetadataStoreException(e);
    }
}
Also used : MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) BKInterruptedException(org.apache.bookkeeper.client.BKException.BKInterruptedException) KeeperException(org.apache.zookeeper.KeeperException)

Example 5 with MetadataStoreException

use of org.apache.bookkeeper.bookie.BookieException.MetadataStoreException in project bookkeeper by apache.

the class BookieInitializationTest method testExitCodeZK_REG_FAIL.

/**
 * Verify the bookie server exit code. On ZooKeeper exception, should return
 * exit code ZK_REG_FAIL = 4
 */
@Test
public void testExitCodeZK_REG_FAIL() throws Exception {
    File tmpDir = createTempDir("bookie", "test");
    final ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setJournalDirName(tmpDir.getPath()).setLedgerDirNames(new String[] { tmpDir.getPath() }).setZkServers(zkUtil.getZooKeeperConnectString());
    RegistrationManager rm = mock(RegistrationManager.class);
    doThrow(new MetadataStoreException("mocked exception")).when(rm).registerBookie(anyString(), anyBoolean());
    // simulating ZooKeeper exception by assigning a closed zk client to bk
    BookieServer bkServer = new BookieServer(conf) {

        protected Bookie newBookie(ServerConfiguration conf) throws IOException, KeeperException, InterruptedException, BookieException {
            Bookie bookie = new Bookie(conf);
            MetadataBookieDriver driver = Whitebox.getInternalState(bookie, "metadataDriver");
            ((ZKMetadataBookieDriver) driver).setRegManager(rm);
            return bookie;
        }
    };
    bkServer.start();
    bkServer.join();
    assertEquals("Failed to return ExitCode.ZK_REG_FAIL", ExitCode.ZK_REG_FAIL, bkServer.getExitCode());
}
Also used : RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) ZKMetadataBookieDriver(org.apache.bookkeeper.meta.zk.ZKMetadataBookieDriver) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ZKMetadataBookieDriver(org.apache.bookkeeper.meta.zk.ZKMetadataBookieDriver) MetadataBookieDriver(org.apache.bookkeeper.meta.MetadataBookieDriver) BookieServer(org.apache.bookkeeper.proto.BookieServer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) Test(org.junit.Test)

Aggregations

MetadataStoreException (org.apache.bookkeeper.bookie.BookieException.MetadataStoreException)8 BKInterruptedException (org.apache.bookkeeper.client.BKException.BKInterruptedException)6 KeeperException (org.apache.zookeeper.KeeperException)6 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)4 CookieNotFoundException (org.apache.bookkeeper.bookie.BookieException.CookieNotFoundException)2 MetadataBookieDriver (org.apache.bookkeeper.meta.MetadataBookieDriver)2 LongVersion (org.apache.bookkeeper.versioning.LongVersion)2 File (java.io.File)1 IOException (java.io.IOException)1 BookieIllegalOpException (org.apache.bookkeeper.bookie.BookieException.BookieIllegalOpException)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 RegistrationManager (org.apache.bookkeeper.discover.RegistrationManager)1 MetadataException (org.apache.bookkeeper.meta.exceptions.MetadataException)1 ZKMetadataBookieDriver (org.apache.bookkeeper.meta.zk.ZKMetadataBookieDriver)1 BookieServer (org.apache.bookkeeper.proto.BookieServer)1 Versioned (org.apache.bookkeeper.versioning.Versioned)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)1 Stat (org.apache.zookeeper.data.Stat)1 Test (org.junit.Test)1