Search in sources :

Example 1 with CookieNotFoundException

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

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

the class ZKRegistrationManager method removeCookie.

@Override
public void removeCookie(String bookieId, Version version) throws BookieException {
    String zkPath = getCookiePath(bookieId);
    try {
        zk.delete(zkPath, (int) ((LongVersion) version).getLongVersion());
    } catch (NoNodeException e) {
        throw new CookieNotFoundException(bookieId);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new MetadataStoreException("Interrupted deleting cookie for bookie " + bookieId, e);
    } catch (KeeperException e) {
        throw new MetadataStoreException("Failed to delete cookie for bookie " + bookieId);
    }
    log.info("Removed cookie from {} for bookie {}.", cookiePath, bookieId);
}
Also used : MetadataStoreException(org.apache.bookkeeper.bookie.BookieException.MetadataStoreException) 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)

Aggregations

CookieNotFoundException (org.apache.bookkeeper.bookie.BookieException.CookieNotFoundException)2 MetadataStoreException (org.apache.bookkeeper.bookie.BookieException.MetadataStoreException)2 BKInterruptedException (org.apache.bookkeeper.client.BKException.BKInterruptedException)2 LongVersion (org.apache.bookkeeper.versioning.LongVersion)2 KeeperException (org.apache.zookeeper.KeeperException)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2 Versioned (org.apache.bookkeeper.versioning.Versioned)1 Stat (org.apache.zookeeper.data.Stat)1