hangc0276 commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1106590835
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -144,140 +78,18 @@ public class Auditor implements AutoCloseable {
private LedgerManager ledgerManager;
private LedgerUnderreplicationManager ledgerUnderreplicationManager;
private final ScheduledExecutorService executor;
- private final ExecutorService ledgerCheckerExecutor;
private List<String> knownBookies = new ArrayList<String>();
private final String bookieIdentifier;
- private volatile Future<?> auditTask;
+ protected volatile Future<?> auditTask;
private Set<String> bookiesToBeAudited = Sets.newHashSet();
Review Comment:
Make it `final`?
##########
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:
remove the duplicated `submitShutdownTask()`?
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorStats.java:
##########
@@ -0,0 +1,294 @@
+/**
+ * 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 static org.apache.bookkeeper.replication.ReplicationStats.AUDITOR_SCOPE;
+import static
org.apache.bookkeeper.replication.ReplicationStats.AUDIT_BOOKIES_TIME;
+import static
org.apache.bookkeeper.replication.ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME;
+import static
org.apache.bookkeeper.replication.ReplicationStats.CHECK_ALL_LEDGERS_TIME;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_BOOKIES_PER_LEDGER;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_FRAGMENTS_PER_LEDGER;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_LEDGERS_CHECKED;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_REPLICATED_LEDGERS;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS;
+import static
org.apache.bookkeeper.replication.ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS_GUAGE;
+import static
org.apache.bookkeeper.replication.ReplicationStats.PLACEMENT_POLICY_CHECK_TIME;
+import static
org.apache.bookkeeper.replication.ReplicationStats.REPLICAS_CHECK_TIME;
+import static
org.apache.bookkeeper.replication.ReplicationStats.UNDER_REPLICATED_LEDGERS_TOTAL_SIZE;
+import static
org.apache.bookkeeper.replication.ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import lombok.Getter;
+import org.apache.bookkeeper.stats.Counter;
+import org.apache.bookkeeper.stats.Gauge;
+import org.apache.bookkeeper.stats.OpStatsLogger;
+import org.apache.bookkeeper.stats.StatsLogger;
+import org.apache.bookkeeper.stats.annotations.StatsDoc;
+
+@StatsDoc(
+ name = AUDITOR_SCOPE,
+ help = "Auditor related stats"
+)
+@Getter
+public class AuditorStats {
+
+ private final AtomicInteger ledgersNotAdheringToPlacementPolicyGuageValue;
+ private final AtomicInteger
ledgersSoftlyAdheringToPlacementPolicyGuageValue;
+ private final AtomicInteger
numOfURLedgersElapsedRecoveryGracePeriodGuageValue;
+ private final AtomicInteger numLedgersHavingNoReplicaOfAnEntryGuageValue;
+ private final AtomicInteger
numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue;
+ private final AtomicInteger
numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue;
+ private final AtomicInteger underReplicatedLedgersGuageValue;
+ private final StatsLogger statsLogger;
Review Comment:
We can remove this field due to it was never used outside the constructor
--
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]