You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by ay...@apache.org on 2022/04/26 06:17:46 UTC
[bookkeeper] branch master updated: Add get under replicated ledger count
This is an automated email from the ASF dual-hosted git repository.
ayegorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new f60a4d6d40 Add get under replicated ledger count
f60a4d6d40 is described below
commit f60a4d6d4069b5318f61a378125a1ef4d8471adf
Author: Hang Chen <ch...@apache.org>
AuthorDate: Tue Apr 26 14:17:37 2022 +0800
Add get under replicated ledger count
### Motivation
Fix #3224
### Changes
Add flag for `ListUnderreplicatedCmd` to control only display under replicated ledgers count
Reviewers: Enrico Olivelli <eo...@gmail.com>, Yong Zhang <zh...@gmail.com>, Andrey Yegorov <None>
This closes #3228 from hangc0276/chenhang/add_get_under_replicate_ledger_count
---
.../java/org/apache/bookkeeper/bookie/BookieShell.java | 17 ++++++++++++-----
.../autorecovery/ListUnderReplicatedCommand.java | 14 ++++++++++++++
site3/website/docs/reference/cli.md | 11 ++++++-----
.../autorecovery/ListUnderReplicatedCommandTest.java | 15 +++++++++++++++
4 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
index 80ce07164c..edf9194f16 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
@@ -650,10 +650,15 @@ public class BookieShell implements Tool {
public ListUnderreplicatedCmd() {
super(CMD_LISTUNDERREPLICATED);
- opts.addOption("missingreplica", true, "Bookie Id of missing replica");
- opts.addOption("excludingmissingreplica", true, "Bookie Id of missing replica to ignore");
- opts.addOption("printmissingreplica", false, "Whether to print missingreplicas list?");
- opts.addOption("printreplicationworkerid", false, "Whether to print replicationworkerid?");
+ opts.addOption("mr", "missingreplica", true, "Bookie Id of missing replica");
+ opts.addOption("emr", "excludingmissingreplica", true,
+ "Bookie Id of missing replica to ignore");
+ opts.addOption("pmr", "printmissingreplica", false,
+ "Whether to print missingreplicas list?");
+ opts.addOption("prw", "printreplicationworkerid", false,
+ "Whether to print replicationworkerid?");
+ opts.addOption("c", "onlydisplayledgercount", false,
+ "Only display underreplicated ledger count");
}
@Override
@@ -680,12 +685,14 @@ public class BookieShell implements Tool {
final String excludingBookieId = cmdLine.getOptionValue("excludingmissingreplica");
final boolean printMissingReplica = cmdLine.hasOption("printmissingreplica");
final boolean printReplicationWorkerId = cmdLine.hasOption("printreplicationworkerid");
+ final boolean onlyDisplayLedgerCount = cmdLine.hasOption("onlydisplayledgercount");
ListUnderReplicatedCommand.LURFlags flags = new ListUnderReplicatedCommand.LURFlags()
.missingReplica(includingBookieId)
.excludingMissingReplica(excludingBookieId)
.printMissingReplica(printMissingReplica)
- .printReplicationWorkerId(printReplicationWorkerId);
+ .printReplicationWorkerId(printReplicationWorkerId)
+ .onlyDisplayLedgerCount(onlyDisplayLedgerCount);
ListUnderReplicatedCommand cmd = new ListUnderReplicatedCommand(ledgerIdFormatter);
cmd.apply(bkConf, flags);
return 0;
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommand.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommand.java
index 6888b3bf50..7979d1d1b5 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommand.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommand.java
@@ -25,6 +25,7 @@ import com.google.common.util.concurrent.UncheckedExecutionException;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import lombok.Setter;
import lombok.experimental.Accessors;
@@ -96,6 +97,10 @@ public class ListUnderReplicatedCommand extends BookieCommand<ListUnderReplicate
@Parameter(names = {"-l", "--ledgeridformatter"}, description = "Set ledger id formatter")
private String ledgerIdFormatter = DEFAULT;
+
+ @Parameter(names = {"-c", "--onlydisplayledgercount"},
+ description = "Only display underreplicated ledger count")
+ private boolean onlyDisplayLedgerCount;
}
@Override
@@ -117,6 +122,7 @@ public class ListUnderReplicatedCommand extends BookieCommand<ListUnderReplicate
final String excludingBookieId = flags.excludingMissingReplica;
final boolean printMissingReplica = flags.printMissingReplica;
final boolean printReplicationWorkerId = flags.printReplicationWorkerId;
+ final boolean onlyDisplayLedgerCount = flags.onlyDisplayLedgerCount;
final Predicate<List<String>> predicate;
if (!StringUtils.isBlank(includingBookieId) && !StringUtils.isBlank(excludingBookieId)) {
@@ -130,6 +136,7 @@ public class ListUnderReplicatedCommand extends BookieCommand<ListUnderReplicate
predicate = null;
}
+ AtomicInteger underReplicatedLedgerCount = new AtomicInteger(0);
runFunctionWithLedgerManagerFactory(bkConf, mFactory -> {
LedgerUnderreplicationManager underreplicationManager;
try {
@@ -143,6 +150,11 @@ public class ListUnderReplicatedCommand extends BookieCommand<ListUnderReplicate
Iterator<UnderreplicatedLedger> iter = underreplicationManager.listLedgersToRereplicate(predicate);
while (iter.hasNext()) {
UnderreplicatedLedger underreplicatedLedger = iter.next();
+ underReplicatedLedgerCount.incrementAndGet();
+ if (onlyDisplayLedgerCount) {
+ continue;
+ }
+
long urLedgerId = underreplicatedLedger.getLedgerId();
LOG.info("{}", ledgerIdFormatter.formatLedgerId(urLedgerId));
long ctime = underreplicatedLedger.getCtime();
@@ -167,6 +179,8 @@ public class ListUnderReplicatedCommand extends BookieCommand<ListUnderReplicate
}
}
}
+
+ LOG.info("Under replicated ledger count: {}", underReplicatedLedgerCount.get());
return null;
});
return true;
diff --git a/site3/website/docs/reference/cli.md b/site3/website/docs/reference/cli.md
index b9b1d6ad7d..c493fec3ad 100644
--- a/site3/website/docs/reference/cli.md
+++ b/site3/website/docs/reference/cli.md
@@ -342,12 +342,13 @@ $ bin/bookkeeper shell listunderreplicated \
<options>
```
-| Flag | Description |
-|-----------------------------------------| ----------- |
-| -missingreplica BOOKIE_ADDRESS | Bookie Id of missing replica |
+| Flag | Description |
+|-----------------------------| ----------- |
+| -missingreplica BOOKIE_ADDRESS | Bookie Id of missing replica |
| -excludingmissingreplica BOOKIE_ADDRESS | Bookie Id of missing replica to ignore |
-| -printmissingreplica | Whether to print missingreplicas list? |
-| -printreplicationworkerid | Whether to print replicationworkerid? |
+| -printmissingreplica | Whether to print missingreplicas list? |
+| -printreplicationworkerid | Whether to print replicationworkerid? |
+| -c,--onlydisplayledgercount | Only display underreplicated ledger count |
### metaformat {#bookkeeper-shell-metaformat}
diff --git a/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommandTest.java b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommandTest.java
index e03b0e2def..b4d86828a7 100644
--- a/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommandTest.java
+++ b/tools/ledger/src/test/java/org/apache/bookkeeper/tools/cli/commands/autorecovery/ListUnderReplicatedCommandTest.java
@@ -19,6 +19,7 @@
package org.apache.bookkeeper.tools.cli.commands.autorecovery;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -128,6 +129,20 @@ public class ListUnderReplicatedCommandTest extends BookieCommandTestBase {
verify(underreplicationManager, times(1)).getReplicationWorkerIdRereplicatingLedger(1L);
}
+ @Test
+ public void testOnlyDisplayLedgerCount() throws InterruptedException, KeeperException,
+ ReplicationException.CompatibilityException, ReplicationException.UnavailableException {
+ testCommand("-c");
+
+ verify(factory, times(1)).newLedgerUnderreplicationManager();
+ verify(underreplicationManager, times(1)).listLedgersToRereplicate(any());
+ verify(underreplicationManager, times(0))
+ .getReplicationWorkerIdRereplicatingLedger(anyLong());
+ verify(ledger, times(0)).getLedgerId();
+ verify(ledger, times(0)).getCtime();
+ verify(ledger, times(0)).getReplicaList();
+ }
+
@Test
public void testCommand1() {
ListUnderReplicatedCommand cmd = new ListUnderReplicatedCommand();