reddycharan commented on a change in pull request #1902: Metadata checker 
validating EnsemblePlacementpolicy
URL: https://github.com/apache/bookkeeper/pull/1902#discussion_r251279933
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java
 ##########
 @@ -803,8 +885,72 @@ void checkAllLedgers() throws BKException, IOException, 
InterruptedException, Ke
                 LOG.error("Got exception while trying to set 
checkAllLedgersCTime", ue);
             }
         } finally {
-            admin.close();
-            client.close();
+            localAdmin.close();
+            localClient.close();
+        }
+    }
+
+    void metadataCheck() throws BKAuditException {
+        final CountDownLatch metadataCheckLatch = new CountDownLatch(1);
+        Processor<Long> ledgerProcessor = new Processor<Long>() {
+            @Override
+            public void process(Long ledgerId, AsyncCallback.VoidCallback 
iterCallback) {
+                
ledgerManager.readLedgerMetadata(ledgerId).whenComplete((metadataVer, 
exception) -> {
+                    if (exception == null) {
+                        LedgerMetadata metadata = metadataVer.getValue();
+                        int writeQuorumSize = metadata.getWriteQuorumSize();
+                        int ackQuorumSize = metadata.getAckQuorumSize();
+                        if (metadata.isClosed()) {
+                            for (Map.Entry<Long, ? extends 
List<BookieSocketAddress>> ensemble : metadata
+                                    .getAllEnsembles().entrySet()) {
+                                long startEntryIdOfSegment = ensemble.getKey();
+                                List<BookieSocketAddress> ensembleOfSegment = 
ensemble.getValue();
+                                boolean segmentAdheringToPlacementPolicy = 
admin.isEnsembleAdheringToPlacementPolicy(
+                                        ensembleOfSegment, writeQuorumSize, 
ackQuorumSize);
+                                if (!segmentAdheringToPlacementPolicy) {
+                                    
metadataCheckEnsembleNotAdheringToPlacementPolicy.inc();
+                                    LOG.warn(
+                                            "For ledger: {}, Segment starting 
at entry: {}, with ensemble: {} having "
+                                                    + "writeQuorumSize: {} and 
ackQuorumSize: {} is not adhering to "
+                                                    + 
"EnsemblePlacementPolicy",
+                                            ledgerId, startEntryIdOfSegment, 
ensembleOfSegment, writeQuorumSize,
+                                            ackQuorumSize);
+                                }
+                            }
+                        } else {
+                            LOG.debug("Ledger: {} is not yet closed, so 
skipping the metadata check analysis for now",
+                                    ledgerId);
+                        }
+                        iterCallback.processResult(BKException.Code.OK, null, 
null);
+                    } else if (BKException
+                            .getExceptionCode(exception) == 
BKException.Code.NoSuchLedgerExistsException) {
+                        LOG.debug("Ignoring replication of already deleted 
ledger {}", ledgerId);
+                        iterCallback.processResult(BKException.Code.OK, null, 
null);
+                    } else {
+                        LOG.warn("Unable to read the ledger: {} information", 
ledgerId);
+                        
iterCallback.processResult(BKException.getExceptionCode(exception), null, null);
+                    }
+                });
+            }
+        };
+        // Reading the result after processing all the ledgers
+        final List<Integer> resultCode = new ArrayList<Integer>(1);
+        ledgerManager.asyncProcessLedgers(ledgerProcessor, new 
AsyncCallback.VoidCallback() {
+
+            @Override
+            public void processResult(int rc, String s, Object obj) {
+                resultCode.add(rc);
+                metadataCheckLatch.countDown();
+            }
+        }, null, BKException.Code.OK, BKException.Code.ReadException);
+        try {
+            metadataCheckLatch.await();
 
 Review comment:
   @jvrao @eolivelli considered about it. But currently both in existing 
bookieCheck/auditBookies and checkAllLedgers it is waiting indefinitely. So I 
would like to leave this checker as it is for now. Probably we can revisit 
about handling this possible indefinite wait in all the checkers.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to