Search in sources :

Example 6 with BKAuditException

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

the class Auditor method submitAuditTask.

@VisibleForTesting
synchronized Future<?> submitAuditTask() {
    if (executor.isShutdown()) {
        SettableFuture<Void> f = SettableFuture.<Void>create();
        f.setException(new BKAuditException("Auditor shutting down"));
        return f;
    }
    return executor.submit(new Runnable() {

        @SuppressWarnings("unchecked")
        public void run() {
            try {
                waitIfLedgerReplicationDisabled();
                int lostBookieRecoveryDelay = Auditor.this.ledgerUnderreplicationManager.getLostBookieRecoveryDelay();
                List<String> availableBookies = getAvailableBookies();
                // casting to String, as knownBookies and availableBookies
                // contains only String values
                // find new bookies(if any) and update the known bookie list
                Collection<String> newBookies = CollectionUtils.subtract(availableBookies, knownBookies);
                knownBookies.addAll(newBookies);
                if (!bookiesToBeAudited.isEmpty() && knownBookies.containsAll(bookiesToBeAudited)) {
                    // check should be ok
                    if (auditTask != null && auditTask.cancel(false)) {
                        auditTask = null;
                        numDelayedBookieAuditsCancelled.inc();
                    }
                    bookiesToBeAudited.clear();
                }
                // find lost bookies(if any)
                bookiesToBeAudited.addAll(CollectionUtils.subtract(knownBookies, availableBookies));
                if (bookiesToBeAudited.size() == 0) {
                    return;
                }
                knownBookies.removeAll(bookiesToBeAudited);
                if (lostBookieRecoveryDelay == 0) {
                    startAudit(false);
                    bookiesToBeAudited.clear();
                    return;
                }
                if (bookiesToBeAudited.size() > 1) {
                    // if more than one bookie is down, start the audit immediately;
                    LOG.info("Multiple bookie failure; not delaying bookie audit. " + "Bookies lost now: {}; All lost bookies: {}", CollectionUtils.subtract(knownBookies, availableBookies), bookiesToBeAudited);
                    if (auditTask != null && auditTask.cancel(false)) {
                        auditTask = null;
                        numDelayedBookieAuditsCancelled.inc();
                    }
                    startAudit(false);
                    bookiesToBeAudited.clear();
                    return;
                }
                if (auditTask == null) {
                    // if there is no scheduled audit, schedule one
                    auditTask = executor.schedule(new Runnable() {

                        public void run() {
                            startAudit(false);
                            auditTask = null;
                            bookiesToBeAudited.clear();
                        }
                    }, lostBookieRecoveryDelay, TimeUnit.SECONDS);
                    numBookieAuditsDelayed.inc();
                    LOG.info("Delaying bookie audit by {} secs for {}", lostBookieRecoveryDelay, bookiesToBeAudited);
                }
            } catch (BKException bke) {
                LOG.error("Exception getting bookie list", bke);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                LOG.error("Interrupted while watching available bookies ", ie);
            } catch (UnavailableException ue) {
                LOG.error("Exception while watching available bookies", ue);
            }
        }
    });
}
Also used : UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) BKException(org.apache.bookkeeper.client.BKException) BKAuditException(org.apache.bookkeeper.replication.ReplicationException.BKAuditException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BKAuditException (org.apache.bookkeeper.replication.ReplicationException.BKAuditException)6 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)5 ArrayList (java.util.ArrayList)3 Processor (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.Processor)3 AsyncCallback (org.apache.zookeeper.AsyncCallback)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)2 GenericCallback (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 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