Search in sources :

Example 1 with CompatibilityException

use of org.apache.bookkeeper.replication.ReplicationException.CompatibilityException in project bookkeeper by apache.

the class Auditor method initialize.

private void initialize(ServerConfiguration conf, ZooKeeper zkc) throws UnavailableException {
    try {
        ClientConfiguration clientConfiguration = new ClientConfiguration(conf);
        clientConfiguration.setClientRole(ClientConfiguration.CLIENT_ROLE_SYSTEM);
        LOG.info("AuthProvider used by the Auditor is {}", clientConfiguration.getClientAuthProviderFactoryClass());
        this.bkc = new BookKeeper(clientConfiguration, zkc);
        LedgerManagerFactory ledgerManagerFactory = AbstractZkLedgerManagerFactory.newLedgerManagerFactory(conf, bkc.getMetadataClientDriver().getLayoutManager());
        ledgerManager = ledgerManagerFactory.newLedgerManager();
        this.bookieLedgerIndexer = new BookieLedgerIndexer(ledgerManager);
        this.ledgerUnderreplicationManager = ledgerManagerFactory.newLedgerUnderreplicationManager();
        this.admin = new BookKeeperAdmin(bkc, statsLogger);
        if (this.ledgerUnderreplicationManager.initializeLostBookieRecoveryDelay(conf.getLostBookieRecoveryDelay())) {
            LOG.info("Initializing lostBookieRecoveryDelay zNode to the conif value: {}", conf.getLostBookieRecoveryDelay());
        } else {
            LOG.info("Valid lostBookieRecoveryDelay zNode is available, so not creating " + "lostBookieRecoveryDelay zNode as part of Auditor initialization ");
        }
        lostBookieRecoveryDelayBeforeChange = this.ledgerUnderreplicationManager.getLostBookieRecoveryDelay();
    } catch (CompatibilityException ce) {
        throw new UnavailableException("CompatibilityException while initializing Auditor", ce);
    } catch (IOException | BKException | KeeperException ioe) {
        throw new UnavailableException("Exception while initializing Auditor", ioe);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new UnavailableException("Interrupted while initializing Auditor", ie);
    }
}
Also used : CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) BookKeeper(org.apache.bookkeeper.client.BookKeeper) BKException(org.apache.bookkeeper.client.BKException) IOException(java.io.IOException) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory) AbstractZkLedgerManagerFactory(org.apache.bookkeeper.meta.AbstractZkLedgerManagerFactory) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with CompatibilityException

use of org.apache.bookkeeper.replication.ReplicationException.CompatibilityException in project bookkeeper by apache.

the class BookKeeperAdmin method decommissionBookie.

/**
 * Triggers AuditTask by resetting lostBookieRecoveryDelay and then make
 * sure the ledgers stored in the given decommissioning bookie are properly
 * replicated and they are not underreplicated because of the given bookie.
 * This method waits untill there are no underreplicatedledgers because of this
 * bookie. If the given Bookie is not shutdown yet, then it will throw
 * BKIllegalOpException.
 *
 * @param bookieAddress
 *            address of the decommissioning bookie
 * @throws CompatibilityException
 * @throws UnavailableException
 * @throws KeeperException
 * @throws InterruptedException
 * @throws IOException
 * @throws BKAuditException
 * @throws TimeoutException
 * @throws BKException
 */
public void decommissionBookie(BookieSocketAddress bookieAddress) throws CompatibilityException, UnavailableException, KeeperException, InterruptedException, IOException, BKAuditException, TimeoutException, BKException {
    if (getAvailableBookies().contains(bookieAddress) || getReadOnlyBookies().contains(bookieAddress)) {
        LOG.error("Bookie: {} is not shutdown yet", bookieAddress);
        throw BKException.create(BKException.Code.IllegalOpException);
    }
    triggerAudit();
    /*
         * Sleep for 30 secs, so that Auditor gets chance to trigger its
         * force audittask and let the underreplicationmanager process
         * to do its replication process
         */
    Thread.sleep(30 * 1000);
    /*
         * get the collection of the ledgers which are stored in this
         * bookie, by making a call to
         * bookieLedgerIndexer.getBookieToLedgerIndex.
         */
    BookieLedgerIndexer bookieLedgerIndexer = new BookieLedgerIndexer(bkc.ledgerManager);
    Map<String, Set<Long>> bookieToLedgersMap = bookieLedgerIndexer.getBookieToLedgerIndex();
    Set<Long> ledgersStoredInThisBookie = bookieToLedgersMap.get(bookieAddress.toString());
    if ((ledgersStoredInThisBookie != null) && (!ledgersStoredInThisBookie.isEmpty())) {
        /*
             * wait untill all the ledgers are replicated to other
             * bookies by making sure that these ledgers metadata don't
             * contain this bookie as part of their ensemble.
             */
        waitForLedgersToBeReplicated(ledgersStoredInThisBookie, bookieAddress, bkc.ledgerManager);
    }
    // for double-checking, check if any ledgers are listed as underreplicated because of this bookie
    Predicate<List<String>> predicate = replicasList -> replicasList.contains(bookieAddress.toString());
    Iterator<Long> urLedgerIterator = underreplicationManager.listLedgersToRereplicate(predicate);
    if (urLedgerIterator.hasNext()) {
        // if there are any then wait and make sure those ledgers are replicated properly
        LOG.info("Still in some underreplicated ledgers metadata, this bookie is part of its ensemble. " + "Have to make sure that those ledger fragments are rereplicated");
        List<Long> urLedgers = new ArrayList<>();
        urLedgerIterator.forEachRemaining(urLedgers::add);
        waitForLedgersToBeReplicated(urLedgers, bookieAddress, bkc.ledgerManager);
    }
}
Also used : Enumeration(java.util.Enumeration) OpenCallback(org.apache.bookkeeper.client.AsyncCallback.OpenCallback) GenericCallback(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) RegistrationListener(org.apache.bookkeeper.discover.RegistrationClient.RegistrationListener) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SingleFragmentCallback(org.apache.bookkeeper.client.LedgerFragmentReplicator.SingleFragmentCallback) Map(java.util.Map) BKAuditException(org.apache.bookkeeper.replication.ReplicationException.BKAuditException) BookieException(org.apache.bookkeeper.bookie.BookieException) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) AuditorElector(org.apache.bookkeeper.replication.AuditorElector) BookieLedgerIndexer(org.apache.bookkeeper.replication.BookieLedgerIndexer) LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Sets(com.google.common.collect.Sets) List(java.util.List) Entry(java.util.Map.Entry) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) Optional(java.util.Optional) MetadataDrivers.runFunctionWithRegistrationManager(org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithRegistrationManager) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) SortedMap(java.util.SortedMap) MultiCallback(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.MultiCallback) LedgerRangeIterator(org.apache.bookkeeper.meta.LedgerManager.LedgerRangeIterator) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Processor(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.Processor) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) RecoverCallback(org.apache.bookkeeper.client.AsyncCallback.RecoverCallback) SyncReadCallback(org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Bookie(org.apache.bookkeeper.bookie.Bookie) MetadataDrivers.runFunctionWithMetadataBookieDriver(org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithMetadataBookieDriver) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) KeeperException(org.apache.zookeeper.KeeperException) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) SyncOpenCallback(org.apache.bookkeeper.client.SyncCallbackUtils.SyncOpenCallback) File(java.io.File) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ExecutionException(java.util.concurrent.ExecutionException) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory) IOUtils(org.apache.bookkeeper.util.IOUtils) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) AsyncCallback(org.apache.zookeeper.AsyncCallback) AbstractFuture(com.google.common.util.concurrent.AbstractFuture) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) BookieLedgerIndexer(org.apache.bookkeeper.replication.BookieLedgerIndexer) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 3 with CompatibilityException

use of org.apache.bookkeeper.replication.ReplicationException.CompatibilityException in project bookkeeper by apache.

the class BookKeeperClusterTestCase method startBookie.

/**
 * Helper method to startup a bookie server using a configuration object.
 * Also, starts the auto recovery process if isAutoRecoveryEnabled is true.
 *
 * @param conf
 *            Server Configuration Object
 */
protected BookieServer startBookie(ServerConfiguration conf) throws Exception {
    TestStatsProvider provider = new TestStatsProvider();
    BookieServer server = new BookieServer(conf, provider.getStatsLogger(""));
    BookieSocketAddress address = Bookie.getBookieAddress(conf);
    bsLoggers.put(address, provider);
    if (bkc == null) {
        bkc = new BookKeeperTestClient(baseClientConf, new TestStatsProvider());
    }
    Future<?> waitForBookie = conf.isForceReadOnlyBookie() ? bkc.waitForReadOnlyBookie(address) : bkc.waitForWritableBookie(address);
    server.start();
    waitForBookie.get(30, TimeUnit.SECONDS);
    LOG.info("New bookie '{}' has been created.", address);
    try {
        startAutoRecovery(server, conf);
    } catch (CompatibilityException ce) {
        LOG.error("Exception while starting AutoRecovery!", ce);
    } catch (UnavailableException ue) {
        LOG.error("Exception while starting AutoRecovery!", ue);
    }
    return server;
}
Also used : CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BookieServer(org.apache.bookkeeper.proto.BookieServer) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) BookKeeperTestClient(org.apache.bookkeeper.client.BookKeeperTestClient)

Example 4 with CompatibilityException

use of org.apache.bookkeeper.replication.ReplicationException.CompatibilityException in project bookkeeper by apache.

the class BookKeeperClusterTestCase method startBookie.

/**
 * Start a bookie with the given bookie instance. Also, starts the auto
 * recovery for this bookie, if isAutoRecoveryEnabled is true.
 */
protected BookieServer startBookie(ServerConfiguration conf, final Bookie b) throws Exception {
    TestStatsProvider provider = new TestStatsProvider();
    BookieServer server = new BookieServer(conf, provider.getStatsLogger("")) {

        @Override
        protected Bookie newBookie(ServerConfiguration conf) {
            return b;
        }
    };
    BookieSocketAddress address = Bookie.getBookieAddress(conf);
    if (bkc == null) {
        bkc = new BookKeeperTestClient(baseClientConf, new TestStatsProvider());
    }
    Future<?> waitForBookie = conf.isForceReadOnlyBookie() ? bkc.waitForReadOnlyBookie(address) : bkc.waitForWritableBookie(address);
    server.start();
    bsLoggers.put(server.getLocalAddress(), provider);
    waitForBookie.get(30, TimeUnit.SECONDS);
    LOG.info("New bookie '{}' has been created.", address);
    try {
        startAutoRecovery(server, conf);
    } catch (CompatibilityException ce) {
        LOG.error("Exception while starting AutoRecovery!", ce);
    } catch (UnavailableException ue) {
        LOG.error("Exception while starting AutoRecovery!", ue);
    }
    return server;
}
Also used : CompatibilityException(org.apache.bookkeeper.replication.ReplicationException.CompatibilityException) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) BookKeeperTestClient(org.apache.bookkeeper.client.BookKeeperTestClient)

Aggregations

CompatibilityException (org.apache.bookkeeper.replication.ReplicationException.CompatibilityException)4 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)4 IOException (java.io.IOException)2 BookKeeperTestClient (org.apache.bookkeeper.client.BookKeeperTestClient)2 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 LedgerManagerFactory (org.apache.bookkeeper.meta.LedgerManagerFactory)2 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)2 BookieServer (org.apache.bookkeeper.proto.BookieServer)2 KeeperException (org.apache.zookeeper.KeeperException)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 AbstractFuture (com.google.common.util.concurrent.AbstractFuture)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1