You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/07/07 11:15:12 UTC

[GitHub] [hive] dengzhhu653 commented on a change in pull request #1205: HIVE-23800: Make HiveServer2 oom hook interface

dengzhhu653 commented on a change in pull request #1205:
URL: https://github.com/apache/hive/pull/1205#discussion_r450788257



##########
File path: service/src/java/org/apache/hive/service/server/HiveServer2OomHookRunner.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.hive.service.server;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hive.common.JavaUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+public class HiveServer2OomHookRunner implements Runnable {
+
+  private static final Logger LOG = LoggerFactory.getLogger(HiveServer2OomHookRunner.class);
+  private OomHookContext context;
+  private final List<OomHookWithContext> hooks = new ArrayList<OomHookWithContext>();
+
+  HiveServer2OomHookRunner(HiveServer2 hiveServer2, HiveConf hiveConf) {
+    context = new OomHookContext(hiveServer2);
+    // The hs2 has not been initialized yet, hiveServer2.getHiveConf() would be null
+    init(hiveConf);
+  }
+
+  private void init(HiveConf hiveConf) {
+    String csHooks = hiveConf.getVar(ConfVars.HIVE_SERVER2_OOM_HOOKS);
+    if (!StringUtils.isBlank(csHooks)) {
+      String[] hookClasses = csHooks.split(",");
+      for (String hookClass : hookClasses) {
+        try {
+          Class clazz =  JavaUtils.loadClass(hookClass.trim());
+          Constructor ctor = clazz.getDeclaredConstructor();
+          ctor.setAccessible(true);

Review comment:
       Thanks for the review! Like DefaultOomHook, the hook declared as private as nobody would access it  except the HiveServer2OomHookRunner.  In this case, the default constructor cannot be used directly to create a instance until calling setAccessible(true).  The hooks loaded by HookRunner::loadHooksFromConf should be declared as public access and I'm willing to follow this principal.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org