From 34d6b12497fb5f3f74ca2502bb75f148e83e5885 Mon Sep 17 00:00:00 2001 From: Yong Zhang Date: Tue, 12 Dec 2023 10:37:07 +0800 Subject: [PATCH] Port the #4058 changes to the branch-4.15 (#4147) --- ### Motivation https://github.com/apache/bookkeeper/pull/4058 --- .../meta/LedgerUnderreplicationManager.java | 5 ++- .../meta/NullMetadataBookieDriver.java | 2 - .../meta/ZkLedgerUnderreplicationManager.java | 1 + .../bookkeeper/replication/Auditor.java | 45 ------------------- .../replication/ReplicationStats.java | 2 - 5 files changed, 4 insertions(+), 51 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerUnderreplicationManager.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerUnderreplicationManager.java index c24f9208023..ddfe10076cd 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerUnderreplicationManager.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerUnderreplicationManager.java @@ -242,8 +242,9 @@ boolean initializeLostBookieRecoveryDelay(int lostBookieRecoveryDelay) * @param cb * @throws ReplicationException.UnavailableException */ - void notifyUnderReplicationLedgerChanged(GenericCallback cb) - throws ReplicationException.UnavailableException; + @Deprecated + default void notifyUnderReplicationLedgerChanged(GenericCallback cb) + throws ReplicationException.UnavailableException {} /** * Receive notification asynchronously when the lostBookieRecoveryDelay value is Changed. diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/NullMetadataBookieDriver.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/NullMetadataBookieDriver.java index 4a1e6e419fa..3a4247f6c61 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/NullMetadataBookieDriver.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/NullMetadataBookieDriver.java @@ -394,7 +394,5 @@ public String getReplicationWorkerIdRereplicatingLedger(long ledgerId) throws ReplicationException.UnavailableException { throw new ReplicationException.UnavailableException("null"); } - @Override - public void notifyUnderReplicationLedgerChanged(GenericCallback cb) {} } } diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/ZkLedgerUnderreplicationManager.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/ZkLedgerUnderreplicationManager.java index 3ac346b1ccf..1413e5af340 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/ZkLedgerUnderreplicationManager.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/ZkLedgerUnderreplicationManager.java @@ -871,6 +871,7 @@ public int getLostBookieRecoveryDelay() throws UnavailableException { } } + @SuppressWarnings("deprecation") @Override public void notifyUnderReplicationLedgerChanged(GenericCallback cb) throws UnavailableException { LOG.debug("notifyUnderReplicationLedgerChanged()"); diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java index baf3d8b7cb3..ad14e2c23ee 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java @@ -34,10 +34,8 @@ 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; @@ -47,7 +45,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Stopwatch; import com.google.common.collect.HashMultiset; -import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Multiset; import com.google.common.collect.Sets; @@ -239,11 +236,6 @@ public class Auditor implements AutoCloseable { help = "the number of delayed-bookie-audits cancelled" ) private final Counter numDelayedBookieAuditsCancelled; - @StatsDoc( - name = NUM_REPLICATED_LEDGERS, - help = "the number of replicated ledgers" - ) - private final Counter numReplicatedLedgers; @StatsDoc( name = NUM_LEDGERS_NOT_ADHERING_TO_PLACEMENT_POLICY, help = "Gauge for number of ledgers not adhering to placement policy found in placement policy check" @@ -276,11 +268,6 @@ public class Auditor implements AutoCloseable { + ", this doesn't include ledgers counted towards numLedgersHavingLessThanAQReplicasOfAnEntry" ) private final Gauge numLedgersHavingLessThanWQReplicasOfAnEntry; - @StatsDoc( - name = NUM_UNDER_REPLICATED_LEDGERS_GUAGE, - help = "Gauge for num of underreplicated ledgers" - ) - private final Gauge numUnderReplicatedLedgers; static BookKeeper createBookKeeperClient(ServerConfiguration conf) throws InterruptedException, IOException { return createBookKeeperClient(conf, NullStatsLogger.INSTANCE); @@ -395,7 +382,6 @@ public Auditor(final String bookieIdentifier, 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() { @Override public Integer getDefaultValue() { @@ -476,18 +462,6 @@ public Integer getSample() { }; this.statsLogger.registerGauge(ReplicationStats.NUM_LEDGERS_HAVING_LESS_THAN_WQ_REPLICAS_OF_AN_ENTRY, numLedgersHavingLessThanWQReplicasOfAnEntry); - numUnderReplicatedLedgers = new Gauge() { - @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; @@ -740,15 +714,6 @@ public void start() { submitShutdownTask(); } - try { - this.ledgerUnderreplicationManager.notifyUnderReplicationLedgerChanged( - new UnderReplicatedLedgersChangedCb()); - } catch (UnavailableException ue) { - LOG.error("Exception while registering for under-replicated ledgers change notification, so exiting", - ue); - submitShutdownTask(); - } - scheduleBookieCheckTask(); scheduleCheckAllLedgersTask(); schedulePlacementPolicyCheckTask(); @@ -1089,16 +1054,6 @@ public void run() { }), initialDelay, interval, TimeUnit.SECONDS); } - private class UnderReplicatedLedgersChangedCb implements GenericCallback { - @Override - public void operationComplete(int rc, Void result) { - Iterator underreplicatedLedgersInfo = ledgerUnderreplicationManager - .listLedgersToRereplicate(null); - underReplicatedLedgersGuageValue.set(Iterators.size(underreplicatedLedgersInfo)); - numReplicatedLedgers.inc(); - } - } - private class LostBookieRecoveryDelayChangedCb implements GenericCallback { @Override public void operationComplete(int rc, Void result) { diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationStats.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationStats.java index 74b76b23b22..d04fcf04279 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationStats.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationStats.java @@ -64,6 +64,4 @@ public interface ReplicationStats { String REPLICATE_EXCEPTION = "exceptions"; String NUM_DEFER_LEDGER_LOCK_RELEASE_OF_FAILED_LEDGER = "NUM_DEFER_LEDGER_LOCK_RELEASE_OF_FAILED_LEDGER"; String NUM_ENTRIES_UNABLE_TO_READ_FOR_REPLICATION = "NUM_ENTRIES_UNABLE_TO_READ_FOR_REPLICATION"; - String NUM_UNDER_REPLICATED_LEDGERS_GUAGE = "NUM_UNDER_REPLICATED_LEDGERS_GUAGE"; - String NUM_REPLICATED_LEDGERS = "NUM_REPLICATED_LEDGERS"; }