pudidic commented on code in PR #3444:
URL: https://github.com/apache/hive/pull/3444#discussion_r935250830


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/DumpExporter.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.parse.repl.dump;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.ThreadPool;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.*;
+
+public class DumpExporter {
+  private ExecutorService execService;
+  private List<Future<?>> futures;
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(DumpExporter.class);
+
+  public DumpExporter() {
+    execService = null;
+    futures = null;
+  }
+
+  public DumpExporter(HiveConf hiveConf) {
+    final int nDumpThreads = 
hiveConf.getIntVar(HiveConf.ConfVars.REPL_EXPORT_DUMP_PARALLELISM);
+    LOG.debug("DumpExporter created with thread pool size {} ", nDumpThreads);
+    if (nDumpThreads != 0) {
+      ThreadFactory namingThreadFactory = new 
ThreadFactoryBuilder().setNameFormat("TableAndPartition-dump-thread-%d").build();
+      execService = Executors.newFixedThreadPool(nDumpThreads, 
namingThreadFactory);
+      futures = new LinkedList<>();
+    } else {
+      execService = null;
+      futures = null;
+    }
+  }
+
+  public static DumpExporter getSingleThreadedDumpExporter() {
+    return new DumpExporter();
+  }
+
+  public boolean isSingleThreadedDumpExporter() {
+    return execService == null && futures == null;
+  }
+
+  public void submit(Runnable r) {
+    if (execService != null && futures != null) {
+      futures.add(execService.submit(r));
+    } else {
+      r.run();
+    }
+  }
+
+  public void finish() throws HiveException {
+    if (!isSingleThreadedDumpExporter()) {
+      execService.shutdown();
+      for (Future<?> future : futures) {
+        try {
+          future.get();
+        } catch (Exception e) {
+          LOG.error("DumpExporter task failed with reason: {} ", e.getCause());
+          throw new HiveException(e.getMessage(), e);
+        }
+      }
+    }
+  }
+
+  public long getTotalTaskEverExecuted() {
+    if (!isSingleThreadedDumpExporter()) {
+      ThreadPoolExecutor executor = (ThreadPoolExecutor) execService;

Review Comment:
   How about cast in advance? Such as; private ThreadPoolExecutor executor;



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to