ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [1/2] ambari git commit: AMBARI-9304 AMS: Optimize LikeCondition (dsen)
Date Fri, 23 Jan 2015 20:43:47 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 8d785ce3d -> 9bb3bc007


AMBARI-9304 AMS: Optimize LikeCondition (dsen)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9bb3bc00
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9bb3bc00
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9bb3bc00

Branch: refs/heads/trunk
Commit: 9bb3bc007c927bca9d85af645eebd027f2c633c8
Parents: f7efd2b
Author: Dmytro Sen <dsen@apache.org>
Authored: Fri Jan 23 22:12:55 2015 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Fri Jan 23 22:43:10 2015 +0200

----------------------------------------------------------------------
 .../timeline/HBaseTimelineMetricStore.java      |   6 +-
 .../metrics/timeline/PhoenixTransactSQL.java    | 101 +++++++------------
 .../timeline/TestPhoenixTransactSQL.java        |  35 ++++---
 3 files changed, 58 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9bb3bc00/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
index 83fc0bd..0fa0834 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
@@ -32,7 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.Condition;
-import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.LikeCondition;
+import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.DefaultCondition;
 
 public class HBaseTimelineMetricStore extends AbstractService
     implements TimelineMetricStore {
@@ -107,7 +107,7 @@ public class HBaseTimelineMetricStore extends AbstractService
       Long startTime, Long endTime, Precision precision, Integer limit,
       boolean groupedByHosts) throws SQLException, IOException {
 
-    Condition condition = new LikeCondition(metricNames, hostname, applicationId,
+    Condition condition = new DefaultCondition(metricNames, hostname, applicationId,
       instanceId, startTime, endTime, precision, limit, groupedByHosts);
 
     if (hostname == null) {
@@ -124,7 +124,7 @@ public class HBaseTimelineMetricStore extends AbstractService
       throws SQLException, IOException {
 
     TimelineMetrics metrics = hBaseAccessor.getMetricRecords(
-      new LikeCondition(Collections.singletonList(metricName), hostname,
+      new DefaultCondition(Collections.singletonList(metricName), hostname,
         applicationId, instanceId, startTime, endTime, precision, limit, true)
     );
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9bb3bc00/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
index a6ad040..e30f710 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
@@ -561,7 +561,7 @@ public class PhoenixTransactSQL {
     void setPrecision(Precision precision);
     String getAppId();
     String getInstanceId();
-    String getConditionClause();
+    StringBuilder getConditionClause();
     String getOrderByClause();
     String getStatement();
     Long getStartTime();
@@ -614,34 +614,47 @@ public class PhoenixTransactSQL {
       return metricNames == null || metricNames.isEmpty() ? null : metricNames;
     }
 
-    String getMetricsClause() {
-      StringBuilder sb = new StringBuilder("(");
-      if (metricNames != null) {
+    public StringBuilder getConditionClause() {
+      StringBuilder sb = new StringBuilder();
+      boolean appendConjunction = false;
+      StringBuilder metricsLike = new StringBuilder();
+      StringBuilder metricsIn = new StringBuilder();
+
+      if (getMetricNames() != null) {
         for (String name : getMetricNames()) {
-          if (sb.length() != 1) {
-            sb.append(", ");
+          if (name.contains("%")) {
+            if (metricsLike.length() > 1) {
+              metricsLike.append(" OR ");
+            }
+            metricsLike.append("METRIC_NAME LIKE ?");
+          } else {
+            if (metricsIn.length() > 0) {
+              metricsIn.append(", ");
+            }
+            metricsIn.append("?");
           }
-          sb.append("?");
         }
-        sb.append(")");
-        return sb.toString();
-      } else {
-        return null;
-      }
-    }
 
-    public String getConditionClause() {
-      StringBuilder sb = new StringBuilder();
-      boolean appendConjunction = false;
+        if (metricsIn.length()>0) {
+          sb.append("(METRIC_NAME IN (");
+          sb.append(metricsIn);
+          sb.append(")");
+          appendConjunction = true;
+        }
 
-      if (getMetricNames() != null) {
-        if (appendConjunction) {
-          sb.append(" AND");
+        if (metricsLike.length() > 0) {
+          if (appendConjunction) {
+            sb.append(" OR ");
+          } else {
+            sb.append("(");
+          }
+          sb.append(metricsLike);
+          appendConjunction = true;
         }
 
-        sb.append("METRIC_NAME IN ");
-        sb.append(getMetricsClause());
-        appendConjunction = true;
+        if (appendConjunction) {
+          sb.append(")");
+        }
       }
 
       appendConjunction = append(sb, appendConjunction, getHostname(), " HOSTNAME = ?");
@@ -650,7 +663,7 @@ public class PhoenixTransactSQL {
       appendConjunction = append(sb, appendConjunction, getStartTime(), " SERVER_TIME >=
?");
       append(sb, appendConjunction, getEndTime(), " SERVER_TIME < ?");
 
-      return sb.toString();
+      return sb;
     }
 
     protected static boolean append(StringBuilder sb,
@@ -791,44 +804,6 @@ public class PhoenixTransactSQL {
     }
   }
 
-  static class LikeCondition extends DefaultCondition {
-
-    LikeCondition(List<String> metricNames, String hostname,
-                  String appId, String instanceId, Long startTime,
-                  Long endTime, Precision precision, Integer limit,
-                  boolean grouped) {
-      super(metricNames, hostname, appId, instanceId, startTime, endTime,
-        precision, limit, grouped);
-    }
-
-    @Override
-    public String getConditionClause() {
-      StringBuilder sb = new StringBuilder();
-      boolean appendConjunction = false;
-
-      if (getMetricNames() != null) {
-        sb.append("(");
-        for (String name : getMetricNames()) {
-          if (sb.length() > 1) {
-            sb.append(" OR ");
-          }
-          sb.append("METRIC_NAME LIKE ?");
-        }
-
-        sb.append(")");
-        appendConjunction = true;
-      }
-
-      appendConjunction = append(sb, appendConjunction, getHostname(), " HOSTNAME = ?");
-      appendConjunction = append(sb, appendConjunction, getAppId(), " APP_ID = ?");
-      appendConjunction = append(sb, appendConjunction, getInstanceId(), " INSTANCE_ID =
?");
-      appendConjunction = append(sb, appendConjunction, getStartTime(), " SERVER_TIME >=
?");
-      append(sb, appendConjunction, getEndTime(), " SERVER_TIME < ?");
-
-      return sb.toString();
-    }
-  }
-
   static class SplitByMetricNamesCondition implements Condition {
     private final Condition adaptee;
     private String currentMetric;
@@ -888,7 +863,7 @@ public class PhoenixTransactSQL {
     }
 
     @Override
-    public String getConditionClause() {
+    public StringBuilder getConditionClause() {
       StringBuilder sb = new StringBuilder();
       boolean appendConjunction = false;
 
@@ -914,7 +889,7 @@ public class PhoenixTransactSQL {
       DefaultCondition.append(sb, appendConjunction, getEndTime(),
         " SERVER_TIME < ?");
 
-      return sb.toString();
+      return sb;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/9bb3bc00/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
index af472c7..038f3de 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
@@ -29,7 +29,6 @@ import java.util.Collections;
 
 import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.Condition;
 import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.DefaultCondition;
-import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.LikeCondition;
 import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixTransactSQL.SplitByMetricNamesCondition;
 
 import static org.easymock.EasyMock.createNiceMock;
@@ -46,8 +45,8 @@ public class TestPhoenixTransactSQL {
       Arrays.asList("cpu_user", "mem_free"), "h1", "a1", "i1",
         1407959718L, 1407959918L, null, null, false);
 
-    String preparedClause = condition.getConditionClause();
-    String expectedClause = "METRIC_NAME IN (?, ?) AND HOSTNAME = ? AND " +
+    String preparedClause = condition.getConditionClause().toString();
+    String expectedClause = "(METRIC_NAME IN (?, ?)) AND HOSTNAME = ? AND " +
       "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 
     Assert.assertNotNull(preparedClause);
@@ -63,7 +62,7 @@ public class TestPhoenixTransactSQL {
     SplitByMetricNamesCondition condition = new SplitByMetricNamesCondition(c);
     condition.setCurrentMetric(c.getMetricNames().get(0));
 
-    String preparedClause = condition.getConditionClause();
+    String preparedClause = condition.getConditionClause().toString();
     String expectedClause = "METRIC_NAME = ? AND HOSTNAME = ? AND " +
       "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 
@@ -73,23 +72,23 @@ public class TestPhoenixTransactSQL {
 
   @Test
   public void testLikeConditionClause() throws Exception {
-    Condition condition = new LikeCondition(
-        Arrays.asList("cpu_user", "mem_free"), "h1", "a1", "i1",
+    Condition condition = new DefaultCondition(
+        Arrays.asList("cpu_user", "some=%.metric"), "h1", "a1", "i1",
         1407959718L, 1407959918L, null, null, false);
 
-    String preparedClause = condition.getConditionClause();
-    String expectedClause = "(METRIC_NAME LIKE ? OR METRIC_NAME LIKE ?) AND HOSTNAME = ?
AND " +
+    String preparedClause = condition.getConditionClause().toString();
+    String expectedClause = "(METRIC_NAME IN (?) OR METRIC_NAME LIKE ?) AND HOSTNAME = ?
AND " +
         "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 
     Assert.assertNotNull(preparedClause);
     Assert.assertEquals(expectedClause, preparedClause);
 
 
-    condition = new LikeCondition(
+    condition = new DefaultCondition(
         Collections.<String>emptyList(), "h1", "a1", "i1",
         1407959718L, 1407959918L, null, null, false);
 
-    preparedClause = condition.getConditionClause();
+    preparedClause = condition.getConditionClause().toString();
     expectedClause = " HOSTNAME = ? AND " +
         "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 
@@ -97,11 +96,11 @@ public class TestPhoenixTransactSQL {
     Assert.assertEquals(expectedClause, preparedClause);
 
 
-    condition = new LikeCondition(
+    condition = new DefaultCondition(
         null, "h1", "a1", "i1",
         1407959718L, 1407959918L, null, null, false);
 
-    preparedClause = condition.getConditionClause();
+    preparedClause = condition.getConditionClause().toString();
     expectedClause = " HOSTNAME = ? AND " +
         "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 
@@ -109,11 +108,11 @@ public class TestPhoenixTransactSQL {
     Assert.assertEquals(expectedClause, preparedClause);
 
 
-    condition = new LikeCondition(
-        Arrays.asList("cpu_user"), "h1", "a1", "i1",
+    condition = new DefaultCondition(
+        Arrays.asList("some=%.metric"), "h1", "a1", "i1",
         1407959718L, 1407959918L, null, null, false);
 
-    preparedClause = condition.getConditionClause();
+    preparedClause = condition.getConditionClause().toString();
     expectedClause = "(METRIC_NAME LIKE ?) AND HOSTNAME = ? AND " +
         "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 
@@ -121,11 +120,11 @@ public class TestPhoenixTransactSQL {
     Assert.assertEquals(expectedClause, preparedClause);
 
 
-    condition = new LikeCondition(
-        Arrays.asList("cpu_user", "mem_free", "cpu_aidle"), "h1", "a1", "i1",
+    condition = new DefaultCondition(
+        Arrays.asList("some=%.metric1", "some=%.metric2", "some=%.metric3"), "h1", "a1",
"i1",
         1407959718L, 1407959918L, null, null, false);
 
-    preparedClause = condition.getConditionClause();
+    preparedClause = condition.getConditionClause().toString();
     expectedClause = "(METRIC_NAME LIKE ? OR METRIC_NAME LIKE ? OR METRIC_NAME LIKE ?) AND
HOSTNAME = ? AND " +
         "APP_ID = ? AND INSTANCE_ID = ? AND SERVER_TIME >= ? AND SERVER_TIME < ?";
 


Mime
View raw message