hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-21884) Scheduled query support
Date Mon, 07 Oct 2019 23:47:09 GMT

     [ https://issues.apache.org/jira/browse/HIVE-21884?focusedWorklogId=324709&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-324709
]

ASF GitHub Bot logged work on HIVE-21884:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 07/Oct/19 23:46
            Start Date: 07/Oct/19 23:46
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on pull request #794: HIVE-21884
URL: https://github.com/apache/hive/pull/794#discussion_r332269978
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/schq/ScheduledQueryExecutionService.java
 ##########
 @@ -0,0 +1,159 @@
+package org.apache.hadoop.hive.ql.schq;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.api.QueryState;
+import org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse;
+import org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo;
+import org.apache.hadoop.hive.ql.DriverFactory;
+import org.apache.hadoop.hive.ql.IDriver;
+import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+public class ScheduledQueryExecutionService implements Closeable {
+
+  private static final Logger LOG = LoggerFactory.getLogger(ScheduledQueryExecutionService.class);
+
+  private ScheduledQueryExecutionContext context;
+  private ScheduledQueryExecutor worker;
+
+  public static ScheduledQueryExecutionService startScheduledQueryExecutorService(HiveConf
conf) {
+    MetastoreBasedScheduledQueryService qService = new MetastoreBasedScheduledQueryService(conf);
+    ExecutorService executor =
+        Executors.newCachedThreadPool(
+            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Scheduled Query Thread
%d").build());
+    ScheduledQueryExecutionContext ctx = new ScheduledQueryExecutionContext(executor, conf,
qService);
+    return new ScheduledQueryExecutionService(ctx);
+  }
+
+  public ScheduledQueryExecutionService(ScheduledQueryExecutionContext ctx) {
+    context = ctx;
+    ctx.executor.submit(worker = new ScheduledQueryExecutor());
+    ctx.executor.submit(new ProgressReporter());
+  }
+
+  class ScheduledQueryExecutor implements Runnable {
+
+    private ScheduledQueryProgressInfo info;
+
+    @Override
+    public void run() {
+      while (true) {
+        ScheduledQueryPollResponse q = context.schedulerService.scheduledQueryPoll();
+        if (q.isSetExecutionId()) {
+          try{
+            processQuery(q);
+          } catch (Throwable t) {
+            LOG.error("Unexpected exception during scheduled query processing", t);
+          }
+        } else {
+          try {
+            Thread.sleep(context.getIdleSleepTime());
+          } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            LOG.info("interrupted");
+            break;
+          }
+        }
+      }
+    }
+
+    QueryState lastState;
+    public synchronized void reportQueryProgress() {
+      if (info != null) {
+        if(lastState == QueryState.FINISHED || lastState == QueryState.ERRORED) {
+          return;
+        }
+        LOG.info("Reporting query progress of {} as {} err:{}", info.getScheduledExecutionId(),
info.getState(),
+            info.getErrorMessage());
+        context.schedulerService.scheduledQueryProgress(info);
+        lastState=info.getState();
+      }
+    }
+
+    private void processQuery(ScheduledQueryPollResponse q) {
+      SessionState state = null;
+      try {
+        state = SessionState.start(context.conf);
+        info = new ScheduledQueryProgressInfo();
+        info.setScheduledExecutionId(q.getExecutionId());
+        info.setState(QueryState.EXECUTING);
+        reportQueryProgress();
+        try (
+          IDriver driver = DriverFactory.newDriver(DriverFactory.getNewQueryState(context.conf),
q.getUser(), null)) {
+          info.setExecutorQueryId(driver.getQueryState().getQueryId());
 
 Review comment:
   This is cool... Basically scheduled execution id matches the query execution id generated
by HS2... which makes it easy to map a scheduled query to the corresponding execution in YARN.
Right?
 
----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 324709)
    Time Spent: 1h 20m  (was: 1h 10m)

> Scheduled query support
> -----------------------
>
>                 Key: HIVE-21884
>                 URL: https://issues.apache.org/jira/browse/HIVE-21884
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-21844.04.patch, HIVE-21844.05.patch, HIVE-21844.06.patch, HIVE-21844.07.patch,
HIVE-21844.08.patch, HIVE-21844.09.patch, HIVE-21844.15.patch, HIVE-21844.19.patch, HIVE-21884.01.patch,
HIVE-21884.02.patch, HIVE-21884.03.patch, HIVE-21884.09.patch, HIVE-21884.10.patch, HIVE-21884.10.patch,
HIVE-21884.11.patch, HIVE-21884.12.patch, HIVE-21884.13.patch, HIVE-21884.14.patch, HIVE-21884.14.patch,
HIVE-21884.14.patch, HIVE-21884.16.patch, HIVE-21884.17.patch, HIVE-21884.18.patch, HIVE-21884.20.patch,
Scheduled queries2.pdf
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> design document:
> https://docs.google.com/document/d/1mJSFdJi_1cbxJTXC9QvGw2rQ3zzJkNfxOO6b5esmyCE/edit#
> in case the google doc is not reachable:  [^Scheduled queries2.pdf] 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message