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 2021/11/22 11:37:25 UTC

[GitHub] [hive] dengzhhu653 commented on a change in pull request #2441: HIVE-25048: Improve the start/end functions in HMSHandler

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



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
##########
@@ -913,74 +900,6 @@ private static void logAndAudit(final String m) {
     logAuditEvent(m);
   }
 
-  private String startFunction(String function, String extraLogInfo) {
-    incrementCounter(function);
-    logAndAudit((getThreadLocalIpAddress() == null ? "" : "source:" + getThreadLocalIpAddress() + " ") +
-        function + extraLogInfo);
-    com.codahale.metrics.Timer timer =
-        Metrics.getOrCreateTimer(MetricsConstants.API_PREFIX + function);

Review comment:
       yes, we have double counted the metrics of api calling by the startFunction and the PerfLogger, e.g, the total call count and the active count of the api. 

##########
File path: standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java
##########
@@ -83,7 +86,7 @@ public void testEndFunctionListener() throws Exception {
     listSize = DummyEndFunctionListener.funcNameList.size();
     String func_name = DummyEndFunctionListener.funcNameList.get(listSize-1);
     MetaStoreEndFunctionContext context = DummyEndFunctionListener.contextList.get(listSize-1);
-    assertEquals(func_name,"get_database");
+    assertEquals(func_name,"get_database_req");

Review comment:
       Thanks a lot for the feedback! you are right, this is where may break compatibility, including the MetaStoreEndFunctionContext(we cannot retrieve inputTableName by method `getInputTableName()` any more). I not so sure if we can make such changes though this can help clean some codes...

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
##########
@@ -4059,7 +3806,7 @@ public Partition append_partition_with_environment_context(final String dbName,
     String location;
 
     PartValEqWrapperLite(Partition partition) {
-      this.values = partition.isSetValues()? partition.getValues() : null;
+      this.values = partition.isSetValues()? new ArrayList<>(partition.getValues()) : null;

Review comment:
       Not a bug really,  just to clean up the codes.  The following pieces of codes can be simply treated as `lhsValues.equals(rhsValues)` by `equals` of an ArrayList.
   
        if (lhsValues.size() != rhsValues.size()) {
           return false;
          }
   
         for (int i=0; i<lhsValues.size(); ++i) {
           String lhsValue = lhsValues.get(i);
           String rhsValue = rhsValues.get(i);
   
           if ((lhsValue == null && rhsValue != null)
               || (lhsValue != null && !lhsValue.equals(rhsValue))) {
             return false;
           }
         }
   
         return true;`

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreAuditLogBuilder.java
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.metastore;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.hive.common.TableName;
+
+import static org.apache.commons.lang3.StringUtils.join;
+
+/**
+ * Generate the audit log in a builder manner.
+ */
+public class MetaStoreAuditLogBuilder {
+  // the function
+  private final String functionName;
+  private final StringBuilder builder;
+
+  private MetaStoreAuditLogBuilder(String functionName) {
+    this.functionName = functionName;
+    this.builder = new StringBuilder();
+  }
+
+  public static MetaStoreAuditLogBuilder functionName(String functionName) {
+    MetaStoreAuditLogBuilder builder = new MetaStoreAuditLogBuilder(functionName);
+    return builder;
+  }
+
+  public MetaStoreAuditLogBuilder connectorName(String connectorName) {
+    builder.append("connector=").append(connectorName).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder catalogName(String catalogName) {
+    builder.append("catName=").append(catalogName).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder dbName(String dbName) {
+    builder.append("db=").append(dbName).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder tableName(String tableName) {
+    builder.append("tbl=").append(tableName).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder packageName(String packageName) {
+    builder.append("package=").append(packageName).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder typeName(String typeName) {
+    builder.append("type=").append(typeName).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder pattern(String pattern) {
+    builder.append("pat=").append(pattern).append(" ");
+    return this;
+  }
+
+  public MetaStoreAuditLogBuilder extraInfo(String extraInfo) {

Review comment:
       Make sense, let me take a look. Thank you!




-- 
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: gitbox-unsubscribe@hive.apache.org

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