hangc0276 commented on code in PR #4873:
URL: https://github.com/apache/bookkeeper/pull/4873#discussion_r4749828777
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -88,24 +88,47 @@ protected CompletableFuture<?>
publishSuspectedLedgersAsync(Collection<String> m
.attr("ledgers", ledgers)
.attr("missingBookies", missingBookies)
.log("Following ledgers are identified as underreplicated");
-
auditorStats.getNumUnderReplicatedLedger().registerSuccessfulValue(ledgers.size());
+ LongAdder publishedLedgers = new LongAdder();
LongAdder underReplicatedSize = new LongAdder();
- FutureUtils.processList(
+ CompletableFuture<List<Void>> publishFuture = FutureUtils.processList(
Lists.newArrayList(ledgers),
- ledgerId ->
-
ledgerManager.readLedgerMetadata(ledgerId).whenComplete((metadata, exception)
-> {
- if (exception == null) {
-
underReplicatedSize.add(metadata.getValue().getLength());
- }
- }), null).whenComplete((res, e) -> {
+ ledgerId ->
ledgerManager.readLedgerMetadata(ledgerId).handle((metadata, exception) -> {
+ if (exception != null) {
+ if (BKException.getExceptionCode(exception)
+ ==
BKException.Code.NoSuchLedgerExistsOnMetadataServerException) {
+ log.info()
+ .attr("ledgerId", ledgerId)
+ .log("Ledger was deleted before publishing
underreplicated mark");
+ return FutureUtils.Void();
+ }
+ log.warn()
+ .attr("ledgerId", ledgerId)
+ .exception(exception)
+ .log("Unable to read ledger metadata;
publishing underreplicated mark fail-open");
+ } else if (metadata == null || metadata.getValue() ==
null) {
+ log.warn()
+ .attr("ledgerId", ledgerId)
+ .log("Ledger metadata was empty; publishing
underreplicated mark fail-open");
+ } else if (metadata.getValue().getWriteQuorumSize() == 1) {
+ auditorStats.getNumSingleReplicaLedgersSkipped().inc();
Review Comment:
Nit: this counter counts (bookie, ledger) pairs rather than ledgers.
`AuditorBookieCheckTask.handleLostBookiesAsync` calls
`publishSuspectedLedgersAsync` once per lost bookie, so a `writeQuorumSize=1`
ledger striped over two failed bookies is read, skipped and counted twice. The
help text says "the number of single-replica ledgers skipped".
Reproduced with one single-replica ledger indexed under two failed bookies:
`testAdvSingleLedgerOnTwoFailedBookiesCountsAsOneSkippedLedger` fails with `one
ledger was skipped expected:<1> but was:<2>`. The same ledger on one bookie
counts 1 (control passes). Since the doc tells operators to alert on this
counter, the value grows with the number of failed bookies. Suggest grouping
ledgers across the lost bookies before publishing (one publish per ledger with
all its missing bookies), or de-duplicating the skip count per audit run.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -88,24 +88,47 @@ protected CompletableFuture<?>
publishSuspectedLedgersAsync(Collection<String> m
.attr("ledgers", ledgers)
.attr("missingBookies", missingBookies)
.log("Following ledgers are identified as underreplicated");
-
auditorStats.getNumUnderReplicatedLedger().registerSuccessfulValue(ledgers.size());
+ LongAdder publishedLedgers = new LongAdder();
LongAdder underReplicatedSize = new LongAdder();
- FutureUtils.processList(
+ CompletableFuture<List<Void>> publishFuture = FutureUtils.processList(
Lists.newArrayList(ledgers),
- ledgerId ->
-
ledgerManager.readLedgerMetadata(ledgerId).whenComplete((metadata, exception)
-> {
- if (exception == null) {
-
underReplicatedSize.add(metadata.getValue().getLength());
- }
- }), null).whenComplete((res, e) -> {
+ ledgerId ->
ledgerManager.readLedgerMetadata(ledgerId).handle((metadata, exception) -> {
Review Comment:
Nit: marking now depends on this metadata read completing. Before this PR
the read only fed the size statistic and `markLedgerUnderreplicatedAsync` ran
independently; now a ledger is only marked after its read future completes, and
`AuditorBookieCheckTask.auditBookies` blocks on the combined future with
`FutureUtils.result(...)` and no timeout. A read that never completes (rather
than failing) leaves that ledger unmarked and the audit thread waiting.
Reproduced with a never-completing `readLedgerMetadata` future for one
ledger: after 500 ms `markLedgerUnderreplicatedAsync` was never called
(`testAdvPendingMetadataReadDoesNotBlockMarking`). The control with a completed
read marks as expected. Real ZooKeeper failures complete the future with an
error and are handled fail-open here, so this only matters for a read that
never completes, and the mark call itself has the same exposure; this just adds
one more call to the chain. A timeout on the read that falls back to the
fail-open path (mark anyway) would keep the old liveness.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java:
##########
@@ -441,78 +455,91 @@ private Set<LedgerFragment>
getNeedRepairedPlacementNotAdheringFragments(LedgerH
}
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
- private boolean rereplicate(long ledgerIdToReplicate) throws
InterruptedException, BKException,
+ private RereplicateResult rereplicate(long ledgerIdToReplicate) throws
InterruptedException, BKException,
UnavailableException {
log.debug().attr("ledgerId", ledgerIdToReplicate).log("Going to
replicate the fragments of the ledger");
boolean deferLedgerLockRelease = false;
- try (LedgerHandle lh =
admin.openLedgerNoRecovery(ledgerIdToReplicate)) {
- Set<LedgerFragment> fragments = getUnderreplicatedFragments(lh,
- conf.getAuditorLedgerVerificationPercentage());
+ try {
+ if (skipHistoricalSingleReplicaLedger(ledgerIdToReplicate)) {
Review Comment:
Cost note (not measured): this guard runs for every ledger the worker
handles, not just single-replica ones. For a normal ledger it reads the
underreplication znode (`getLedgerUnreplicationInfo`) and, when the replica
list is non-empty, does a blocking `readLedgerMetadata`; then
`admin.openLedgerNoRecovery` below reads the same metadata again. After a
bookie failure with a large number of ledgers that is extra ZooKeeper work on
the recovery hot path.
Possible alternative: open the ledger first and check
`lh.getLedgerMetadata().getWriteQuorumSize() == 1` on the handle you already
have, keeping the replica-list check on the underreplication info you already
read. (I did not run `TestReplicationWorker`, which needs real bookies, so this
comes from reading the code.)
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorTask.java:
##########
@@ -88,24 +88,47 @@ protected CompletableFuture<?>
publishSuspectedLedgersAsync(Collection<String> m
.attr("ledgers", ledgers)
.attr("missingBookies", missingBookies)
.log("Following ledgers are identified as underreplicated");
-
auditorStats.getNumUnderReplicatedLedger().registerSuccessfulValue(ledgers.size());
+ LongAdder publishedLedgers = new LongAdder();
LongAdder underReplicatedSize = new LongAdder();
- FutureUtils.processList(
+ CompletableFuture<List<Void>> publishFuture = FutureUtils.processList(
Lists.newArrayList(ledgers),
- ledgerId ->
-
ledgerManager.readLedgerMetadata(ledgerId).whenComplete((metadata, exception)
-> {
- if (exception == null) {
-
underReplicatedSize.add(metadata.getValue().getLength());
- }
- }), null).whenComplete((res, e) -> {
+ ledgerId ->
ledgerManager.readLedgerMetadata(ledgerId).handle((metadata, exception) -> {
+ if (exception != null) {
+ if (BKException.getExceptionCode(exception)
+ ==
BKException.Code.NoSuchLedgerExistsOnMetadataServerException) {
+ log.info()
+ .attr("ledgerId", ledgerId)
+ .log("Ledger was deleted before publishing
underreplicated mark");
+ return FutureUtils.Void();
+ }
+ log.warn()
+ .attr("ledgerId", ledgerId)
+ .exception(exception)
+ .log("Unable to read ledger metadata;
publishing underreplicated mark fail-open");
+ } else if (metadata == null || metadata.getValue() ==
null) {
+ log.warn()
+ .attr("ledgerId", ledgerId)
+ .log("Ledger metadata was empty; publishing
underreplicated mark fail-open");
+ } else if (metadata.getValue().getWriteQuorumSize() == 1) {
+ auditorStats.getNumSingleReplicaLedgersSkipped().inc();
+ log.info()
+ .attr("ledgerId", ledgerId)
+ .attr("writeQuorumSize",
metadata.getValue().getWriteQuorumSize())
+ .attr("reason", "single-replica-ledger")
+ .attr("action", "skip-publish")
+ .log("Skipping underreplicated mark");
+ return FutureUtils.Void();
+ } else {
+
underReplicatedSize.add(metadata.getValue().getLength());
Review Comment:
Test gap: nothing asserts `getUnderReplicatedLedgerTotalSize()`. I removed
just this `underReplicatedSize.add(...)` line and every test in
`AuditorBookieCheckTaskTest` still passed.
A test that fails without the line and passes with it (one ledger with
`writeQuorumSize=2` and `getLength()` returning 4096, with the size stat
mocked):
```java
bookieCheckTask.publishSuspectedLedgersAsync(Lists.newArrayList("127.0.0.1:1000"),
ledgerIds).join();
verify(sizeStats).registerSuccessfulValue(4096L);
```
The description says size is counted "only for ledgers actually submitted",
so a case with a skipped single-replica ledger next to a published one would
pin that as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]