You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/11/14 08:50:16 UTC
[GitHub] [bookkeeper] wenbingshen opened a new pull request, #3637: [improvement] Refactor Auditor to simplify the readability
wenbingshen opened a new pull request, #3637:
URL: https://github.com/apache/bookkeeper/pull/3637
### Motivation
Fix #3636
See explanation in #3636
### Changes
Auditor class: Only reserved to do some necessary initialization work, scheduling of various detection tasks
Separate monitoring metrics into AuditorStats
Separate the auditBookies task to the AuditorBookieCheckTask
Separate the checkAllLedgers task into the AuditorCheckAllLedgersTask
Separate placementPolicyCheck task into AuditorPlacementPolicyCheckTask
Separate replicasCheck to AuditorReplicasCheckTask
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102236736
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -343,167 +154,43 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
-
- 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.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
+ this.auditorStats = new AuditorStats(statsLogger);
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
- executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ ledgerCheckerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
Review Comment:
We can define and initialize it in AuditorCheckAllLedgersTask. And add an abstract method `shutdown()` in the AuditorTask, if we need to do some resource cleaning, we can override the shutdown(). In Auditor shutdown(), to invoke task.shutdown();
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102250009
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorCheckAllLedgersTaskTest.java:
##########
@@ -0,0 +1,118 @@
+/**
+ * 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.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerManagerFactory;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.apache.bookkeeper.test.TestStatsProvider;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit test {@link AuditorCheckAllLedgersTask}.
+ */
+public class AuditorCheckAllLedgersTaskTest extends BookKeeperClusterTestCase {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(AuditorCheckAllLedgersTaskTest.class);
+
+ private static final int maxNumberOfConcurrentOpenLedgerOperations = 500;
+ private static final int acquireConcurrentOpenLedgerOperationsTimeoutMSec = 120000;
+
+ private BookKeeperAdmin admin;
+ private LedgerManager ledgerManager;
+ private LedgerUnderreplicationManager ledgerUnderreplicationManager;
+
+ public AuditorCheckAllLedgersTaskTest() {
+ super(3);
+ baseConf.setPageLimit(1);
+ baseConf.setAutoRecoveryDaemonEnabled(false);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final BookKeeper bookKeeper = new BookKeeper(baseClientConf);
+ admin = new BookKeeperAdmin(bookKeeper, NullStatsLogger.INSTANCE, new ClientConfiguration(baseClientConf));
+ LedgerManagerFactory ledgerManagerFactory = bookKeeper.getLedgerManagerFactory();
+ ledgerManager = ledgerManagerFactory.newLedgerManager();
+ ledgerUnderreplicationManager = ledgerManagerFactory.newLedgerUnderreplicationManager();
+ baseConf.setAuditorMaxNumberOfConcurrentOpenLedgerOperations(maxNumberOfConcurrentOpenLedgerOperations);
+ baseConf.setAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec(
+ acquireConcurrentOpenLedgerOperationsTimeoutMSec);
+ }
+
+ @Test
+ public void testCheckAllLedgers() throws Exception {
+ // 1. create ledgers
+ final int numLedgers = 10;
+ List<Long> ids = new LinkedList<Long>();
+ for (int i = 0; i < numLedgers; i++) {
+ LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
+ ids.add(lh.getId());
+ for (int j = 0; j < 2; j++) {
+ lh.addEntry("testdata".getBytes());
+ }
+ lh.close();
+ }
+
+ // 2. init CheckAllLedgersTask
+ final TestStatsProvider statsProvider = new TestStatsProvider();
+ final TestStatsProvider.TestStatsLogger statsLogger = statsProvider.getStatsLogger(AUDITOR_SCOPE);
+ final AuditorStats auditorStats = new AuditorStats(statsLogger);
+
+ ExecutorService ledgerCheckerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r, "LedgerChecker-test");
+ t.setDaemon(true);
+ return t;
+ }
+ });
+
+ AuditorCheckAllLedgersTask auditorCheckAllLedgersTask = new AuditorCheckAllLedgersTask(
+ baseConf, auditorStats, admin, ledgerManager,
+ ledgerUnderreplicationManager, null, ledgerCheckerExecutor);
+
+ // 3. checkAllLedgers
+ auditorCheckAllLedgersTask.runTask();
+
+ // 4. verify
+ assertEquals("CHECK_ALL_LEDGERS_TIME", 1, ((TestStatsProvider.TestOpStatsLogger) statsLogger
+ .getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME)).getSuccessCount());
+ assertEquals("", numLedgers,
Review Comment:
The first param is an empty string.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102372744
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPlacementPolicyCheckTaskTest.java:
##########
@@ -0,0 +1,102 @@
+/**
+ * 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.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerManagerFactory;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.apache.bookkeeper.test.TestStatsProvider;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit test {@link AuditorPlacementPolicyCheckTask}.
+ */
+public class AuditorPlacementPolicyCheckTaskTest extends BookKeeperClusterTestCase {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(AuditorPlacementPolicyCheckTaskTest.class);
+
+ private BookKeeperAdmin admin;
+ private LedgerManager ledgerManager;
+ private LedgerUnderreplicationManager ledgerUnderreplicationManager;
+
+ public AuditorPlacementPolicyCheckTaskTest() {
+ super(3);
+ baseConf.setPageLimit(1);
+ baseConf.setAutoRecoveryDaemonEnabled(false);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final BookKeeper bookKeeper = new BookKeeper(baseClientConf);
+ admin = new BookKeeperAdmin(bookKeeper, NullStatsLogger.INSTANCE, new ClientConfiguration(baseClientConf));
+ LedgerManagerFactory ledgerManagerFactory = bookKeeper.getLedgerManagerFactory();
+ ledgerManager = ledgerManagerFactory.newLedgerManager();
+ ledgerUnderreplicationManager = ledgerManagerFactory.newLedgerUnderreplicationManager();
+ }
+
+ @Test
+ public void testPlacementPolicyCheck() throws BKException, InterruptedException {
+
+ // 1. create ledgers
+ final int numLedgers = 10;
+ List<Long> ids = new LinkedList<Long>();
+ for (int i = 0; i < numLedgers; i++) {
+ LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
+ ids.add(lh.getId());
+ for (int j = 0; j < 2; j++) {
+ lh.addEntry("testdata".getBytes());
+ }
+ lh.close();
+ }
+
+ // 2. init auditorPlacementPolicyCheckTask
+ final TestStatsProvider statsProvider = new TestStatsProvider();
+ final TestStatsProvider.TestStatsLogger statsLogger = statsProvider.getStatsLogger(AUDITOR_SCOPE);
+ final AuditorStats auditorStats = new AuditorStats(statsLogger);
+
+ AuditorPlacementPolicyCheckTask auditorPlacementPolicyCheckTask = new AuditorPlacementPolicyCheckTask(
+ baseConf, auditorStats, admin, ledgerManager,
+ ledgerUnderreplicationManager, null);
+
+ // 3. placementPolicyCheck
+ auditorPlacementPolicyCheckTask.runTask();
+
+ // 4. verify
+ assertEquals("PLACEMENT_POLICY_CHECK_TIME", 1, ((TestStatsProvider.TestOpStatsLogger)
+ statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME)).getSuccessCount());
+ assertEquals("numOfClosedLedgersAuditedInPlacementPolicyCheck",
+ numLedgers,
+ auditorPlacementPolicyCheckTask.getNumOfClosedLedgersAuditedInPlacementPolicyCheck().get());
Review Comment:
addressed done.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1324441350
> I hope my comment makes sense and it can be made even better.
@dlg99 Thanks for all your comments. The comments make a lot of sense, I'll try to perfect the whole PR.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1023458552
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -587,7 +270,7 @@ synchronized Future<?> submitAuditTask() {
knownBookies.removeAll(bookiesToBeAudited);
if (lostBookieRecoveryDelay == 0) {
- startAudit(false);
+ newAuditorBookieCheckTask().startAudit(false);
Review Comment:
@hangc0276 May be we can use netty Recycler. But I don't think a large number of AuditorTasks will be created in a short period of time, because the inspection tasks are executed periodically, most of them are once a day, and these instances can be recycled by the GC as soon as possible.
If you feel strongly about this, I can add.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098601632
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -341,155 +153,48 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
+ this.auditorStats = new AuditorStats(statsLogger);
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());
+ Semaphore 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 =
+ int openLedgerNoRecoverySemaphoreWaitTimeoutMSec =
conf.getAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec();
- this.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
-
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
+ AuditorTask.ShutdownTaskHandler shutdownTaskHandler = this::submitShutdownTask;
+ AuditorTask.SubmitTaskHandler submitBookieCheckTaskHandler = this::submitBookieCheckTask;
Review Comment:
I suggest keeping TaskHandler in AuditorTask, other tasks may introduce some TaskHandler in the future or expand some other tasks in the future
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1418473600
@horizonzy Please help take a look, thanks.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
hangc0276 commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1022962993
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorReplicasCheckTask.java:
##########
@@ -0,0 +1,750 @@
+/**
+ * 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.HashMultiset;
+import com.google.common.collect.Multiset;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BiConsumer;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.RoundRobinDistributionSchedule;
+import org.apache.bookkeeper.client.api.LedgerMetadata;
+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.util.AvailabilityOfEntriesOfLedger;
+import org.apache.bookkeeper.versioning.Versioned;
+import org.apache.zookeeper.AsyncCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorReplicasCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorReplicasCheckTask.class);
+
+ private static final int MAX_CONCURRENT_REPLICAS_CHECK_LEDGER_REQUESTS = 100;
+ private static final int REPLICAS_CHECK_TIMEOUT_IN_SECS = 120;
+ private static final BitSet EMPTY_BITSET = new BitSet();
+
+ private final int zkOpTimeoutMs;
+
+ AuditorReplicasCheckTask(Auditor auditor,
+ ServerConfiguration conf,
+ AuditorStats auditorStats, BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ Auditor.ShutdownTaskHandler shutdownTaskHandler) {
+ super(auditor, conf, auditorStats, admin, ledgerManager, ledgerUnderreplicationManager, shutdownTaskHandler);
+ this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
+ }
+
+ @Override
+ protected void runTask() {
+ try {
+ if (!ledgerUnderreplicationManager.isLedgerReplicationEnabled()) {
+ LOG.info("Ledger replication disabled, skipping replicasCheck task.");
+ return;
+ }
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ LOG.info("Starting ReplicasCheck");
+ replicasCheck();
+ long replicasCheckDuration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+ int numLedgersFoundHavingNoReplicaOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingNoReplicaOfAnEntry().get();
+ int numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanAQReplicasOfAnEntry().get();
+ int numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanWQReplicasOfAnEntry().get();
+ LOG.info(
+ "Completed ReplicasCheck in {} milliSeconds numLedgersFoundHavingNoReplicaOfAnEntry {}"
+ + " numLedgersFoundHavingLessThanAQReplicasOfAnEntry {}"
+ + " numLedgersFoundHavingLessThanWQReplicasOfAnEntry {}.",
+ replicasCheckDuration, numLedgersFoundHavingNoReplicaOfAnEntryValue,
+ numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue,
+ numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue);
+ auditorStats.getNumLedgersHavingNoReplicaOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingNoReplicaOfAnEntryValue);
+ auditorStats.getNumLedgersHavingLessThanAQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue);
+ auditorStats.getNumLedgersHavingLessThanWQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue);
+ auditorStats.getReplicasCheckTime().registerSuccessfulEvent(
+ replicasCheckDuration, TimeUnit.MILLISECONDS);
+ } catch (ReplicationException.BKAuditException e) {
+ LOG.error("BKAuditException running periodic replicas check.", e);
+ int numLedgersFoundHavingNoReplicaOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingNoReplicaOfAnEntry().get();
+ if (numLedgersFoundHavingNoReplicaOfAnEntryValue > 0) {
+ /*
+ * Though there is BKAuditException while doing
+ * replicasCheck, it found few ledgers having no replica
+ * of an entry. So reporting it.
+ */
+ auditorStats.getNumLedgersHavingNoReplicaOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingNoReplicaOfAnEntryValue);
+ }
+ int numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanAQReplicasOfAnEntry().get();
+ if (numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue > 0) {
+ /*
+ * Though there is BKAuditException while doing
+ * replicasCheck, it found few ledgers having an entry
+ * less than AQ num of Replicas. So reporting it.
+ */
+ auditorStats.getNumLedgersHavingLessThanAQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue);
+ }
+ int numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanWQReplicasOfAnEntry().get();
+ if (numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue > 0) {
+ /*
+ * Though there is BKAuditException while doing
+ * replicasCheck, it found few ledgers having an entry
+ * less than WQ num of Replicas. So reporting it.
+ */
+ auditorStats.getNumLedgersHavingLessThanWQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue);
+ }
+ } catch (ReplicationException.UnavailableException ue) {
+ LOG.error("Underreplication manager unavailable running periodic check", ue);
+ }
+ }
+
+ void replicasCheck() throws ReplicationException.BKAuditException {
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithMissingEntries =
+ new ConcurrentHashMap<Long, MissingEntriesInfoOfLedger>();
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithUnavailableBookies =
+ new ConcurrentHashMap<Long, MissingEntriesInfoOfLedger>();
+ LedgerManager.LedgerRangeIterator ledgerRangeIterator = ledgerManager.getLedgerRanges(zkOpTimeoutMs);
+ final Semaphore maxConcurrentSemaphore = new Semaphore(MAX_CONCURRENT_REPLICAS_CHECK_LEDGER_REQUESTS);
+ while (true) {
+ LedgerManager.LedgerRange ledgerRange = null;
+ try {
+ if (ledgerRangeIterator.hasNext()) {
+ ledgerRange = ledgerRangeIterator.next();
+ } else {
+ break;
+ }
+ } catch (IOException ioe) {
+ LOG.error("Got IOException while iterating LedgerRangeIterator", ioe);
+ throw new ReplicationException.BKAuditException(
+ "Got IOException while iterating LedgerRangeIterator", ioe);
+ }
+ ledgersWithMissingEntries.clear();
+ ledgersWithUnavailableBookies.clear();
+ auditorStats.getNumLedgersFoundHavingNoReplicaOfAnEntry().set(0);
+ auditorStats.getNumLedgersFoundHavingLessThanAQReplicasOfAnEntry().set(0);
+ auditorStats.getNumLedgersFoundHavingLessThanWQReplicasOfAnEntry().set(0);
+ Set<Long> ledgersInRange = ledgerRange.getLedgers();
+ int numOfLedgersInRange = ledgersInRange.size();
+ // Final result after processing all the ledgers
+ final AtomicInteger resultCode = new AtomicInteger();
+ final CountDownLatch replicasCheckLatch = new CountDownLatch(1);
+
+ ReplicasCheckFinalCallback
+ finalCB = new ReplicasCheckFinalCallback(resultCode, replicasCheckLatch);
+ BookkeeperInternalCallbacks.MultiCallback mcbForThisLedgerRange =
+ new BookkeeperInternalCallbacks.MultiCallback(numOfLedgersInRange, finalCB, null,
+ BKException.Code.OK, BKException.Code.ReadException) {
+ @Override
+ public void processResult(int rc, String path, Object ctx) {
+ try {
+ super.processResult(rc, path, ctx);
+ } finally {
+ maxConcurrentSemaphore.release();
+ }
+ }
+ };
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Number of ledgers in the current LedgerRange : {}",
+ numOfLedgersInRange);
+ }
+ for (Long ledgerInRange : ledgersInRange) {
+ try {
+ if (!maxConcurrentSemaphore.tryAcquire(REPLICAS_CHECK_TIMEOUT_IN_SECS, TimeUnit.SECONDS)) {
+ LOG.error("Timedout ({} secs) while waiting for acquiring semaphore",
+ REPLICAS_CHECK_TIMEOUT_IN_SECS);
+ throw new ReplicationException.BKAuditException(
+ "Timedout while waiting for acquiring semaphore");
+ }
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ LOG.error("Got InterruptedException while acquiring semaphore for replicascheck", ie);
+ throw new ReplicationException.BKAuditException(
+ "Got InterruptedException while acquiring semaphore for replicascheck", ie);
+ }
+ if (checkUnderReplicationForReplicasCheck(ledgerInRange, mcbForThisLedgerRange)) {
+ /*
+ * if ledger is marked underreplicated, then ignore this
+ * ledger for replicascheck.
+ */
+ continue;
+ }
+ ledgerManager.readLedgerMetadata(ledgerInRange)
+ .whenComplete(new ReadLedgerMetadataCallbackForReplicasCheck(ledgerInRange,
+ mcbForThisLedgerRange, ledgersWithMissingEntries, ledgersWithUnavailableBookies));
+ }
+ try {
+ /*
+ * if mcbForThisLedgerRange is not calledback within
+ * REPLICAS_CHECK_TIMEOUT_IN_SECS secs then better give up
+ * doing replicascheck, since there could be an issue and
+ * blocking the single threaded auditor executor thread is not
+ * expected.
+ */
+ if (!replicasCheckLatch.await(REPLICAS_CHECK_TIMEOUT_IN_SECS, TimeUnit.SECONDS)) {
+ LOG.error(
+ "For LedgerRange with num of ledgers : {} it didn't complete replicascheck"
+ + " in {} secs, so giving up",
+ numOfLedgersInRange, REPLICAS_CHECK_TIMEOUT_IN_SECS);
+ throw new ReplicationException.BKAuditException(
+ "Got InterruptedException while doing replicascheck");
+ }
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ LOG.error("Got InterruptedException while doing replicascheck", ie);
+ throw new ReplicationException.BKAuditException(
+ "Got InterruptedException while doing replicascheck", ie);
+ }
+ reportLedgersWithMissingEntries(ledgersWithMissingEntries);
+ reportLedgersWithUnavailableBookies(ledgersWithUnavailableBookies);
+ int resultCodeIntValue = resultCode.get();
+ if (resultCodeIntValue != BKException.Code.OK) {
+ throw new ReplicationException.BKAuditException("Exception while doing replicas check",
+ BKException.create(resultCodeIntValue));
+ }
+ }
+ try {
+ final long timeMillis = System.currentTimeMillis();
+ ledgerUnderreplicationManager.setReplicasCheckCTime(timeMillis);
+ LOG.info("ledgerUnderreplicationManager setReplicasCheckCTime {}", timeMillis);
+ } catch (ReplicationException.NonRecoverableReplicationException nre) {
+ LOG.error("Non Recoverable Exception while reading from ZK", nre);
+ submitShutdownTask();
+ } catch (ReplicationException.UnavailableException ue) {
+ LOG.error("Got exception while trying to set ReplicasCheckCTime", ue);
+ }
+ }
+
+ private static class MissingEntriesInfo {
+ // ledger id of missing entries
+ private final long ledgerId;
+ /*
+ * segment details, like start entryid of the segment and ensemble List.
+ */
+ private final Map.Entry<Long, ? extends List<BookieId>> segmentEnsemble;
+ // bookie missing these entries
+ private final BookieId bookieMissingEntries;
+ /*
+ * entries of this segment which are supposed to contain in this bookie
+ * but missing in this bookie.
+ */
+ private final List<Long> unavailableEntriesList;
+
+ private MissingEntriesInfo(long ledgerId, Map.Entry<Long, ? extends List<BookieId>> segmentEnsemble,
+ BookieId bookieMissingEntries, List<Long> unavailableEntriesList) {
+ this.ledgerId = ledgerId;
+ this.segmentEnsemble = segmentEnsemble;
+ this.bookieMissingEntries = bookieMissingEntries;
+ this.unavailableEntriesList = unavailableEntriesList;
+ }
+
+ private long getLedgerId() {
+ return ledgerId;
+ }
+
+ private Map.Entry<Long, ? extends List<BookieId>> getSegmentEnsemble() {
+ return segmentEnsemble;
+ }
+
+ private BookieId getBookieMissingEntries() {
+ return bookieMissingEntries;
+ }
+
+ private List<Long> getUnavailableEntriesList() {
+ return unavailableEntriesList;
+ }
+ }
+
+ private static class MissingEntriesInfoOfLedger {
+ private final long ledgerId;
+ private final int ensembleSize;
+ private final int writeQuorumSize;
+ private final int ackQuorumSize;
+ private final List<MissingEntriesInfo> missingEntriesInfoList;
+
+ private MissingEntriesInfoOfLedger(long ledgerId, int ensembleSize, int writeQuorumSize, int ackQuorumSize,
+ List<MissingEntriesInfo> missingEntriesInfoList) {
+ this.ledgerId = ledgerId;
+ this.ensembleSize = ensembleSize;
+ this.writeQuorumSize = writeQuorumSize;
+ this.ackQuorumSize = ackQuorumSize;
+ this.missingEntriesInfoList = missingEntriesInfoList;
+ }
+
+ private long getLedgerId() {
+ return ledgerId;
+ }
+
+ private int getEnsembleSize() {
+ return ensembleSize;
+ }
+
+ private int getWriteQuorumSize() {
+ return writeQuorumSize;
+ }
+
+ private int getAckQuorumSize() {
+ return ackQuorumSize;
+ }
+
+ private List<MissingEntriesInfo> getMissingEntriesInfoList() {
+ return missingEntriesInfoList;
+ }
+ }
+
+ private class ReadLedgerMetadataCallbackForReplicasCheck
+ implements BiConsumer<Versioned<LedgerMetadata>, Throwable> {
+ private final long ledgerInRange;
+ private final BookkeeperInternalCallbacks.MultiCallback mcbForThisLedgerRange;
+ private final ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithMissingEntries;
+ private final ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithUnavailableBookies;
+
+ ReadLedgerMetadataCallbackForReplicasCheck(
+ long ledgerInRange,
+ BookkeeperInternalCallbacks.MultiCallback mcbForThisLedgerRange,
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithMissingEntries,
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithUnavailableBookies) {
+ this.ledgerInRange = ledgerInRange;
+ this.mcbForThisLedgerRange = mcbForThisLedgerRange;
+ this.ledgersWithMissingEntries = ledgersWithMissingEntries;
+ this.ledgersWithUnavailableBookies = ledgersWithUnavailableBookies;
+ }
+
+ @Override
+ public void accept(Versioned<LedgerMetadata> metadataVer, Throwable exception) {
+ if (exception != null) {
+ if (BKException.getExceptionCode(exception)
+ == BKException.Code.NoSuchLedgerExistsOnMetadataServerException) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ignoring replicas check of already deleted ledger {}",
+ ledgerInRange);
+ }
+ mcbForThisLedgerRange.processResult(BKException.Code.OK, null, null);
+ return;
+ } else {
+ LOG.warn("Unable to read the ledger: {} information", ledgerInRange, exception);
+ mcbForThisLedgerRange.processResult(BKException.getExceptionCode(exception), null, null);
+ return;
+ }
+ }
+
+ LedgerMetadata metadata = metadataVer.getValue();
+ if (!metadata.isClosed()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ledger: {} is not yet closed, "
+ + "so skipping the replicas check analysis for now",
+ ledgerInRange);
+ }
+ mcbForThisLedgerRange.processResult(BKException.Code.OK, null, null);
+ return;
+ }
+
+ final long lastEntryId = metadata.getLastEntryId();
+ if (lastEntryId == -1) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ledger: {} is closed but it doesn't has any entries, "
+ + "so skipping the replicas check", ledgerInRange);
+ }
+ mcbForThisLedgerRange.processResult(BKException.Code.OK, null, null);
+ return;
+ }
+
+ int writeQuorumSize = metadata.getWriteQuorumSize();
+ int ackQuorumSize = metadata.getAckQuorumSize();
+ int ensembleSize = metadata.getEnsembleSize();
+ RoundRobinDistributionSchedule distributionSchedule = new RoundRobinDistributionSchedule(writeQuorumSize,
+ ackQuorumSize, ensembleSize);
+ List<Map.Entry<Long, ? extends List<BookieId>>> segments = new LinkedList<>(
+ metadata.getAllEnsembles().entrySet());
+ /*
+ * since there are multiple segments, MultiCallback should be
+ * created for (ensembleSize * segments.size()) calls.
+ */
+ BookkeeperInternalCallbacks.MultiCallback mcbForThisLedger =
+ new BookkeeperInternalCallbacks.MultiCallback(
+ ensembleSize * segments.size(), mcbForThisLedgerRange,
+ null, BKException.Code.OK, BKException.Code.ReadException);
+ HashMap<BookieId, List<BookieExpectedToContainSegmentInfo>> bookiesSegmentInfoMap =
+ new HashMap<BookieId, List<BookieExpectedToContainSegmentInfo>>();
+ for (int segmentNum = 0; segmentNum < segments.size(); segmentNum++) {
+ final Map.Entry<Long, ? extends List<BookieId>> segmentEnsemble = segments.get(segmentNum);
+ final List<BookieId> ensembleOfSegment = segmentEnsemble.getValue();
+ final long startEntryIdOfSegment = segmentEnsemble.getKey();
+ final boolean lastSegment = (segmentNum == (segments.size() - 1));
+ final long lastEntryIdOfSegment = lastSegment ? lastEntryId
+ : segments.get(segmentNum + 1).getKey() - 1;
+ /*
+ * Segment can be empty. If last segment is empty, then
+ * startEntryIdOfSegment of it will be greater than lastEntryId
+ * of the ledger. If the segment in middle is empty, then its
+ * startEntry will be same as startEntry of the following
+ * segment.
+ */
+ final boolean emptySegment = lastSegment ? (startEntryIdOfSegment > lastEntryId)
+ : (startEntryIdOfSegment == segments.get(segmentNum + 1).getKey());
+ for (int bookieIndex = 0; bookieIndex < ensembleOfSegment.size(); bookieIndex++) {
+ final BookieId bookieInEnsemble = ensembleOfSegment.get(bookieIndex);
+ final BitSet entriesStripedToThisBookie = emptySegment ? EMPTY_BITSET
+ : distributionSchedule.getEntriesStripedToTheBookie(bookieIndex, startEntryIdOfSegment,
+ lastEntryIdOfSegment);
+ if (entriesStripedToThisBookie.cardinality() == 0) {
+ /*
+ * if no entry is expected to contain in this bookie,
+ * then there is no point in making
+ * getListOfEntriesOfLedger call for this bookie. So
+ * instead callback with success result.
+ */
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
+ "For ledger: {}, in Segment: {}, no entry is expected to contain in"
+ + " this bookie: {}. So skipping getListOfEntriesOfLedger call",
+ ledgerInRange, segmentEnsemble, bookieInEnsemble);
+ }
+ mcbForThisLedger.processResult(BKException.Code.OK, null, null);
+ continue;
+ }
+ List<BookieExpectedToContainSegmentInfo> bookieSegmentInfoList = bookiesSegmentInfoMap
+ .get(bookieInEnsemble);
+ if (bookieSegmentInfoList == null) {
Review Comment:
replace with `computeIfAbsent` ?
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -587,7 +270,7 @@ synchronized Future<?> submitAuditTask() {
knownBookies.removeAll(bookiesToBeAudited);
if (lostBookieRecoveryDelay == 0) {
- startAudit(false);
+ newAuditorBookieCheckTask().startAudit(false);
Review Comment:
Are there any ways that do not create the `checkTask` instance every time?
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorBookieCheckTask.java:
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.Lists;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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.commons.collections4.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorBookieCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorBookieCheckTask.class);
+
+ private BookieLedgerIndexer bookieLedgerIndexer;
Review Comment:
final?
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1316887008
rerun failure checks
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098594655
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -0,0 +1,176 @@
+/**
+ * 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.collect.Lists;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.LongAdder;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.common.concurrent.FutureUtils;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class AuditorTask implements Runnable {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorTask.class);
+
+ protected final ServerConfiguration conf;
+ protected AuditorStats auditorStats;
+ protected BookKeeperAdmin admin;
+ protected LedgerManager ledgerManager;
+ protected LedgerUnderreplicationManager ledgerUnderreplicationManager;
+ private final SubmitTaskHandler submitTaskHandler;
+ private final ShutdownTaskHandler shutdownTaskHandler;
+
+ AuditorTask(ServerConfiguration conf,
+ AuditorStats auditorStats,
+ BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ SubmitTaskHandler submitTaskHandler,
+ ShutdownTaskHandler shutdownTaskHandler) {
+ this.conf = conf;
+ this.auditorStats = auditorStats;
+ this.admin = admin;
+ this.ledgerManager = ledgerManager;
+ this.ledgerUnderreplicationManager = ledgerUnderreplicationManager;
+ this.submitTaskHandler = submitTaskHandler;
+ this.shutdownTaskHandler = shutdownTaskHandler;
+ }
+
+ @Override
+ public void run() {
+ runTask();
+ }
+
+ protected abstract void runTask();
+
+ protected void waitIfLedgerReplicationDisabled() throws ReplicationException.UnavailableException,
Review Comment:
Addressed done.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098594312
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorPlacementPolicyCheckTask.java:
##########
@@ -0,0 +1,297 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.EnsemblePlacementPolicy;
+import org.apache.bookkeeper.client.api.LedgerMetadata;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.meta.UnderreplicatedLedger;
+import org.apache.bookkeeper.net.BookieId;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks;
+import org.apache.bookkeeper.versioning.Versioned;
+import org.apache.zookeeper.AsyncCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorPlacementPolicyCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorPlacementPolicyCheckTask.class);
+
+ private final long underreplicatedLedgerRecoveryGracePeriod;
+
+ AuditorPlacementPolicyCheckTask(ServerConfiguration conf,
+ AuditorStats auditorStats,
+ BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ SubmitTaskHandler submitTaskHandler,
+ ShutdownTaskHandler shutdownTaskHandler) {
+ super(conf, auditorStats, admin, ledgerManager,
+ ledgerUnderreplicationManager, submitTaskHandler, shutdownTaskHandler);
+ this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
+ }
+
+ @Override
+ protected void runTask() {
+ try {
+ if (!isLedgerReplicationEnabled()) {
+ LOG.info("Ledger replication disabled, skipping placementPolicyCheck");
+ return;
+ }
+
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ LOG.info("Starting PlacementPolicyCheck");
+ placementPolicyCheck();
+ long placementPolicyCheckDuration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+ int numOfLedgersFoundNotAdheringInPlacementPolicyCheckValue =
+ auditorStats.getNumOfLedgersFoundNotAdheringInPlacementPolicyCheck().get();
Review Comment:
I agree! Addressed done.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -341,155 +153,48 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
+ this.auditorStats = new AuditorStats(statsLogger);
if (conf.getAuditorMaxNumberOfConcurrentOpenLedgerOperations() <= 0) {
Review Comment:
Addressed done.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1315037518
ping @zymap @hangc0276 @Shoothzj @dlg99 If you have time, can you help take a look. Thanks.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1023459587
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -587,7 +270,7 @@ synchronized Future<?> submitAuditTask() {
knownBookies.removeAll(bookiesToBeAudited);
if (lostBookieRecoveryDelay == 0) {
- startAudit(false);
+ newAuditorBookieCheckTask().startAudit(false);
Review Comment:
Maybe we can reuse the one AuditorTask, I'll try 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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098298475
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -341,155 +153,48 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
+ this.auditorStats = new AuditorStats(statsLogger);
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());
+ Semaphore 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 =
+ int openLedgerNoRecoverySemaphoreWaitTimeoutMSec =
conf.getAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec();
- this.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
-
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
+ AuditorTask.ShutdownTaskHandler shutdownTaskHandler = this::submitShutdownTask;
+ AuditorTask.SubmitTaskHandler submitBookieCheckTaskHandler = this::submitBookieCheckTask;
Review Comment:
It's only for AuditorBookieCheckTask, not define it in the AuditorTask.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1106821705
##########
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:
Make sense to me. I have submit your feedback. PTAL. Thanks.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1313397933
rerun failure checks
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098277040
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -0,0 +1,176 @@
+/**
+ * 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.collect.Lists;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.LongAdder;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.common.concurrent.FutureUtils;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class AuditorTask implements Runnable {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorTask.class);
+
+ protected final ServerConfiguration conf;
+ protected AuditorStats auditorStats;
+ protected BookKeeperAdmin admin;
+ protected LedgerManager ledgerManager;
+ protected LedgerUnderreplicationManager ledgerUnderreplicationManager;
+ private final SubmitTaskHandler submitTaskHandler;
+ private final ShutdownTaskHandler shutdownTaskHandler;
+
+ AuditorTask(ServerConfiguration conf,
+ AuditorStats auditorStats,
+ BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ SubmitTaskHandler submitTaskHandler,
+ ShutdownTaskHandler shutdownTaskHandler) {
+ this.conf = conf;
+ this.auditorStats = auditorStats;
+ this.admin = admin;
+ this.ledgerManager = ledgerManager;
+ this.ledgerUnderreplicationManager = ledgerUnderreplicationManager;
+ this.submitTaskHandler = submitTaskHandler;
+ this.shutdownTaskHandler = shutdownTaskHandler;
+ }
+
+ @Override
+ public void run() {
+ runTask();
+ }
+
+ protected abstract void runTask();
+
+ protected void waitIfLedgerReplicationDisabled() throws ReplicationException.UnavailableException,
Review Comment:
It only invokes by AuditorBookieCheckTask, move it to AuditorBookieCheckTask.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098343849
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -727,15 +432,19 @@ public void start() {
}
}
+ protected void submitBookieCheckTask() {
+ executor.submit(auditorBookieCheckTask);
Review Comment:
Not wrap it, use `executor.submit(auditorBookieCheckTask);` directly.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102372241
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -343,167 +154,43 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
-
- 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.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
+ this.auditorStats = new AuditorStats(statsLogger);
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
- executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ ledgerCheckerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
Review Comment:
addressed done.
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorCheckAllLedgersTaskTest.java:
##########
@@ -0,0 +1,118 @@
+/**
+ * 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.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerManagerFactory;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.apache.bookkeeper.test.TestStatsProvider;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit test {@link AuditorCheckAllLedgersTask}.
+ */
+public class AuditorCheckAllLedgersTaskTest extends BookKeeperClusterTestCase {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(AuditorCheckAllLedgersTaskTest.class);
+
+ private static final int maxNumberOfConcurrentOpenLedgerOperations = 500;
+ private static final int acquireConcurrentOpenLedgerOperationsTimeoutMSec = 120000;
+
+ private BookKeeperAdmin admin;
+ private LedgerManager ledgerManager;
+ private LedgerUnderreplicationManager ledgerUnderreplicationManager;
+
+ public AuditorCheckAllLedgersTaskTest() {
+ super(3);
+ baseConf.setPageLimit(1);
+ baseConf.setAutoRecoveryDaemonEnabled(false);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final BookKeeper bookKeeper = new BookKeeper(baseClientConf);
+ admin = new BookKeeperAdmin(bookKeeper, NullStatsLogger.INSTANCE, new ClientConfiguration(baseClientConf));
+ LedgerManagerFactory ledgerManagerFactory = bookKeeper.getLedgerManagerFactory();
+ ledgerManager = ledgerManagerFactory.newLedgerManager();
+ ledgerUnderreplicationManager = ledgerManagerFactory.newLedgerUnderreplicationManager();
+ baseConf.setAuditorMaxNumberOfConcurrentOpenLedgerOperations(maxNumberOfConcurrentOpenLedgerOperations);
+ baseConf.setAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec(
+ acquireConcurrentOpenLedgerOperationsTimeoutMSec);
+ }
+
+ @Test
+ public void testCheckAllLedgers() throws Exception {
+ // 1. create ledgers
+ final int numLedgers = 10;
+ List<Long> ids = new LinkedList<Long>();
+ for (int i = 0; i < numLedgers; i++) {
+ LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
+ ids.add(lh.getId());
+ for (int j = 0; j < 2; j++) {
+ lh.addEntry("testdata".getBytes());
+ }
+ lh.close();
+ }
+
+ // 2. init CheckAllLedgersTask
+ final TestStatsProvider statsProvider = new TestStatsProvider();
+ final TestStatsProvider.TestStatsLogger statsLogger = statsProvider.getStatsLogger(AUDITOR_SCOPE);
+ final AuditorStats auditorStats = new AuditorStats(statsLogger);
+
+ ExecutorService ledgerCheckerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r, "LedgerChecker-test");
+ t.setDaemon(true);
+ return t;
+ }
+ });
+
+ AuditorCheckAllLedgersTask auditorCheckAllLedgersTask = new AuditorCheckAllLedgersTask(
+ baseConf, auditorStats, admin, ledgerManager,
+ ledgerUnderreplicationManager, null, ledgerCheckerExecutor);
+
+ // 3. checkAllLedgers
+ auditorCheckAllLedgersTask.runTask();
+
+ // 4. verify
+ assertEquals("CHECK_ALL_LEDGERS_TIME", 1, ((TestStatsProvider.TestOpStatsLogger) statsLogger
+ .getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME)).getSuccessCount());
+ assertEquals("", numLedgers,
Review Comment:
addressed done.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1030454417
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.collect.Lists;
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.LongAdder;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class AuditorTask implements Runnable {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorTask.class);
+
+ protected Auditor auditor;
+ protected final ServerConfiguration conf;
+ protected AuditorStats auditorStats;
+ protected BookKeeperAdmin admin;
+ protected LedgerManager ledgerManager;
+ protected LedgerUnderreplicationManager ledgerUnderreplicationManager;
+ private final Auditor.ShutdownTaskHandler shutdownTaskHandler;
+
+ AuditorTask(Auditor auditor,
+ ServerConfiguration conf,
+ AuditorStats auditorStats,
+ BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ Auditor.ShutdownTaskHandler shutdownTaskHandler) {
+ this.auditor = auditor;
+ this.conf = conf;
+ this.auditorStats = auditorStats;
+ this.admin = admin;
+ this.ledgerManager = ledgerManager;
+ this.ledgerUnderreplicationManager = ledgerUnderreplicationManager;
+ this.shutdownTaskHandler = shutdownTaskHandler;
+ }
+
+ @Override
+ public void run() {
+ runTask();
+ }
+
+ protected abstract void runTask();
+
+ protected void waitIfLedgerReplicationDisabled() throws ReplicationException.UnavailableException,
+ InterruptedException {
+ ReplicationEnableCb cb = new ReplicationEnableCb();
Review Comment:
I have addressed.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098243355
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorPlacementPolicyCheckTask.java:
##########
@@ -0,0 +1,297 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.EnsemblePlacementPolicy;
+import org.apache.bookkeeper.client.api.LedgerMetadata;
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.meta.UnderreplicatedLedger;
+import org.apache.bookkeeper.net.BookieId;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks;
+import org.apache.bookkeeper.versioning.Versioned;
+import org.apache.zookeeper.AsyncCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorPlacementPolicyCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorPlacementPolicyCheckTask.class);
+
+ private final long underreplicatedLedgerRecoveryGracePeriod;
+
+ AuditorPlacementPolicyCheckTask(ServerConfiguration conf,
+ AuditorStats auditorStats,
+ BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ SubmitTaskHandler submitTaskHandler,
+ ShutdownTaskHandler shutdownTaskHandler) {
+ super(conf, auditorStats, admin, ledgerManager,
+ ledgerUnderreplicationManager, submitTaskHandler, shutdownTaskHandler);
+ this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
+ }
+
+ @Override
+ protected void runTask() {
+ try {
+ if (!isLedgerReplicationEnabled()) {
+ LOG.info("Ledger replication disabled, skipping placementPolicyCheck");
+ return;
+ }
+
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ LOG.info("Starting PlacementPolicyCheck");
+ placementPolicyCheck();
+ long placementPolicyCheckDuration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+ int numOfLedgersFoundNotAdheringInPlacementPolicyCheckValue =
+ auditorStats.getNumOfLedgersFoundNotAdheringInPlacementPolicyCheck().get();
Review Comment:
Not use auditorStats.getNumOfLedgersFoundNotAdheringInPlacementPolicyCheck, we can define numOfLedgersFoundNotAdheringInPlacementPolicyCheck in AuditorPlacementPolicyCheckTask.
Some other fields also are, just define the guava field in AuditorStats
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1099966820
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -599,20 +304,20 @@ synchronized Future<?> submitAuditTask() {
bookiesToBeAudited);
if (auditTask != null && auditTask.cancel(false)) {
auditTask = null;
- numDelayedBookieAuditsCancelled.inc();
+ auditorStats.getNumDelayedBookieAuditsCancelled().inc();
}
- startAudit(false);
+ auditorBookieCheckTask.startAudit(false);
bookiesToBeAudited.clear();
return;
}
if (auditTask == null) {
// if there is no scheduled audit, schedule one
auditTask = executor.schedule(() -> {
- startAudit(false);
+ auditorBookieCheckTask.startAudit(false);
Review Comment:
Ok, that's fine.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102255923
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPlacementPolicyCheckTaskTest.java:
##########
@@ -0,0 +1,102 @@
+/**
+ * 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.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerManagerFactory;
+import org.apache.bookkeeper.meta.LedgerUnderreplicationManager;
+import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.apache.bookkeeper.test.TestStatsProvider;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit test {@link AuditorPlacementPolicyCheckTask}.
+ */
+public class AuditorPlacementPolicyCheckTaskTest extends BookKeeperClusterTestCase {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(AuditorPlacementPolicyCheckTaskTest.class);
+
+ private BookKeeperAdmin admin;
+ private LedgerManager ledgerManager;
+ private LedgerUnderreplicationManager ledgerUnderreplicationManager;
+
+ public AuditorPlacementPolicyCheckTaskTest() {
+ super(3);
+ baseConf.setPageLimit(1);
+ baseConf.setAutoRecoveryDaemonEnabled(false);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final BookKeeper bookKeeper = new BookKeeper(baseClientConf);
+ admin = new BookKeeperAdmin(bookKeeper, NullStatsLogger.INSTANCE, new ClientConfiguration(baseClientConf));
+ LedgerManagerFactory ledgerManagerFactory = bookKeeper.getLedgerManagerFactory();
+ ledgerManager = ledgerManagerFactory.newLedgerManager();
+ ledgerUnderreplicationManager = ledgerManagerFactory.newLedgerUnderreplicationManager();
+ }
+
+ @Test
+ public void testPlacementPolicyCheck() throws BKException, InterruptedException {
+
+ // 1. create ledgers
+ final int numLedgers = 10;
+ List<Long> ids = new LinkedList<Long>();
+ for (int i = 0; i < numLedgers; i++) {
+ LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
+ ids.add(lh.getId());
+ for (int j = 0; j < 2; j++) {
+ lh.addEntry("testdata".getBytes());
+ }
+ lh.close();
+ }
+
+ // 2. init auditorPlacementPolicyCheckTask
+ final TestStatsProvider statsProvider = new TestStatsProvider();
+ final TestStatsProvider.TestStatsLogger statsLogger = statsProvider.getStatsLogger(AUDITOR_SCOPE);
+ final AuditorStats auditorStats = new AuditorStats(statsLogger);
+
+ AuditorPlacementPolicyCheckTask auditorPlacementPolicyCheckTask = new AuditorPlacementPolicyCheckTask(
+ baseConf, auditorStats, admin, ledgerManager,
+ ledgerUnderreplicationManager, null);
+
+ // 3. placementPolicyCheck
+ auditorPlacementPolicyCheckTask.runTask();
+
+ // 4. verify
+ assertEquals("PLACEMENT_POLICY_CHECK_TIME", 1, ((TestStatsProvider.TestOpStatsLogger)
+ statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME)).getSuccessCount());
+ assertEquals("numOfClosedLedgersAuditedInPlacementPolicyCheck",
+ numLedgers,
+ auditorPlacementPolicyCheckTask.getNumOfClosedLedgersAuditedInPlacementPolicyCheck().get());
Review Comment:
We can also check `numOfLedgersFoundNotAdheringInPlacementPolicyCheck`.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1106822031
##########
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:
Addressed it. PTAL.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1325091224
> It does split the code into smaller components but it leaves the components interconnected - tasks that have to access Auditor's internals etc. Typically this is a design smell that will backfire in the future when changing the code or it will become a burden when you start writing unit tests and mocks for the tasks
Second point is the unit tests. I think that new tasks deserve some unit tests.
@dlg99
1. I updated the code to avoid circular dependency between Auditor and CheckTask.
2. I added unit tests corresponding to different tasks.
3. Now these tasks can run independently without Auditor.
4. These tasks all have basic unit tests, indicating that they can run independently without Auditor. Since there are too many items that can be used for testing, if we want other unit tests to cover more options, I hope to use another PR. The previous unit tests are sufficient to prove that the changes in this PR maintain compatibility.
If tests not fail, PTAL. Thanks!
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1030454653
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorBookieCheckTask.java:
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.Lists;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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.commons.collections4.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorBookieCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorBookieCheckTask.class);
+
+ private final BookieLedgerIndexer bookieLedgerIndexer;
+
+ public AuditorBookieCheckTask(Auditor auditor,
Review Comment:
I have addressed.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorCheckAllLedgersTask.java:
##########
@@ -0,0 +1,240 @@
+/**
+ * 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.Semaphore;
+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.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;
+
+ AuditorCheckAllLedgersTask(Auditor auditor,
Review Comment:
I have addressed.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] codecov-commenter commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1420732383
# [Codecov](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#3637](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (cf9a48a) into [master](https://codecov.io/gh/apache/bookkeeper/commit/02e64a4b97e03afc9993ab227f82a5956965c03f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (02e64a4) will **decrease** coverage by `35.38%`.
> The diff coverage is `70.88%`.
```diff
@@ Coverage Diff @@
## master #3637 +/- ##
=============================================
- Coverage 68.02% 32.64% -35.38%
+ Complexity 6659 3107 -3552
=============================================
Files 468 474 +6
Lines 40844 40953 +109
Branches 5235 5235
=============================================
- Hits 27786 13371 -14415
- Misses 10807 25916 +15109
+ Partials 2251 1666 -585
```
| Flag | Coverage Δ | |
|---|---|---|
| bookie | `?` | |
| client | `?` | |
| remaining | `29.66% <70.88%> (+0.21%)` | :arrow_up: |
| replication | `?` | |
| tls | `21.02% <0.00%> (-0.17%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...keeper/replication/AuditorCheckAllLedgersTask.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvckNoZWNrQWxsTGVkZ2Vyc1Rhc2suamF2YQ==) | `52.27% <52.27%> (ø)` | |
| [...r/replication/AuditorPlacementPolicyCheckTask.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvclBsYWNlbWVudFBvbGljeUNoZWNrVGFzay5qYXZh) | `63.80% <63.80%> (ø)` | |
| [...okkeeper/replication/AuditorReplicasCheckTask.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvclJlcGxpY2FzQ2hlY2tUYXNrLmphdmE=) | `73.71% <73.71%> (ø)` | |
| [...bookkeeper/replication/AuditorBookieCheckTask.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvckJvb2tpZUNoZWNrVGFzay5qYXZh) | `75.00% <75.00%> (ø)` | |
| [...rg/apache/bookkeeper/replication/AuditorStats.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvclN0YXRzLmphdmE=) | `82.14% <82.14%> (ø)` | |
| [...org/apache/bookkeeper/replication/AuditorTask.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvclRhc2suamF2YQ==) | `82.60% <82.60%> (ø)` | |
| [...ava/org/apache/bookkeeper/replication/Auditor.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcmVwbGljYXRpb24vQXVkaXRvci5qYXZh) | `73.73% <100.00%> (+4.04%)` | :arrow_up: |
| [...java/org/apache/bookkeeper/proto/BookieClient.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvcHJvdG8vQm9va2llQ2xpZW50LmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [...a/org/apache/bookkeeper/client/api/BookKeeper.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvY2xpZW50L2FwaS9Cb29rS2VlcGVyLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [...a/org/apache/bookkeeper/client/api/ReadHandle.java](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Ym9va2tlZXBlci1zZXJ2ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvY2xpZW50L2FwaS9SZWFkSGFuZGxlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| ... and [342 more](https://codecov.io/gh/apache/bookkeeper/pull/3637?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102236736
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -343,167 +154,43 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
-
- 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.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
+ this.auditorStats = new AuditorStats(statsLogger);
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
- executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ ledgerCheckerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
Review Comment:
We can define and initialize it in AuditorCheckAllLedgersTask. And add a abstract method `shutdown()` in the AuditorTask, if we need to do some resource clean, we can override the shutdown(). In Auditor shutdown(), to invoke task.shutdown();
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102248271
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPeriodicCheckTest.java:
##########
@@ -751,6 +737,24 @@ CountDownLatch getLatch() {
void setLatch(CountDownLatch latch) {
latchRef.set(latch);
}
+
+ private static class AuditorTestWrapperTask extends AuditorTask {
+ private final AuditorTask innerTask;
+ private final AtomicReference<CountDownLatch> latchRef;
Review Comment:
Just confirm, why define latchRef. And the latchRef is shared in all the AuditorTestWrapperTask.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098343849
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -727,15 +432,19 @@ public void start() {
}
}
+ protected void submitBookieCheckTask() {
+ executor.submit(auditorBookieCheckTask);
Review Comment:
Not wrap it, use `executor.submit(auditorBookieCheckTask);` directly.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1099969487
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -341,155 +153,48 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
+ this.auditorStats = new AuditorStats(statsLogger);
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());
+ Semaphore 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 =
+ int openLedgerNoRecoverySemaphoreWaitTimeoutMSec =
conf.getAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec();
- this.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
-
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
+ AuditorTask.ShutdownTaskHandler shutdownTaskHandler = this::submitShutdownTask;
+ AuditorTask.SubmitTaskHandler submitBookieCheckTaskHandler = this::submitBookieCheckTask;
Review Comment:
I don't think so. If any task needs to do some operations, it can do the operation alone. The SubmitTaskHandler is not common for different tasks.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098609374
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -599,20 +304,20 @@ synchronized Future<?> submitAuditTask() {
bookiesToBeAudited);
if (auditTask != null && auditTask.cancel(false)) {
auditTask = null;
- numDelayedBookieAuditsCancelled.inc();
+ auditorStats.getNumDelayedBookieAuditsCancelled().inc();
}
- startAudit(false);
+ auditorBookieCheckTask.startAudit(false);
bookiesToBeAudited.clear();
return;
}
if (auditTask == null) {
// if there is no scheduled audit, schedule one
auditTask = executor.schedule(() -> {
- startAudit(false);
+ auditorBookieCheckTask.startAudit(false);
Review Comment:
auditorBookieCheckTask is runnable, and scheduled operation is a complete task execution. The runTask method is also a part of the task. startAudit is only the execution of one of the methods, and does not represent a complete scheduled task.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098258278
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -341,155 +153,48 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
+ this.auditorStats = new AuditorStats(statsLogger);
if (conf.getAuditorMaxNumberOfConcurrentOpenLedgerOperations() <= 0) {
Review Comment:
Suggest moving the check logic in the AuditorCheckAllLedgersTask construction.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1106834526
##########
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:
@hangc0276 The statsLogger of auditorStats is used in AuditorTask. After thinking about it, if the task needs to use statsLogger to build bookkeeper internal components, statsLogger is best placed in AuditorStats.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1107971028
##########
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:
OK, make sense.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] dlg99 commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
dlg99 commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1029866761
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorBookieCheckTask.java:
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.Lists;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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.commons.collections4.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorBookieCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorBookieCheckTask.class);
+
+ private final BookieLedgerIndexer bookieLedgerIndexer;
+
+ public AuditorBookieCheckTask(Auditor auditor,
Review Comment:
Can we avoid circular dependency between Auditor and AuditorBookieCheckTask?
It will backfire eventually.
Most likely you'd notice it if you start adding unit tests/mocks for AuditorBookieCheckTask/other tasks instead of current coarse-leveled test.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.collect.Lists;
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.LongAdder;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class AuditorTask implements Runnable {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorTask.class);
+
+ protected Auditor auditor;
+ protected final ServerConfiguration conf;
+ protected AuditorStats auditorStats;
+ protected BookKeeperAdmin admin;
+ protected LedgerManager ledgerManager;
+ protected LedgerUnderreplicationManager ledgerUnderreplicationManager;
+ private final Auditor.ShutdownTaskHandler shutdownTaskHandler;
+
+ AuditorTask(Auditor auditor,
+ ServerConfiguration conf,
+ AuditorStats auditorStats,
+ BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ Auditor.ShutdownTaskHandler shutdownTaskHandler) {
+ this.auditor = auditor;
+ this.conf = conf;
+ this.auditorStats = auditorStats;
+ this.admin = admin;
+ this.ledgerManager = ledgerManager;
+ this.ledgerUnderreplicationManager = ledgerUnderreplicationManager;
+ this.shutdownTaskHandler = shutdownTaskHandler;
+ }
+
+ @Override
+ public void run() {
+ runTask();
+ }
+
+ protected abstract void runTask();
+
+ protected void waitIfLedgerReplicationDisabled() throws ReplicationException.UnavailableException,
+ InterruptedException {
+ ReplicationEnableCb cb = new ReplicationEnableCb();
Review Comment:
create the call back object inside the if statement, to avoid unnecessary creation
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorCheckAllLedgersTask.java:
##########
@@ -0,0 +1,240 @@
+/**
+ * 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.Semaphore;
+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.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;
+
+ AuditorCheckAllLedgersTask(Auditor auditor,
Review Comment:
same, circular dependency
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] hangc0276 merged pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 merged PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "horizonzy (via GitHub)" <gi...@apache.org>.
horizonzy commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1098333711
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -599,20 +304,20 @@ synchronized Future<?> submitAuditTask() {
bookiesToBeAudited);
if (auditTask != null && auditTask.cancel(false)) {
auditTask = null;
- numDelayedBookieAuditsCancelled.inc();
+ auditorStats.getNumDelayedBookieAuditsCancelled().inc();
}
- startAudit(false);
+ auditorBookieCheckTask.startAudit(false);
bookiesToBeAudited.clear();
return;
}
if (auditTask == null) {
// if there is no scheduled audit, schedule one
auditTask = executor.schedule(() -> {
- startAudit(false);
+ auditorBookieCheckTask.startAudit(false);
Review Comment:
It's odd. The auditorBookieCheckTask is runnable, here we define a runnable to invoke `auditorBookieCheckTask.startAudit(false)`.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1101027021
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java:
##########
@@ -341,155 +153,48 @@ public Auditor(final String bookieIdentifier,
StatsLogger statsLogger)
throws UnavailableException {
this.conf = conf;
- this.underreplicatedLedgerRecoveryGracePeriod = conf.getUnderreplicatedLedgerRecoveryGracePeriod();
- this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
this.bookieIdentifier = bookieIdentifier;
- this.statsLogger = statsLogger;
- this.numOfLedgersFoundNotAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersNotAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfLedgersFoundSoftlyAdheringInPlacementPolicyCheck = new AtomicInteger(0);
- this.ledgersSoftlyAdheringToPlacementPolicyGuageValue = new AtomicInteger(0);
- this.numOfClosedLedgersAuditedInPlacementPolicyCheck = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriod = new AtomicInteger(0);
- this.numOfURLedgersElapsedRecoveryGracePeriodGuageValue = new AtomicInteger(0);
- this.numLedgersHavingNoReplicaOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingNoReplicaOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanAQReplicasOfAnEntry = new AtomicInteger(0);
- this.numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue = new AtomicInteger(0);
- this.numLedgersFoundHavingLessThanWQReplicasOfAnEntry = new AtomicInteger(0);
+ this.auditorStats = new AuditorStats(statsLogger);
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());
+ Semaphore 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 =
+ int openLedgerNoRecoverySemaphoreWaitTimeoutMSec =
conf.getAuditorAcquireConcurrentOpenLedgerOperationsTimeoutMSec();
- this.underReplicatedLedgersGuageValue = new AtomicInteger(0);
- numUnderReplicatedLedger = this.statsLogger.getOpStatsLogger(ReplicationStats.NUM_UNDER_REPLICATED_LEDGERS);
- underReplicatedLedgerTotalSize = this.statsLogger.getOpStatsLogger(UNDER_REPLICATED_LEDGERS_TOTAL_SIZE);
- uRLPublishTimeForLostBookies = this.statsLogger
- .getOpStatsLogger(ReplicationStats.URL_PUBLISH_TIME_FOR_LOST_BOOKIE);
- bookieToLedgersMapCreationTime = this.statsLogger
- .getOpStatsLogger(ReplicationStats.BOOKIE_TO_LEDGERS_MAP_CREATION_TIME);
- checkAllLedgersTime = this.statsLogger.getOpStatsLogger(ReplicationStats.CHECK_ALL_LEDGERS_TIME);
- placementPolicyCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.PLACEMENT_POLICY_CHECK_TIME);
- replicasCheckTime = this.statsLogger.getOpStatsLogger(ReplicationStats.REPLICAS_CHECK_TIME);
- auditBookiesTime = this.statsLogger.getOpStatsLogger(ReplicationStats.AUDIT_BOOKIES_TIME);
- numLedgersChecked = this.statsLogger.getCounter(ReplicationStats.NUM_LEDGERS_CHECKED);
- numFragmentsPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_FRAGMENTS_PER_LEDGER);
- numBookiesPerLedger = statsLogger.getOpStatsLogger(ReplicationStats.NUM_BOOKIES_PER_LEDGER);
- numBookieAuditsDelayed = this.statsLogger.getCounter(ReplicationStats.NUM_BOOKIE_AUDITS_DELAYED);
- numDelayedBookieAuditsCancelled = this.statsLogger
- .getCounter(ReplicationStats.NUM_DELAYED_BOOKIE_AUDITS_DELAYES_CANCELLED);
- numReplicatedLedgers = this.statsLogger.getCounter(NUM_REPLICATED_LEDGERS);
- numLedgersNotAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersNotAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersNotAdheringToPlacementPolicy);
- numLedgersSoftlyAdheringToPlacementPolicy = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return ledgersSoftlyAdheringToPlacementPolicyGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_SOFTLY_ADHERING_TO_PLACEMENT_POLICY,
- numLedgersSoftlyAdheringToPlacementPolicy);
-
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numOfURLedgersElapsedRecoveryGracePeriodGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_UNDERREPLICATED_LEDGERS_ELAPSED_RECOVERY_GRACE_PERIOD,
- numUnderreplicatedLedgersElapsedRecoveryGracePeriod);
-
- numLedgersHavingNoReplicaOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingNoReplicaOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_NO_REPLICA_OF_AN_ENTRY,
- numLedgersHavingNoReplicaOfAnEntry);
- numLedgersHavingLessThanAQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanAQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_AQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanAQReplicasOfAnEntry);
- numLedgersHavingLessThanWQReplicasOfAnEntry = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return numLedgersHavingLessThanWQReplicasOfAnEntryGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY,
- numLedgersHavingLessThanWQReplicasOfAnEntry);
- numUnderReplicatedLedgers = new Gauge<Integer>() {
- @Override
- public Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Integer getSample() {
- return underReplicatedLedgersGuageValue.get();
- }
- };
- this.statsLogger.registerGauge(NUM_UNDER_REPLICATED_LEDGERS_GUAGE, numUnderReplicatedLedgers);
-
this.bkc = bkc;
this.ownBkc = ownBkc;
this.admin = admin;
this.ownAdmin = ownAdmin;
initialize(conf, bkc);
+ AuditorTask.ShutdownTaskHandler shutdownTaskHandler = this::submitShutdownTask;
+ AuditorTask.SubmitTaskHandler submitBookieCheckTaskHandler = this::submitBookieCheckTask;
Review Comment:
I got it. I have submit your feedback. PTAL. Thanks.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by "wenbingshen (via GitHub)" <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1102359160
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPeriodicCheckTest.java:
##########
@@ -751,6 +737,24 @@ CountDownLatch getLatch() {
void setLatch(CountDownLatch latch) {
latchRef.set(latch);
}
+
+ private static class AuditorTestWrapperTask extends AuditorTask {
+ private final AuditorTask innerTask;
+ private final AtomicReference<CountDownLatch> latchRef;
Review Comment:
@horizonzy I think there are several reasons for defining latchRef:
1. Before this PR, the original author has defined latchRef in this test, I just try to ensure that its content does not change and the unit test can pass
2. latchRef is only wrapped in three tasks: auditorCheckAllLedgersTask, auditorPlacementPolicyCheckTask and auditorReplicasCheckTask
3. In the unit test, every time any task is tested, the conf will be changed and the other two tasks will be disabled.
4. LatchRef will countDown() only after the execution of the AuditorTask core logic of the unit test is completed, so that the unit test can then judge the correctness of the metrics in the verification operation and whether it meets expectations.
5. latchRef is used to ensure the execution order among multiple threads
6. If there is no better implementation, we can keep the original author's latchRef implementation
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1333763105
I have another bugfix for Auditor. I want to commit after this PR so that I can avoid rebase master. Can you help me to see this PR? Thank you very much. @hangc0276 @dlg99 @eolivelli
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on a diff in pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on code in PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#discussion_r1023902579
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorReplicasCheckTask.java:
##########
@@ -0,0 +1,750 @@
+/**
+ * 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.HashMultiset;
+import com.google.common.collect.Multiset;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BiConsumer;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.client.RoundRobinDistributionSchedule;
+import org.apache.bookkeeper.client.api.LedgerMetadata;
+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.util.AvailabilityOfEntriesOfLedger;
+import org.apache.bookkeeper.versioning.Versioned;
+import org.apache.zookeeper.AsyncCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorReplicasCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorReplicasCheckTask.class);
+
+ private static final int MAX_CONCURRENT_REPLICAS_CHECK_LEDGER_REQUESTS = 100;
+ private static final int REPLICAS_CHECK_TIMEOUT_IN_SECS = 120;
+ private static final BitSet EMPTY_BITSET = new BitSet();
+
+ private final int zkOpTimeoutMs;
+
+ AuditorReplicasCheckTask(Auditor auditor,
+ ServerConfiguration conf,
+ AuditorStats auditorStats, BookKeeperAdmin admin,
+ LedgerManager ledgerManager,
+ LedgerUnderreplicationManager ledgerUnderreplicationManager,
+ Auditor.ShutdownTaskHandler shutdownTaskHandler) {
+ super(auditor, conf, auditorStats, admin, ledgerManager, ledgerUnderreplicationManager, shutdownTaskHandler);
+ this.zkOpTimeoutMs = conf.getZkTimeout() * 2;
+ }
+
+ @Override
+ protected void runTask() {
+ try {
+ if (!ledgerUnderreplicationManager.isLedgerReplicationEnabled()) {
+ LOG.info("Ledger replication disabled, skipping replicasCheck task.");
+ return;
+ }
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ LOG.info("Starting ReplicasCheck");
+ replicasCheck();
+ long replicasCheckDuration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+ int numLedgersFoundHavingNoReplicaOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingNoReplicaOfAnEntry().get();
+ int numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanAQReplicasOfAnEntry().get();
+ int numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanWQReplicasOfAnEntry().get();
+ LOG.info(
+ "Completed ReplicasCheck in {} milliSeconds numLedgersFoundHavingNoReplicaOfAnEntry {}"
+ + " numLedgersFoundHavingLessThanAQReplicasOfAnEntry {}"
+ + " numLedgersFoundHavingLessThanWQReplicasOfAnEntry {}.",
+ replicasCheckDuration, numLedgersFoundHavingNoReplicaOfAnEntryValue,
+ numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue,
+ numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue);
+ auditorStats.getNumLedgersHavingNoReplicaOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingNoReplicaOfAnEntryValue);
+ auditorStats.getNumLedgersHavingLessThanAQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue);
+ auditorStats.getNumLedgersHavingLessThanWQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue);
+ auditorStats.getReplicasCheckTime().registerSuccessfulEvent(
+ replicasCheckDuration, TimeUnit.MILLISECONDS);
+ } catch (ReplicationException.BKAuditException e) {
+ LOG.error("BKAuditException running periodic replicas check.", e);
+ int numLedgersFoundHavingNoReplicaOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingNoReplicaOfAnEntry().get();
+ if (numLedgersFoundHavingNoReplicaOfAnEntryValue > 0) {
+ /*
+ * Though there is BKAuditException while doing
+ * replicasCheck, it found few ledgers having no replica
+ * of an entry. So reporting it.
+ */
+ auditorStats.getNumLedgersHavingNoReplicaOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingNoReplicaOfAnEntryValue);
+ }
+ int numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanAQReplicasOfAnEntry().get();
+ if (numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue > 0) {
+ /*
+ * Though there is BKAuditException while doing
+ * replicasCheck, it found few ledgers having an entry
+ * less than AQ num of Replicas. So reporting it.
+ */
+ auditorStats.getNumLedgersHavingLessThanAQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanAQReplicasOfAnEntryValue);
+ }
+ int numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue =
+ auditorStats.getNumLedgersFoundHavingLessThanWQReplicasOfAnEntry().get();
+ if (numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue > 0) {
+ /*
+ * Though there is BKAuditException while doing
+ * replicasCheck, it found few ledgers having an entry
+ * less than WQ num of Replicas. So reporting it.
+ */
+ auditorStats.getNumLedgersHavingLessThanWQReplicasOfAnEntryGuageValue()
+ .set(numLedgersFoundHavingLessThanWQReplicasOfAnEntryValue);
+ }
+ } catch (ReplicationException.UnavailableException ue) {
+ LOG.error("Underreplication manager unavailable running periodic check", ue);
+ }
+ }
+
+ void replicasCheck() throws ReplicationException.BKAuditException {
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithMissingEntries =
+ new ConcurrentHashMap<Long, MissingEntriesInfoOfLedger>();
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithUnavailableBookies =
+ new ConcurrentHashMap<Long, MissingEntriesInfoOfLedger>();
+ LedgerManager.LedgerRangeIterator ledgerRangeIterator = ledgerManager.getLedgerRanges(zkOpTimeoutMs);
+ final Semaphore maxConcurrentSemaphore = new Semaphore(MAX_CONCURRENT_REPLICAS_CHECK_LEDGER_REQUESTS);
+ while (true) {
+ LedgerManager.LedgerRange ledgerRange = null;
+ try {
+ if (ledgerRangeIterator.hasNext()) {
+ ledgerRange = ledgerRangeIterator.next();
+ } else {
+ break;
+ }
+ } catch (IOException ioe) {
+ LOG.error("Got IOException while iterating LedgerRangeIterator", ioe);
+ throw new ReplicationException.BKAuditException(
+ "Got IOException while iterating LedgerRangeIterator", ioe);
+ }
+ ledgersWithMissingEntries.clear();
+ ledgersWithUnavailableBookies.clear();
+ auditorStats.getNumLedgersFoundHavingNoReplicaOfAnEntry().set(0);
+ auditorStats.getNumLedgersFoundHavingLessThanAQReplicasOfAnEntry().set(0);
+ auditorStats.getNumLedgersFoundHavingLessThanWQReplicasOfAnEntry().set(0);
+ Set<Long> ledgersInRange = ledgerRange.getLedgers();
+ int numOfLedgersInRange = ledgersInRange.size();
+ // Final result after processing all the ledgers
+ final AtomicInteger resultCode = new AtomicInteger();
+ final CountDownLatch replicasCheckLatch = new CountDownLatch(1);
+
+ ReplicasCheckFinalCallback
+ finalCB = new ReplicasCheckFinalCallback(resultCode, replicasCheckLatch);
+ BookkeeperInternalCallbacks.MultiCallback mcbForThisLedgerRange =
+ new BookkeeperInternalCallbacks.MultiCallback(numOfLedgersInRange, finalCB, null,
+ BKException.Code.OK, BKException.Code.ReadException) {
+ @Override
+ public void processResult(int rc, String path, Object ctx) {
+ try {
+ super.processResult(rc, path, ctx);
+ } finally {
+ maxConcurrentSemaphore.release();
+ }
+ }
+ };
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Number of ledgers in the current LedgerRange : {}",
+ numOfLedgersInRange);
+ }
+ for (Long ledgerInRange : ledgersInRange) {
+ try {
+ if (!maxConcurrentSemaphore.tryAcquire(REPLICAS_CHECK_TIMEOUT_IN_SECS, TimeUnit.SECONDS)) {
+ LOG.error("Timedout ({} secs) while waiting for acquiring semaphore",
+ REPLICAS_CHECK_TIMEOUT_IN_SECS);
+ throw new ReplicationException.BKAuditException(
+ "Timedout while waiting for acquiring semaphore");
+ }
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ LOG.error("Got InterruptedException while acquiring semaphore for replicascheck", ie);
+ throw new ReplicationException.BKAuditException(
+ "Got InterruptedException while acquiring semaphore for replicascheck", ie);
+ }
+ if (checkUnderReplicationForReplicasCheck(ledgerInRange, mcbForThisLedgerRange)) {
+ /*
+ * if ledger is marked underreplicated, then ignore this
+ * ledger for replicascheck.
+ */
+ continue;
+ }
+ ledgerManager.readLedgerMetadata(ledgerInRange)
+ .whenComplete(new ReadLedgerMetadataCallbackForReplicasCheck(ledgerInRange,
+ mcbForThisLedgerRange, ledgersWithMissingEntries, ledgersWithUnavailableBookies));
+ }
+ try {
+ /*
+ * if mcbForThisLedgerRange is not calledback within
+ * REPLICAS_CHECK_TIMEOUT_IN_SECS secs then better give up
+ * doing replicascheck, since there could be an issue and
+ * blocking the single threaded auditor executor thread is not
+ * expected.
+ */
+ if (!replicasCheckLatch.await(REPLICAS_CHECK_TIMEOUT_IN_SECS, TimeUnit.SECONDS)) {
+ LOG.error(
+ "For LedgerRange with num of ledgers : {} it didn't complete replicascheck"
+ + " in {} secs, so giving up",
+ numOfLedgersInRange, REPLICAS_CHECK_TIMEOUT_IN_SECS);
+ throw new ReplicationException.BKAuditException(
+ "Got InterruptedException while doing replicascheck");
+ }
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ LOG.error("Got InterruptedException while doing replicascheck", ie);
+ throw new ReplicationException.BKAuditException(
+ "Got InterruptedException while doing replicascheck", ie);
+ }
+ reportLedgersWithMissingEntries(ledgersWithMissingEntries);
+ reportLedgersWithUnavailableBookies(ledgersWithUnavailableBookies);
+ int resultCodeIntValue = resultCode.get();
+ if (resultCodeIntValue != BKException.Code.OK) {
+ throw new ReplicationException.BKAuditException("Exception while doing replicas check",
+ BKException.create(resultCodeIntValue));
+ }
+ }
+ try {
+ final long timeMillis = System.currentTimeMillis();
+ ledgerUnderreplicationManager.setReplicasCheckCTime(timeMillis);
+ LOG.info("ledgerUnderreplicationManager setReplicasCheckCTime {}", timeMillis);
+ } catch (ReplicationException.NonRecoverableReplicationException nre) {
+ LOG.error("Non Recoverable Exception while reading from ZK", nre);
+ submitShutdownTask();
+ } catch (ReplicationException.UnavailableException ue) {
+ LOG.error("Got exception while trying to set ReplicasCheckCTime", ue);
+ }
+ }
+
+ private static class MissingEntriesInfo {
+ // ledger id of missing entries
+ private final long ledgerId;
+ /*
+ * segment details, like start entryid of the segment and ensemble List.
+ */
+ private final Map.Entry<Long, ? extends List<BookieId>> segmentEnsemble;
+ // bookie missing these entries
+ private final BookieId bookieMissingEntries;
+ /*
+ * entries of this segment which are supposed to contain in this bookie
+ * but missing in this bookie.
+ */
+ private final List<Long> unavailableEntriesList;
+
+ private MissingEntriesInfo(long ledgerId, Map.Entry<Long, ? extends List<BookieId>> segmentEnsemble,
+ BookieId bookieMissingEntries, List<Long> unavailableEntriesList) {
+ this.ledgerId = ledgerId;
+ this.segmentEnsemble = segmentEnsemble;
+ this.bookieMissingEntries = bookieMissingEntries;
+ this.unavailableEntriesList = unavailableEntriesList;
+ }
+
+ private long getLedgerId() {
+ return ledgerId;
+ }
+
+ private Map.Entry<Long, ? extends List<BookieId>> getSegmentEnsemble() {
+ return segmentEnsemble;
+ }
+
+ private BookieId getBookieMissingEntries() {
+ return bookieMissingEntries;
+ }
+
+ private List<Long> getUnavailableEntriesList() {
+ return unavailableEntriesList;
+ }
+ }
+
+ private static class MissingEntriesInfoOfLedger {
+ private final long ledgerId;
+ private final int ensembleSize;
+ private final int writeQuorumSize;
+ private final int ackQuorumSize;
+ private final List<MissingEntriesInfo> missingEntriesInfoList;
+
+ private MissingEntriesInfoOfLedger(long ledgerId, int ensembleSize, int writeQuorumSize, int ackQuorumSize,
+ List<MissingEntriesInfo> missingEntriesInfoList) {
+ this.ledgerId = ledgerId;
+ this.ensembleSize = ensembleSize;
+ this.writeQuorumSize = writeQuorumSize;
+ this.ackQuorumSize = ackQuorumSize;
+ this.missingEntriesInfoList = missingEntriesInfoList;
+ }
+
+ private long getLedgerId() {
+ return ledgerId;
+ }
+
+ private int getEnsembleSize() {
+ return ensembleSize;
+ }
+
+ private int getWriteQuorumSize() {
+ return writeQuorumSize;
+ }
+
+ private int getAckQuorumSize() {
+ return ackQuorumSize;
+ }
+
+ private List<MissingEntriesInfo> getMissingEntriesInfoList() {
+ return missingEntriesInfoList;
+ }
+ }
+
+ private class ReadLedgerMetadataCallbackForReplicasCheck
+ implements BiConsumer<Versioned<LedgerMetadata>, Throwable> {
+ private final long ledgerInRange;
+ private final BookkeeperInternalCallbacks.MultiCallback mcbForThisLedgerRange;
+ private final ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithMissingEntries;
+ private final ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithUnavailableBookies;
+
+ ReadLedgerMetadataCallbackForReplicasCheck(
+ long ledgerInRange,
+ BookkeeperInternalCallbacks.MultiCallback mcbForThisLedgerRange,
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithMissingEntries,
+ ConcurrentHashMap<Long, MissingEntriesInfoOfLedger> ledgersWithUnavailableBookies) {
+ this.ledgerInRange = ledgerInRange;
+ this.mcbForThisLedgerRange = mcbForThisLedgerRange;
+ this.ledgersWithMissingEntries = ledgersWithMissingEntries;
+ this.ledgersWithUnavailableBookies = ledgersWithUnavailableBookies;
+ }
+
+ @Override
+ public void accept(Versioned<LedgerMetadata> metadataVer, Throwable exception) {
+ if (exception != null) {
+ if (BKException.getExceptionCode(exception)
+ == BKException.Code.NoSuchLedgerExistsOnMetadataServerException) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ignoring replicas check of already deleted ledger {}",
+ ledgerInRange);
+ }
+ mcbForThisLedgerRange.processResult(BKException.Code.OK, null, null);
+ return;
+ } else {
+ LOG.warn("Unable to read the ledger: {} information", ledgerInRange, exception);
+ mcbForThisLedgerRange.processResult(BKException.getExceptionCode(exception), null, null);
+ return;
+ }
+ }
+
+ LedgerMetadata metadata = metadataVer.getValue();
+ if (!metadata.isClosed()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ledger: {} is not yet closed, "
+ + "so skipping the replicas check analysis for now",
+ ledgerInRange);
+ }
+ mcbForThisLedgerRange.processResult(BKException.Code.OK, null, null);
+ return;
+ }
+
+ final long lastEntryId = metadata.getLastEntryId();
+ if (lastEntryId == -1) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ledger: {} is closed but it doesn't has any entries, "
+ + "so skipping the replicas check", ledgerInRange);
+ }
+ mcbForThisLedgerRange.processResult(BKException.Code.OK, null, null);
+ return;
+ }
+
+ int writeQuorumSize = metadata.getWriteQuorumSize();
+ int ackQuorumSize = metadata.getAckQuorumSize();
+ int ensembleSize = metadata.getEnsembleSize();
+ RoundRobinDistributionSchedule distributionSchedule = new RoundRobinDistributionSchedule(writeQuorumSize,
+ ackQuorumSize, ensembleSize);
+ List<Map.Entry<Long, ? extends List<BookieId>>> segments = new LinkedList<>(
+ metadata.getAllEnsembles().entrySet());
+ /*
+ * since there are multiple segments, MultiCallback should be
+ * created for (ensembleSize * segments.size()) calls.
+ */
+ BookkeeperInternalCallbacks.MultiCallback mcbForThisLedger =
+ new BookkeeperInternalCallbacks.MultiCallback(
+ ensembleSize * segments.size(), mcbForThisLedgerRange,
+ null, BKException.Code.OK, BKException.Code.ReadException);
+ HashMap<BookieId, List<BookieExpectedToContainSegmentInfo>> bookiesSegmentInfoMap =
+ new HashMap<BookieId, List<BookieExpectedToContainSegmentInfo>>();
+ for (int segmentNum = 0; segmentNum < segments.size(); segmentNum++) {
+ final Map.Entry<Long, ? extends List<BookieId>> segmentEnsemble = segments.get(segmentNum);
+ final List<BookieId> ensembleOfSegment = segmentEnsemble.getValue();
+ final long startEntryIdOfSegment = segmentEnsemble.getKey();
+ final boolean lastSegment = (segmentNum == (segments.size() - 1));
+ final long lastEntryIdOfSegment = lastSegment ? lastEntryId
+ : segments.get(segmentNum + 1).getKey() - 1;
+ /*
+ * Segment can be empty. If last segment is empty, then
+ * startEntryIdOfSegment of it will be greater than lastEntryId
+ * of the ledger. If the segment in middle is empty, then its
+ * startEntry will be same as startEntry of the following
+ * segment.
+ */
+ final boolean emptySegment = lastSegment ? (startEntryIdOfSegment > lastEntryId)
+ : (startEntryIdOfSegment == segments.get(segmentNum + 1).getKey());
+ for (int bookieIndex = 0; bookieIndex < ensembleOfSegment.size(); bookieIndex++) {
+ final BookieId bookieInEnsemble = ensembleOfSegment.get(bookieIndex);
+ final BitSet entriesStripedToThisBookie = emptySegment ? EMPTY_BITSET
+ : distributionSchedule.getEntriesStripedToTheBookie(bookieIndex, startEntryIdOfSegment,
+ lastEntryIdOfSegment);
+ if (entriesStripedToThisBookie.cardinality() == 0) {
+ /*
+ * if no entry is expected to contain in this bookie,
+ * then there is no point in making
+ * getListOfEntriesOfLedger call for this bookie. So
+ * instead callback with success result.
+ */
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
+ "For ledger: {}, in Segment: {}, no entry is expected to contain in"
+ + " this bookie: {}. So skipping getListOfEntriesOfLedger call",
+ ledgerInRange, segmentEnsemble, bookieInEnsemble);
+ }
+ mcbForThisLedger.processResult(BKException.Code.OK, null, null);
+ continue;
+ }
+ List<BookieExpectedToContainSegmentInfo> bookieSegmentInfoList = bookiesSegmentInfoMap
+ .get(bookieInEnsemble);
+ if (bookieSegmentInfoList == null) {
Review Comment:
addressed done
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorBookieCheckTask.java:
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.Lists;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+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.commons.collections4.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuditorBookieCheckTask extends AuditorTask {
+ private static final Logger LOG = LoggerFactory.getLogger(AuditorBookieCheckTask.class);
+
+ private BookieLedgerIndexer bookieLedgerIndexer;
Review Comment:
addressed 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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [bookkeeper] wenbingshen commented on pull request #3637: [improvement] Refactor Auditor to simplify the readability
Posted by GitBox <gi...@apache.org>.
wenbingshen commented on PR #3637:
URL: https://github.com/apache/bookkeeper/pull/3637#issuecomment-1316889938
@hangc0276 I have addressed all your comments. PTAL.
--
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: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org