Radiancebobo commented on code in PR #4873:
URL: https://github.com/apache/bookkeeper/pull/4873#discussion_r4754317819


##########
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:
   Added the size assertion to the mixed-ledger test: the published ledger has 
length 4096 and the skipped single-replica ledger has length 8192. The test 
verifies that the published count is 1 and the reported size is 4096.
   
   I also verified that removing `underReplicatedSize.add(...)`  makes this 
test fail with an actual size of 0.



-- 
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]

Reply via email to