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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to