NickyYe commented on a change in pull request #2080:
URL: https://github.com/apache/hadoop/pull/2080#discussion_r444685702



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java
##########
@@ -1748,4 +1828,58 @@ public void refreshSuperUserGroupsConfiguration() throws 
IOException {
   public String[] getGroupsForUser(String user) throws IOException {
     return routerProto.getGroupsForUser(user);
   }
-}
\ No newline at end of file
+
+  /**
+   * Deals with loading datanode report into the cache and refresh.
+   */
+  private class DatanodeReportCacheLoader
+      extends CacheLoader<DatanodeReportType, DatanodeInfo[]> {
+
+    private ListeningExecutorService executorService;
+
+    DatanodeReportCacheLoader() {
+      ThreadFactory threadFactory = new ThreadFactoryBuilder()
+          .setNameFormat("DatanodeReport-Cache-Reload")
+          .setDaemon(true)
+          .build();
+
+      // Only use 1 thread to refresh cache.
+      // With coreThreadCount == maxThreadCount we effectively
+      // create a fixed size thread pool. As allowCoreThreadTimeOut
+      // has been set, all threads will die after 60 seconds of non use.
+      ThreadPoolExecutor parentExecutor = new ThreadPoolExecutor(
+          1,
+          1,
+          60,
+          TimeUnit.SECONDS,
+          new LinkedBlockingQueue<Runnable>(),
+          threadFactory);
+      parentExecutor.allowCoreThreadTimeOut(true);
+      executorService = MoreExecutors.listeningDecorator(parentExecutor);
+    }
+
+    @Override
+    public DatanodeInfo[] load(DatanodeReportType type) throws Exception {
+      return getCachedDatanodeReportImpl(type);
+    }
+
+    /**
+     * Override the reload method to provide an asynchronous implementation,
+     * so that the query will not be slowed down by the cache refresh. It
+     * will return the old cache value and schedule a background refresh.
+     */
+    @Override
+    public ListenableFuture<DatanodeInfo[]> reload(
+        final DatanodeReportType type, DatanodeInfo[] oldValue)
+        throws Exception {
+      ListenableFuture<DatanodeInfo[]> listenableFuture =

Review comment:
       Thank you for the comments. I've addressed all of them.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to