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

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java
 ##########
 @@ -466,80 +487,141 @@ public void start() {
                 submitShutdownTask();
             }
 
-            long bookieCheckInterval = 
conf.getAuditorPeriodicBookieCheckInterval();
-            if (bookieCheckInterval == 0) {
-                LOG.info("Auditor periodic bookie checking disabled, running 
once check now anyhow");
-                executor.submit(bookieCheck);
-            } else {
-                LOG.info("Auditor periodic bookie checking enabled"
-                         + " 'auditorPeriodicBookieCheckInterval' {} seconds", 
bookieCheckInterval);
-                executor.scheduleAtFixedRate(bookieCheck, 0, 
bookieCheckInterval, TimeUnit.SECONDS);
-            }
+            scheduleBookieCheckTask();
+            scheduleCheckAllLedgersTask();
+            scheduleMetadataCheckTask();
+        }
+    }
 
-            long interval = conf.getAuditorPeriodicCheckInterval();
+    private void scheduleBookieCheckTask() {
+        long bookieCheckInterval = 
conf.getAuditorPeriodicBookieCheckInterval();
+        if (bookieCheckInterval == 0) {
+            LOG.info("Auditor periodic bookie checking disabled, running once 
check now anyhow");
+            executor.submit(bookieCheck);
+        } else {
+            LOG.info("Auditor periodic bookie checking enabled" + " 
'auditorPeriodicBookieCheckInterval' {} seconds",
+                    bookieCheckInterval);
+            executor.scheduleAtFixedRate(bookieCheck, 0, bookieCheckInterval, 
TimeUnit.SECONDS);
+        }
+    }
 
-            if (interval > 0) {
-                LOG.info("Auditor periodic ledger checking enabled" + " 
'auditorPeriodicCheckInterval' {} seconds",
-                        interval);
+    private void scheduleCheckAllLedgersTask(){
+        long interval = conf.getAuditorPeriodicCheckInterval();
 
-                long checkAllLedgersLastExecutedCTime;
-                long durationSinceLastExecutionInSecs;
-                long initialDelay;
-                try {
-                    checkAllLedgersLastExecutedCTime = 
ledgerUnderreplicationManager.getCheckAllLedgersCTime();
-                } catch (UnavailableException ue) {
-                    LOG.error("Got UnavailableException while trying to get 
checkAllLedgersCTime", ue);
-                    checkAllLedgersLastExecutedCTime = -1;
-                }
-                if (checkAllLedgersLastExecutedCTime == -1) {
-                    durationSinceLastExecutionInSecs = -1;
-                    initialDelay = 0;
-                } else {
-                    durationSinceLastExecutionInSecs = 
(System.currentTimeMillis() - checkAllLedgersLastExecutedCTime)
-                            / 1000;
-                    if (durationSinceLastExecutionInSecs < 0) {
-                        // this can happen if there is no strict time ordering
-                        durationSinceLastExecutionInSecs = 0;
-                    }
-                    initialDelay = durationSinceLastExecutionInSecs > interval 
? 0
-                            : (interval - durationSinceLastExecutionInSecs);
+        if (interval > 0) {
+            LOG.info("Auditor periodic ledger checking enabled" + " 
'auditorPeriodicCheckInterval' {} seconds",
+                    interval);
+
+            long checkAllLedgersLastExecutedCTime;
+            long durationSinceLastExecutionInSecs;
+            long initialDelay;
+            try {
+                checkAllLedgersLastExecutedCTime = 
ledgerUnderreplicationManager.getCheckAllLedgersCTime();
+            } catch (UnavailableException ue) {
+                LOG.error("Got UnavailableException while trying to get 
checkAllLedgersCTime", ue);
+                checkAllLedgersLastExecutedCTime = -1;
+            }
+            if (checkAllLedgersLastExecutedCTime == -1) {
+                durationSinceLastExecutionInSecs = -1;
+                initialDelay = 0;
+            } else {
+                durationSinceLastExecutionInSecs = (System.currentTimeMillis() 
- checkAllLedgersLastExecutedCTime)
+                        / 1000;
+                if (durationSinceLastExecutionInSecs < 0) {
+                    // this can happen if there is no strict time ordering
+                    durationSinceLastExecutionInSecs = 0;
                 }
-                LOG.info(
-                        "checkAllLedgers scheduling info.  
checkAllLedgersLastExecutedCTime: {} "
-                                + "durationSinceLastExecutionInSecs: {} 
initialDelay: {} interval: {}",
-                        checkAllLedgersLastExecutedCTime, 
durationSinceLastExecutionInSecs, initialDelay, interval);
-
-                executor.scheduleAtFixedRate(new Runnable() {
-                    public void run() {
-                        try {
-                            if 
(!ledgerUnderreplicationManager.isLedgerReplicationEnabled()) {
-                                LOG.info("Ledger replication disabled, 
skipping checkAllLedgers");
-                                return;
-                            }
+                initialDelay = durationSinceLastExecutionInSecs > interval ? 0
+                        : (interval - durationSinceLastExecutionInSecs);
+            }
+            LOG.info(
+                    "checkAllLedgers scheduling info.  
checkAllLedgersLastExecutedCTime: {} "
+                            + "durationSinceLastExecutionInSecs: {} 
initialDelay: {} interval: {}",
+                    checkAllLedgersLastExecutedCTime, 
durationSinceLastExecutionInSecs, initialDelay, interval);
 
-                            Stopwatch stopwatch = Stopwatch.createStarted();
-                            LOG.info("Starting checkAllLedgers");
-                            checkAllLedgers();
-                            long checkAllLedgersDuration = 
stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
-                            LOG.info("Completed checkAllLedgers in {} 
milliSeconds", checkAllLedgersDuration);
-                            
checkAllLedgersTime.registerSuccessfulEvent(checkAllLedgersDuration, 
TimeUnit.MILLISECONDS);
-                        } catch (KeeperException ke) {
-                            LOG.error("Exception while running periodic 
check", ke);
-                        } catch (InterruptedException ie) {
-                            Thread.currentThread().interrupt();
-                            LOG.error("Interrupted while running periodic 
check", ie);
-                        } catch (BKException bke) {
-                            LOG.error("Exception running periodic check", bke);
-                        } catch (IOException ioe) {
-                            LOG.error("I/O exception running periodic check", 
ioe);
-                        } catch (ReplicationException.UnavailableException ue) 
{
-                            LOG.error("Underreplication manager unavailable 
running periodic check", ue);
+            executor.scheduleAtFixedRate(new Runnable() {
+                public void run() {
+                    try {
+                        if 
(!ledgerUnderreplicationManager.isLedgerReplicationEnabled()) {
+                            LOG.info("Ledger replication disabled, skipping 
checkAllLedgers");
+                            return;
                         }
+
+                        Stopwatch stopwatch = Stopwatch.createStarted();
+                        LOG.info("Starting checkAllLedgers");
+                        checkAllLedgers();
+                        long checkAllLedgersDuration = 
stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
+                        LOG.info("Completed checkAllLedgers in {} 
milliSeconds", checkAllLedgersDuration);
+                        
checkAllLedgersTime.registerSuccessfulEvent(checkAllLedgersDuration, 
TimeUnit.MILLISECONDS);
+                    } catch (KeeperException ke) {
+                        LOG.error("Exception while running periodic check", 
ke);
+                    } catch (InterruptedException ie) {
+                        Thread.currentThread().interrupt();
+                        LOG.error("Interrupted while running periodic check", 
ie);
+                    } catch (BKException bke) {
+                        LOG.error("Exception running periodic check", bke);
+                    } catch (IOException ioe) {
+                        LOG.error("I/O exception running periodic check", ioe);
+                    } catch (ReplicationException.UnavailableException ue) {
+                        LOG.error("Underreplication manager unavailable 
running periodic check", ue);
                     }
-                    }, initialDelay, interval, TimeUnit.SECONDS);
+                }
+                }, initialDelay, interval, TimeUnit.SECONDS);
+        } else {
+            LOG.info("Periodic checking disabled");
+        }
+    }
+
+    private void scheduleMetadataCheckTask(){
+        long interval = conf.getAuditorPeriodicMetadataCheckInterval();
+
+        if (interval > 0) {
+            LOG.info("Auditor periodic metadata check enabled" + " 
'auditorPeriodicMetadataCheckInterval' {} seconds",
+                    interval);
+
+            long metadataCheckLastExecutedCTime;
+            long durationSinceLastExecutionInSecs;
+            long initialDelay;
+            try {
+                metadataCheckLastExecutedCTime = 
ledgerUnderreplicationManager.getMetadataCheckCTime();
+            } catch (UnavailableException ue) {
+                LOG.error("Got UnavailableException while trying to get 
metadataCheckCTime", ue);
+                metadataCheckLastExecutedCTime = -1;
+            }
+            if (metadataCheckLastExecutedCTime == -1) {
+                durationSinceLastExecutionInSecs = -1;
+                initialDelay = 0;
             } else {
-                LOG.info("Periodic checking disabled");
+                durationSinceLastExecutionInSecs = (System.currentTimeMillis() 
- metadataCheckLastExecutedCTime)
+                        / 1000;
+                if (durationSinceLastExecutionInSecs < 0) {
+                    // this can happen if there is no strict time ordering
+                    durationSinceLastExecutionInSecs = 0;
+                }
+                initialDelay = durationSinceLastExecutionInSecs > interval ? 0
+                        : (interval - durationSinceLastExecutionInSecs);
             }
+            LOG.info(
+                    "metadataCheck scheduling info.  
metadataCheckLastExecutedCTime: {} "
+                            + "durationSinceLastExecutionInSecs: {} 
initialDelay: {} interval: {}",
+                            metadataCheckLastExecutedCTime, 
durationSinceLastExecutionInSecs, initialDelay, interval);
+
+            executor.scheduleAtFixedRate(new Runnable() {
+                public void run() {
+                    try {
+                        Stopwatch stopwatch = Stopwatch.createStarted();
+                        LOG.info("Starting MetadataCheck");
+                        metadataCheck();
 
 Review comment:
   we are running in single threaded executor, so it will always be single 
instance

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