phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sama...@apache.org
Subject phoenix git commit: PHOENIX-2485 Expose number of open phoenix connections in global client metrics
Date Thu, 14 Jan 2016 18:34:41 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 8495329ee -> 7bab1f397


PHOENIX-2485 Expose number of open phoenix connections in global client metrics


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7bab1f39
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7bab1f39
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7bab1f39

Branch: refs/heads/4.x-HBase-0.98
Commit: 7bab1f39756faf635a9cdc6cf26ee8ccc1a86dd6
Parents: 8495329
Author: Samarth <samarth.jain@salesforce.com>
Authored: Thu Jan 14 10:34:10 2016 -0800
Committer: Samarth <samarth.jain@salesforce.com>
Committed: Thu Jan 14 10:34:10 2016 -0800

----------------------------------------------------------------------
 .../org/apache/phoenix/monitoring/PhoenixMetricsIT.java   | 10 ++++++++++
 .../java/org/apache/phoenix/jdbc/PhoenixConnection.java   |  4 ++++
 .../java/org/apache/phoenix/monitoring/AtomicMetric.java  |  5 +++++
 .../org/apache/phoenix/monitoring/CombinableMetric.java   |  3 +++
 .../apache/phoenix/monitoring/CombinableMetricImpl.java   |  5 +++++
 .../apache/phoenix/monitoring/GlobalClientMetrics.java    | 10 +++++++++-
 .../org/apache/phoenix/monitoring/GlobalMetricImpl.java   |  6 ++++++
 .../main/java/org/apache/phoenix/monitoring/Metric.java   |  9 +++++++--
 .../java/org/apache/phoenix/monitoring/MetricType.java    |  3 ++-
 .../org/apache/phoenix/monitoring/NonAtomicMetric.java    |  5 +++++
 10 files changed, 56 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
index c1c3d4c..eed0e48 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
@@ -15,6 +15,7 @@ import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_MUTATION_
 import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_MUTATION_COMMIT_TIME;
 import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_MUTATION_SQL_COUNTER;
 import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_NUM_PARALLEL_SCANS;
+import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_OPEN_PHOENIX_CONNECTIONS;
 import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_QUERY_TIME;
 import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_QUERY_TIMEOUT_COUNTER;
 import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_REJECTED_TASK_COUNTER;
@@ -618,6 +619,15 @@ public class PhoenixMetricsIT extends BaseOwnClusterHBaseManagedTimeIT
{
         assertMetricsAreSame(readMetrics, autoCommitReadMetrics, readMetricsToSkip);
     }
     
+    @Test
+    public void testOpenConnectionsCounter() throws Exception {
+        long numOpenConnections = GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            assertEquals(numOpenConnections + 1, GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue());
+        }
+        assertEquals(numOpenConnections, GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue());
+    }
+    
     private void createTableAndInsertValues(boolean commit, int numRows, Connection conn,
String tableName)
             throws SQLException {
         String ddl = "CREATE TABLE " + tableName + " (K VARCHAR NOT NULL PRIMARY KEY, V VARCHAR)";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index e8b0131..3a247b2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.jdbc;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static java.util.Collections.emptyMap;
+import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_OPEN_PHOENIX_CONNECTIONS;
 
 import java.io.EOFException;
 import java.io.IOException;
@@ -70,6 +71,7 @@ import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.iterate.TableResultIterator;
 import org.apache.phoenix.iterate.TableResultIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixStatement.PhoenixStatementParser;
+import org.apache.phoenix.monitoring.GlobalClientMetrics;
 import org.apache.phoenix.parse.PFunction;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.ConnectionQueryServices.Feature;
@@ -286,6 +288,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated,
SQLClosea
         this.customTracingAnnotations = getImmutableCustomTracingAnnotations();
         this.scannerQueue = new LinkedBlockingQueue<>();
         this.tableResultIteratorFactory = new DefaultTableResultIteratorFactory();
+        GLOBAL_OPEN_PHOENIX_CONNECTIONS.increment();
     }
     
     private static void checkScn(Long scnParam) throws SQLException {
@@ -502,6 +505,7 @@ public class PhoenixConnection implements Connection, MetaDataMutated,
SQLClosea
             }
         } finally {
             isClosed = true;
+            GLOBAL_OPEN_PHOENIX_CONNECTIONS.decrement();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/AtomicMetric.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/AtomicMetric.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/AtomicMetric.java
index 796e8ba..c79d34b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/AtomicMetric.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/AtomicMetric.java
@@ -67,4 +67,9 @@ public class AtomicMetric implements Metric {
         value.set(0);
     }
 
+    @Override
+    public void decrement() {
+        value.decrementAndGet();        
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java
b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java
index 7ebb0c1..ededb41 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetric.java
@@ -72,6 +72,9 @@ public interface CombinableMetric extends Metric {
         public CombinableMetric combine(CombinableMetric metric) {
             return INSTANCE;
         }
+
+        @Override
+        public void decrement() {}
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java
index fa6f7d3..1972095 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/CombinableMetricImpl.java
@@ -74,4 +74,9 @@ public class CombinableMetricImpl implements CombinableMetric {
         return this;
     }
 
+    @Override
+    public void decrement() {
+        metric.decrement();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalClientMetrics.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalClientMetrics.java
b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalClientMetrics.java
index a8f3bb4..c3a7261 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalClientMetrics.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalClientMetrics.java
@@ -17,6 +17,7 @@
  */
 package org.apache.phoenix.monitoring;
 
+import static org.apache.phoenix.monitoring.MetricType.OPEN_PHOENIX_CONNECTIONS_COUNTER;
 import static org.apache.phoenix.monitoring.MetricType.QUERY_FAILED_COUNTER;
 import static org.apache.phoenix.monitoring.MetricType.MEMORY_CHUNK_BYTES;
 import static org.apache.phoenix.monitoring.MetricType.MEMORY_WAIT_TIME;
@@ -71,7 +72,8 @@ public enum GlobalClientMetrics {
     GLOBAL_REJECTED_TASK_COUNTER(TASK_REJECTED_COUNTER),
     GLOBAL_QUERY_TIMEOUT_COUNTER(QUERY_TIMEOUT_COUNTER),
     GLOBAL_FAILED_QUERY_COUNTER(QUERY_FAILED_COUNTER),
-    GLOBAL_SPOOL_FILE_COUNTER(SPOOL_FILE_COUNTER);
+    GLOBAL_SPOOL_FILE_COUNTER(SPOOL_FILE_COUNTER),
+    GLOBAL_OPEN_PHOENIX_CONNECTIONS(OPEN_PHOENIX_CONNECTIONS_COUNTER);
     
     private static final boolean isGlobalMetricsEnabled = QueryServicesOptions.withDefaults().isGlobalMetricsEnabled();
     private GlobalMetric metric;
@@ -101,6 +103,12 @@ public enum GlobalClientMetrics {
             metric.increment();
         }
     }
+    
+    public void decrement() {
+        if (isGlobalMetricsEnabled) {
+            metric.decrement();
+        }
+    }
 
     public static Collection<GlobalMetric> getMetrics() {
         List<GlobalMetric> metrics = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalMetricImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalMetricImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalMetricImpl.java
index 26a16e1..25c0dfb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalMetricImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/GlobalMetricImpl.java
@@ -71,4 +71,10 @@ public class GlobalMetricImpl implements GlobalMetric {
     public String getCurrentMetricState() {
         return metric.getCurrentMetricState() + ", Number of samples: " + numberOfSamples.get();
     }
+
+    @Override
+    public void decrement() {
+        metric.decrement();
+        numberOfSamples.incrementAndGet();
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/Metric.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/Metric.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/Metric.java
index 1ad1c7a..53c91e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/Metric.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/Metric.java
@@ -45,10 +45,15 @@ public interface Metric {
     public void change(long delta);
 
     /**
-     * Change the value of metric by 1
+     * Increase the value of metric by 1
      */
     public void increment();
-
+    
+    /**
+     * Decrease the value of metric by 1
+     */
+    public void decrement();
+    
     /**
      * @return String that represents the current state of the metric. Typically used for
logging or reporting purposes.
      */

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricType.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricType.java
index a0c2a4a..6cfe977 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricType.java
@@ -40,7 +40,8 @@ public enum MetricType {
     SPOOL_FILE_COUNTER("Number of spool files created"),
     CACHE_REFRESH_SPLITS_COUNTER("Number of times cache was refreshed because of splits"),
     WALL_CLOCK_TIME_MS("Wall clock time elapsed for the overall query execution"),
-    RESULT_SET_TIME_MS("Wall clock time elapsed for reading all records using resultSet.next()");
+    RESULT_SET_TIME_MS("Wall clock time elapsed for reading all records using resultSet.next()"),
+    OPEN_PHOENIX_CONNECTIONS_COUNTER("Number of open phoenix connections");
     
     private final String description;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bab1f39/phoenix-core/src/main/java/org/apache/phoenix/monitoring/NonAtomicMetric.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/NonAtomicMetric.java
b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/NonAtomicMetric.java
index 2d92116..5205228 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/NonAtomicMetric.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/NonAtomicMetric.java
@@ -68,4 +68,9 @@ class NonAtomicMetric implements Metric {
         value = 0;
     }
 
+    @Override
+    public void decrement() {
+        value--;
+    }
+
 }


Mime
View raw message