You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ai...@apache.org on 2016/04/27 01:32:54 UTC
hive git commit: HIVE-13585: Add counter metric for direct sql
failures (Mohit Sabharwal, reviewed by Aihua Xu, Sergey Shelukhin)
Repository: hive
Updated Branches:
refs/heads/master 972bcba7a -> 815499af9
HIVE-13585: Add counter metric for direct sql failures (Mohit Sabharwal, reviewed by Aihua Xu, Sergey Shelukhin)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/815499af
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/815499af
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/815499af
Branch: refs/heads/master
Commit: 815499af9543687948b0330c1f8793bfbf2dea67
Parents: 972bcba
Author: Aihua Xu <ax...@cloudera.com>
Authored: Tue Apr 26 19:31:40 2016 -0400
Committer: Aihua Xu <ax...@cloudera.com>
Committed: Tue Apr 26 19:31:40 2016 -0400
----------------------------------------------------------------------
.../common/metrics/common/MetricsConstant.java | 2 +
metastore/pom.xml | 8 ++++
.../hadoop/hive/metastore/ObjectStore.java | 19 +++++++-
.../hadoop/hive/metastore/TestObjectStore.java | 50 ++++++++++++++++++++
4 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/815499af/common/src/java/org/apache/hadoop/hive/common/metrics/common/MetricsConstant.java
----------------------------------------------------------------------
diff --git a/common/src/java/org/apache/hadoop/hive/common/metrics/common/MetricsConstant.java b/common/src/java/org/apache/hadoop/hive/common/metrics/common/MetricsConstant.java
index 65b914c..b0d2b85 100644
--- a/common/src/java/org/apache/hadoop/hive/common/metrics/common/MetricsConstant.java
+++ b/common/src/java/org/apache/hadoop/hive/common/metrics/common/MetricsConstant.java
@@ -55,4 +55,6 @@ public class MetricsConstant {
public static final String DELETE_TOTAL_DATABASES = "delete_total_count_dbs";
public static final String DELETE_TOTAL_TABLES = "delete_total_count_tables";
public static final String DELETE_TOTAL_PARTITIONS = "delete_total_count_partitions";
+
+ public static final String DIRECTSQL_ERRORS = "directsql_errors";
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/815499af/metastore/pom.xml
----------------------------------------------------------------------
diff --git a/metastore/pom.xml b/metastore/pom.xml
index 18c1f9c..8816829 100644
--- a/metastore/pom.xml
+++ b/metastore/pom.xml
@@ -207,6 +207,14 @@
<artifactId>tephra-hbase-compat-1.0</artifactId>
<version>${tephra.version}</version>
</dependency>
+ <!-- test intra-project -->
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<!-- test inter-project -->
<dependency>
<groupId>junit</groupId>
http://git-wip-us.apache.org/repos/asf/hive/blob/815499af/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index 24fbf70..f651a13 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -63,6 +63,9 @@ import org.apache.hadoop.hive.common.ObjectPair;
import org.apache.hadoop.hive.common.StatsSetupConst;
import org.apache.hadoop.hive.common.classification.InterfaceAudience;
import org.apache.hadoop.hive.common.classification.InterfaceStability;
+import org.apache.hadoop.hive.common.metrics.common.Metrics;
+import org.apache.hadoop.hive.common.metrics.common.MetricsConstant;
+import org.apache.hadoop.hive.common.metrics.common.MetricsFactory;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.metastore.api.AggrStats;
@@ -2556,7 +2559,8 @@ public class ObjectStore implements RawStore, Configurable {
}
/** Helper class for getting stuff w/transaction, direct SQL, perf logging, etc. */
- private abstract class GetHelper<T> {
+ @VisibleForTesting
+ public abstract class GetHelper<T> {
private final boolean isInTxn, doTrace, allowJdo;
private boolean doUseDirectSql;
private long start;
@@ -2668,6 +2672,16 @@ public class ObjectStore implements RawStore, Configurable {
} else {
start = doTrace ? System.nanoTime() : 0;
}
+
+ Metrics metrics = MetricsFactory.getInstance();
+ if (metrics != null) {
+ try {
+ metrics.incrementCounter(MetricsConstant.DIRECTSQL_ERRORS);
+ } catch (Exception e) {
+ LOG.warn("Error reporting Direct SQL errors to metrics system", e);
+ }
+ }
+
doUseDirectSql = false;
}
@@ -2707,7 +2721,8 @@ public class ObjectStore implements RawStore, Configurable {
}
}
- private abstract class GetDbHelper extends GetHelper<Database> {
+ @VisibleForTesting
+ public abstract class GetDbHelper extends GetHelper<Database> {
/**
* GetHelper for returning db info using directSql/JDO.
* Since this is a db-level call, tblName is ignored, and null is passed irrespective of what is passed in.
http://git-wip-us.apache.org/repos/asf/hive/blob/815499af/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
----------------------------------------------------------------------
diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java b/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
index 2e1f5f4..6cb062a 100644
--- a/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
+++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestObjectStore.java
@@ -21,6 +21,11 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
+import org.apache.hadoop.hive.common.metrics.common.MetricsConstant;
+import org.apache.hadoop.hive.common.metrics.common.MetricsFactory;
+import org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics;
+import org.apache.hadoop.hive.common.metrics.metrics2.MetricsReporting;
+import org.apache.hadoop.hive.common.metrics.MetricsTestUtils;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -244,6 +249,51 @@ public class TestObjectStore {
objectStore.removeRole(ROLE1);
}
+ @Test
+ public void testDirectSqlErrorMetrics() throws Exception {
+ HiveConf conf = new HiveConf();
+ conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED, true);
+ conf.setVar(HiveConf.ConfVars.HIVE_METRICS_REPORTER, MetricsReporting.JSON_FILE.name()
+ + "," + MetricsReporting.JMX.name());
+
+ MetricsFactory.init(conf);
+ CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance();
+
+ objectStore.new GetDbHelper("foo", null, true, true) {
+ @Override
+ protected Database getSqlResult(ObjectStore.GetHelper<Database> ctx) throws MetaException {
+ return null;
+ }
+
+ @Override
+ protected Database getJdoResult(ObjectStore.GetHelper<Database> ctx) throws MetaException,
+ NoSuchObjectException {
+ return null;
+ }
+ }.run(false);
+
+ String json = metrics.dumpJson();
+ MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER,
+ MetricsConstant.DIRECTSQL_ERRORS, "");
+
+ objectStore.new GetDbHelper("foo", null, true, true) {
+ @Override
+ protected Database getSqlResult(ObjectStore.GetHelper<Database> ctx) throws MetaException {
+ throw new RuntimeException();
+ }
+
+ @Override
+ protected Database getJdoResult(ObjectStore.GetHelper<Database> ctx) throws MetaException,
+ NoSuchObjectException {
+ return null;
+ }
+ }.run(false);
+
+ json = metrics.dumpJson();
+ MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER,
+ MetricsConstant.DIRECTSQL_ERRORS, 1);
+ }
+
public static void dropAllStoreObjects(RawStore store) throws MetaException, InvalidObjectException, InvalidInputException {
try {
Deadline.registerIfNot(100000);