wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1106822597


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorCheckAllLedgersTask.java:
##########
@@ -0,0 +1,286 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bookkeeper.replication;
+
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.LedgerChecker;
+import org.apache.bookkeeper.client.LedgerFragment;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.common.concurrent.FutureUtils;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.net.BookieId;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks;
+import 
org.apache.bookkeeper.replication.ReplicationException.UnavailableException;
+import org.apache.zookeeper.AsyncCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorCheckAllLedgersTask extends AuditorTask {
+    private static final Logger LOG = 
LoggerFactory.getLogger(AuditorBookieCheckTask.class);
+
+    private final Semaphore openLedgerNoRecoverySemaphore;
+    private final int openLedgerNoRecoverySemaphoreWaitTimeoutMSec;
+    private final ExecutorService ledgerCheckerExecutor;
+
+    AuditorCheckAllLedgersTask(ServerConfiguration conf,
+                               AuditorStats auditorStats,
+                               BookKeeperAdmin admin,
+                               LedgerManager ledgerManager,
+                               LedgerUnderreplicationManager 
ledgerUnderreplicationManager,
+                               ShutdownTaskHandler shutdownTaskHandler)
+            throws UnavailableException {
+        super(conf, auditorStats, admin, ledgerManager,
+                ledgerUnderreplicationManager, shutdownTaskHandler);
+
+        if (conf.getAuditorMaxNumberOfConcurrentOpenLedgerOperations() <= 0) {
+            LOG.error("auditorMaxNumberOfConcurrentOpenLedgerOperations should 
be greater than 0");
+            throw new 
UnavailableException("auditorMaxNumberOfConcurrentOpenLedgerOperations should 
be greater than 0");
+        }
+        this.openLedgerNoRecoverySemaphore =
+                new 
Semaphore(conf.getAuditorMaxNumberOfConcurrentOpenLedgerOperations());
+
+        if (conf.getAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec() 
< 0) {
+            LOG.error("auditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec 
should be greater than or equal to 0");
+            throw new 
UnavailableException("auditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec "
+                    + "should be greater than or equal to 0");
+        }
+        this.openLedgerNoRecoverySemaphoreWaitTimeoutMSec =
+                
conf.getAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec();
+
+        this.ledgerCheckerExecutor = Executors.newSingleThreadExecutor(new 
ThreadFactory() {
+            @Override
+            public Thread newThread(Runnable r) {
+                Thread t = new Thread(r, 
"AuditorCheckAllLedgers-LedgerChecker");
+                t.setDaemon(true);
+                return t;
+            }
+        });
+    }
+
+    @Override
+    protected void runTask() {
+        Stopwatch stopwatch = Stopwatch.createStarted();
+        boolean checkSuccess = false;
+        try {
+            if (!isLedgerReplicationEnabled()) {
+                LOG.info("Ledger replication disabled, skipping 
checkAllLedgers");
+                return;
+            }
+
+            LOG.info("Starting checkAllLedgers");
+            checkAllLedgers();
+            long checkAllLedgersDuration = 
stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+            LOG.info("Completed checkAllLedgers in {} milliSeconds", 
checkAllLedgersDuration);
+            auditorStats.getCheckAllLedgersTime()
+                    .registerSuccessfulEvent(checkAllLedgersDuration, 
TimeUnit.MILLISECONDS);
+            checkSuccess = true;
+        } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+            LOG.error("Interrupted while running periodic check", ie);
+        } catch (BKException bke) {
+            LOG.error("Exception running periodic check", bke);
+        } catch (IOException ioe) {
+            LOG.error("I/O exception running periodic check", ioe);
+        } catch (ReplicationException.NonRecoverableReplicationException nre) {
+            LOG.error("Non Recoverable Exception while reading from ZK", nre);
+            submitShutdownTask();
+            submitShutdownTask();

Review Comment:
   Good catch. I have fixed it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to