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

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

                Author: ASF GitHub Bot
            Created on: 22/Nov/21 10:45
            Start Date: 22/Nov/21 10:45
    Worklog Time Spent: 10m 
      Work Description: kgyrtkirk commented on a change in pull request #2441:
URL: https://github.com/apache/hive/pull/2441#discussion_r754132199



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/PerfLogger.java
##########
@@ -186,24 +187,19 @@ public Long getDuration(String method) {
   private transient Timer.Context totalApiCallsTimerContext = null;
 
   private void beginMetrics(String method) {
-    Timer timer = Metrics.getOrCreateTimer(MetricsConstants.API_PREFIX + 
method);
-    if (timer != null) {
-      timerContexts.put(method, timer.time());
-    }
-    timer = Metrics.getOrCreateTimer(MetricsConstants.TOTAL_API_CALLS);
-    if (timer != null) {
-      totalApiCallsTimerContext = timer.time();
-    }
+    Optional.ofNullable(Metrics.getOrCreateTimer(MetricsConstants.API_PREFIX + 
method))
+        .ifPresent(timer -> timerContexts.put(method, timer.time()));
+    
Optional.ofNullable(Metrics.getOrCreateTimer(MetricsConstants.TOTAL_API_CALLS))
+        .ifPresent(timer -> {totalApiCallsTimerContext = timer.time();});
+    
Optional.ofNullable(Metrics.getOrCreateCounter(MetricsConstants.ACTIVE_CALLS + 
method))
+        .ifPresent(counter -> counter.inc());

Review comment:
       I'm usually not agains changes like this - however this seems like a 
pretty hot method:
   
   the old implementation have only created 1 new string objects which will be 
garbage collected - however the new method creates 3 sets of `Nullable` objects 
and some function objects to make the call...
   
   can we add the `ACTIVE_CALLS` stuff the boring way?

##########
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:
       all the callsites of this method look like:
   ```
   " some=" + value
   ```
   they not only expose the internal "key=value" strucutre; but they should 
also add and extra whitespace.
   
   I think it would be better to add arguments like `key, value` - and let the 
builder take up some responsibility.
   
   one more thing: `extraInfo` is pasted directly into the output builder; 
meanwhile for other methods the `key=` is written by this class.

##########
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:
       is this a bugfix? if yes - could you open a separate jira to submit it?

##########
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:
       after this change it seems like `EndFunctionListers` will get a bit 
different data - is that true?

##########
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:
       I wonder if its an error if we already have a timer running for a method 
already - I think in normal cases we may have only one api call running in a 
single connection...




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


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

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

> Refine the start/end functions in HMSHandler
> --------------------------------------------
>
>                 Key: HIVE-25048
>                 URL: https://issues.apache.org/jira/browse/HIVE-25048
>             Project: Hive
>          Issue Type: Improvement
>          Components: Standalone Metastore
>            Reporter: Zhihua Deng
>            Assignee: Zhihua Deng
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 4.5h
>  Remaining Estimate: 0h
>
> Some start/end functions are incomplete or wrong in the HMSHandler, these 
> functions audit actions, monitor the performance, and notify the end function 
> listeners. We have already measured the performance of the HMSHandler in 
> PerfLogger,  and covered more methods than these functions that have done, so 
> we can remove the monitoring from the start/end functions, move the end 
> function listeners to the RetryingHMSHandler to eliminate the try-finally 
> blocks that spread across many different methods. After these, we can try to 
> cleanup the functions to make HMSHandler be more simplified.
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to