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