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

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

                Author: ASF GitHub Bot
            Created on: 15/Sep/20 12:24
            Start Date: 15/Sep/20 12:24
    Worklog Time Spent: 10m 
      Work Description: kgyrtkirk commented on a change in pull request #1205:
URL: https://github.com/apache/hive/pull/1205#discussion_r488617988



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/hooks/HooksLoader.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.hooks;
+
+import com.cronutils.utils.VisibleForTesting;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hive.common.util.HiveStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ *  Loads and stores different kinds of hooks, provides {@link 
HooksLoader#addHook(HookContext.HookType, Object)}} to
+ *  add hook alone or {@link HooksLoader#getHooks(HookContext.HookType, 
Class)} to get all hooks
+ *  corresponding to the specific hook type.
+ */
+public class HooksLoader {
+  private static final Logger LOG = LoggerFactory.getLogger(HooksLoader.class);
+  private final HiveConf conf;
+  private final Hooks[] hooks;
+  private SessionState.LogHelper console;
+
+  public HooksLoader(HiveConf conf) {
+    this.conf = conf;
+    this.hooks = new Hooks[HookContext.HookType.values().length];
+    for (int i = 0; i < hooks.length; i++) {
+      hooks[i] = new Hooks();
+    }
+  }
+
+  public HooksLoader(HiveConf conf, SessionState.LogHelper console) {
+    this(conf);
+    this.console = console;
+  }
+
+  /**
+   * Loads the configured hooks corresponding to the specific hook type.
+   * @param type hook type
+   */
+  @VisibleForTesting
+  void loadHooksFromConf(HookContext.HookType type) {
+    Hooks container = hooks[type.ordinal()];
+    if (!container.loadedFromConf) {
+      container.loadedFromConf = true;
+      List hooks = container.getHooks();
+      HiveConf.ConfVars confVars = type.getConfVar();

Review comment:
       I think this should be only `confVar`

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/hooks/HooksLoader.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.hooks;
+
+import com.cronutils.utils.VisibleForTesting;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hive.common.util.HiveStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ *  Loads and stores different kinds of hooks, provides {@link 
HooksLoader#addHook(HookContext.HookType, Object)}} to
+ *  add hook alone or {@link HooksLoader#getHooks(HookContext.HookType, 
Class)} to get all hooks
+ *  corresponding to the specific hook type.
+ */
+public class HooksLoader {
+  private static final Logger LOG = LoggerFactory.getLogger(HooksLoader.class);
+  private final HiveConf conf;
+  private final Hooks[] hooks;

Review comment:
       this will make an index based contract - instead of that we could 
utrilize a `Map<HookType,Hook> `

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/hooks/HookContext.java
##########
@@ -45,7 +47,50 @@
 public class HookContext {
 
   static public enum HookType {
-    PRE_EXEC_HOOK, POST_EXEC_HOOK, ON_FAILURE_HOOK
+
+    PRE_EXEC_HOOK(HiveConf.ConfVars.PREEXECHOOKS, ExecuteWithHookContext.class,
+        "Pre-execution hooks to be invoked for each statement"),
+    POST_EXEC_HOOK(HiveConf.ConfVars.POSTEXECHOOKS, 
ExecuteWithHookContext.class,
+        "Post-execution hooks to be invoked for each statement"),
+    ON_FAILURE_HOOK(HiveConf.ConfVars.ONFAILUREHOOKS, 
ExecuteWithHookContext.class,
+        "On-failure hooks to be invoked for each statement"),
+    QUERY_LIFETIME_HOOKS(HiveConf.ConfVars.HIVE_QUERY_LIFETIME_HOOKS, 
QueryLifeTimeHook.class,
+      "Hooks that will be triggered before/after query compilation and 
before/after query execution"),
+    SEMANTIC_ANALYZER_HOOK(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK, 
HiveSemanticAnalyzerHook.class,
+      "Hooks that invoked before/after Hive performs its own semantic analysis 
on a statement"),
+    DRIVER_RUN_HOOKS(HiveConf.ConfVars.HIVE_DRIVER_RUN_HOOKS, 
HiveDriverRunHook.class,
+      "Hooks that Will be run at the beginning and end of Driver.run"),
+    REDACTOR(HiveConf.ConfVars.QUERYREDACTORHOOKS, Redactor.class,
+      "Hooks to be invoked for each query which can tranform the query before 
it's placed in the job.xml file"),
+    // The HiveSessionHook.class cannot access, use Hook.class instead
+    HIVE_SERVER2_SESSION_HOOK(HiveConf.ConfVars.HIVE_SERVER2_SESSION_HOOK, 
Hook.class,
+      "Hooks to be executed when session manager starts a new session"),
+    OOM(HiveConf.ConfVars.HIVE_SERVER2_OOM_HOOKS, Runnable.class,

Review comment:
       please keep some kind of naming contract between the varname and the 
enum key

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/hooks/HooksLoader.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.hooks;
+
+import com.cronutils.utils.VisibleForTesting;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hive.common.util.HiveStringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ *  Loads and stores different kinds of hooks, provides {@link 
HooksLoader#addHook(HookContext.HookType, Object)}} to
+ *  add hook alone or {@link HooksLoader#getHooks(HookContext.HookType, 
Class)} to get all hooks
+ *  corresponding to the specific hook type.
+ */
+public class HooksLoader {
+  private static final Logger LOG = LoggerFactory.getLogger(HooksLoader.class);
+  private final HiveConf conf;
+  private final Hooks[] hooks;
+  private SessionState.LogHelper console;
+
+  public HooksLoader(HiveConf conf) {
+    this.conf = conf;
+    this.hooks = new Hooks[HookContext.HookType.values().length];
+    for (int i = 0; i < hooks.length; i++) {
+      hooks[i] = new Hooks();
+    }
+  }
+
+  public HooksLoader(HiveConf conf, SessionState.LogHelper console) {
+    this(conf);
+    this.console = console;
+  }
+
+  /**
+   * Loads the configured hooks corresponding to the specific hook type.
+   * @param type hook type
+   */
+  @VisibleForTesting
+  void loadHooksFromConf(HookContext.HookType type) {
+    Hooks container = hooks[type.ordinal()];
+    if (!container.loadedFromConf) {

Review comment:
       I don't see any particular benefit of doing the loading lazily - just 
load all of them upfront in the constructor - the Conf *may not* change after 
the creation of this object




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


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

    Worklog Id:     (was: 484452)
    Time Spent: 4.5h  (was: 4h 20m)

> Add hooks when HiveServer2 stops due to OutOfMemoryError
> --------------------------------------------------------
>
>                 Key: HIVE-23800
>                 URL: https://issues.apache.org/jira/browse/HIVE-23800
>             Project: Hive
>          Issue Type: Improvement
>          Components: HiveServer2
>            Reporter: Zhihua Deng
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 4.5h
>  Remaining Estimate: 0h
>
> Make oom hook an interface of HiveServer2,  so user can implement the hook to 
> do something before HS2 stops, such as dumping the heap or altering the 
> devops.



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

Reply via email to