[phoenix] branch 4.x-HBase-1.2 updated: PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE

2019-05-03 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.x-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.2 by this push:
 new 06f7ccf  PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE
06f7ccf is described below

commit 06f7ccfc06704e387635cc40fd519dca7b57fde6
Author: Thomas D'Silva 
AuthorDate: Thu May 2 16:33:20 2019 -0700

PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE
---
 .../org/apache/phoenix/monitoring/PhoenixMetricsIT.java  | 16 
 .../apache/phoenix/iterate/ScanningResultIterator.java   |  5 +++--
 2 files changed, 19 insertions(+), 2 deletions(-)

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 9dddece..74e69f6 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
@@ -212,6 +212,22 @@ public class PhoenixMetricsIT extends BasePhoenixMetricsIT 
{
 conn.createStatement().execute(ddl);
 }
 
+// See PHOENIX-5101
+@Test
+public void testMetricsLargeQuery() throws Exception {
+String tableName = "MY_TABLE";
+String ddl = "CREATE TABLE " + tableName + " (K VARCHAR NOT NULL 
PRIMARY KEY, V VARCHAR)";
+Connection conn = DriverManager.getConnection(getUrl());
+conn.createStatement().execute(ddl);
+long numRows = 18750;
+insertRowsInTable(tableName, numRows);
+String query = "SELECT * FROM " + tableName;
+Statement stmt = conn.createStatement();
+ResultSet rs = stmt.executeQuery(query);
+while (rs.next()) {}
+rs.close();
+}
+
 @Test
 public void testReadMetricsForSelect() throws Exception {
 String tableName = generateUniqueName();
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
index 8a1fe5a..f4bbbf1 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
@@ -77,8 +77,9 @@ public class ScanningResultIterator implements ResultIterator 
{
 
 @Override
 public void close() throws SQLException {
-getScanMetrics();
+// close the scanner so that metrics are available
 scanner.close();
+updateMetrics();
 }
 
 private void changeMetric(CombinableMetric metric, Long value) {
@@ -93,7 +94,7 @@ public class ScanningResultIterator implements ResultIterator 
{
 }
 }
 
-private void getScanMetrics() {
+private void updateMetrics() {
 
 if (scanMetricsEnabled && !scanMetricsUpdated) {
 ScanMetrics scanMetrics = scan.getScanMetrics();



[phoenix] branch 4.x-HBase-1.2 updated: PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE (Addendum)

2019-04-03 Thread karanmehta93
This is an automated email from the ASF dual-hosted git repository.

karanmehta93 pushed a commit to branch 4.x-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.2 by this push:
 new d442c51  PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE 
(Addendum)
d442c51 is described below

commit d442c5124dab7d6c3f9c004d7a7a78c7cb258ddf
Author: Karan Mehta 
AuthorDate: Wed Apr 3 15:12:19 2019 -0700

PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE (Addendum)
---
 .../phoenix/iterate/ScanningResultIterator.java| 37 --
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
index 9a656ee..8a1fe5a 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
@@ -17,17 +17,8 @@
  */
 package org.apache.phoenix.iterate;
 
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.BYTES_IN_REMOTE_RESULTS_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.BYTES_IN_RESULTS_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.MILLIS_BETWEEN_NEXTS_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.NOT_SERVING_REGION_EXCEPTION_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.REGIONS_SCANNED_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.REMOTE_RPC_CALLS_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.REMOTE_RPC_RETRIES_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.RPC_CALLS_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.RPC_RETRIES_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics.COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME;
-import static 
org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics.COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics.COUNT_OF_ROWS_FILTERED_KEY;
+import static 
org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics.COUNT_OF_ROWS_SCANNED_KEY;
 import static 
org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HBASE_COUNT_BYTES_IN_REMOTE_RESULTS;
 import static 
org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HBASE_COUNT_BYTES_REGION_SERVER_RESULTS;
 import static 
org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HBASE_COUNT_MILLS_BETWEEN_NEXTS;
@@ -59,12 +50,26 @@ import org.apache.phoenix.util.ServerUtil;
 
 public class ScanningResultIterator implements ResultIterator {
 private final ResultScanner scanner;
+private final Scan scan;
 private final ScanMetricsHolder scanMetricsHolder;
 boolean scanMetricsUpdated;
 boolean scanMetricsEnabled;
 
+// These metric names are how HBase refers them
+// Since HBase stores these strings as static final, we are using the same 
here
+static final String RPC_CALLS_METRIC_NAME = "RPC_CALLS";
+static final String REMOTE_RPC_CALLS_METRIC_NAME = "REMOTE_RPC_CALLS";
+static final String MILLIS_BETWEEN_NEXTS_METRIC_NAME = 
"MILLIS_BETWEEN_NEXTS";
+static final String NOT_SERVING_REGION_EXCEPTION_METRIC_NAME = 
"NOT_SERVING_REGION_EXCEPTION";
+static final String BYTES_IN_RESULTS_METRIC_NAME = "BYTES_IN_RESULTS";
+static final String BYTES_IN_REMOTE_RESULTS_METRIC_NAME = 
"BYTES_IN_REMOTE_RESULTS";
+static final String REGIONS_SCANNED_METRIC_NAME = "REGIONS_SCANNED";
+static final String RPC_RETRIES_METRIC_NAME = "RPC_RETRIES";
+static final String REMOTE_RPC_RETRIES_METRIC_NAME = "REMOTE_RPC_RETRIES";
+
 public ScanningResultIterator(ResultScanner scanner, Scan scan, 
ScanMetricsHolder scanMetricsHolder) {
 this.scanner = scanner;
+this.scan = scan;
 this.scanMetricsHolder = scanMetricsHolder;
 scanMetricsUpdated = false;
 scanMetricsEnabled = scan.isScanMetricsEnabled();
@@ -91,7 +96,7 @@ public class ScanningResultIterator implements ResultIterator 
{
 private void getScanMetrics() {
 
 if (scanMetricsEnabled && !scanMetricsUpdated) {
-ScanMetrics scanMetrics = scanner.getScanMetrics();
+ScanMetrics scanMetrics = scan.getScanMetrics();
 Map scanMetricsMap = scanMetrics.getMetricsMap();
 scanMetricsHolder.setScanMetricMap(scanMetricsMap);
 
@@ -114,9 +119,9 @@ public class ScanningResultIterator implements 
ResultIterator {
 changeMetric(scanMetricsHolder.getCountOfRemoteRPCRetries(),
 scanMetricsMap.get(REMOTE_RPC_RETRIES_METRIC_NAME));
 

[phoenix] branch 4.x-HBase-1.2 updated: PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE

2019-04-03 Thread karanmehta93
This is an automated email from the ASF dual-hosted git repository.

karanmehta93 pushed a commit to branch 4.x-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.2 by this push:
 new 9e74148  PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE
9e74148 is described below

commit 9e741482ce12f5e77f82ebbbc3337ee9029157f9
Author: Karan Mehta 
AuthorDate: Wed Apr 3 11:34:26 2019 -0700

PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE
---
 .../phoenix/iterate/ScanningResultIterator.java| 85 --
 1 file changed, 46 insertions(+), 39 deletions(-)

diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
index 893eaa2..9a656ee 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
@@ -17,6 +17,17 @@
  */
 package org.apache.phoenix.iterate;
 
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.BYTES_IN_REMOTE_RESULTS_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.BYTES_IN_RESULTS_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.MILLIS_BETWEEN_NEXTS_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.NOT_SERVING_REGION_EXCEPTION_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.REGIONS_SCANNED_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.REMOTE_RPC_CALLS_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.REMOTE_RPC_RETRIES_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.RPC_CALLS_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ScanMetrics.RPC_RETRIES_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics.COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME;
+import static 
org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics.COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME;
 import static 
org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HBASE_COUNT_BYTES_IN_REMOTE_RESULTS;
 import static 
org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HBASE_COUNT_BYTES_REGION_SERVER_RESULTS;
 import static 
org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_HBASE_COUNT_MILLS_BETWEEN_NEXTS;
@@ -40,6 +51,7 @@ import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
 import org.apache.phoenix.monitoring.CombinableMetric;
+import org.apache.phoenix.monitoring.GlobalClientMetrics;
 import org.apache.phoenix.monitoring.ScanMetricsHolder;
 import org.apache.phoenix.schema.tuple.ResultTuple;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -47,29 +59,12 @@ import org.apache.phoenix.util.ServerUtil;
 
 public class ScanningResultIterator implements ResultIterator {
 private final ResultScanner scanner;
-private final Scan scan;
 private final ScanMetricsHolder scanMetricsHolder;
 boolean scanMetricsUpdated;
 boolean scanMetricsEnabled;
 
-// These metric names are how HBase refers them
-// Since HBase stores these strings as static final, we are using the same 
here
-static final String RPC_CALLS_METRIC_NAME = "RPC_CALLS";
-static final String REMOTE_RPC_CALLS_METRIC_NAME = "REMOTE_RPC_CALLS";
-static final String MILLIS_BETWEEN_NEXTS_METRIC_NAME = 
"MILLIS_BETWEEN_NEXTS";
-static final String NOT_SERVING_REGION_EXCEPTION_METRIC_NAME = 
"NOT_SERVING_REGION_EXCEPTION";
-static final String BYTES_IN_RESULTS_METRIC_NAME = "BYTES_IN_RESULTS";
-static final String BYTES_IN_REMOTE_RESULTS_METRIC_NAME = 
"BYTES_IN_REMOTE_RESULTS";
-static final String REGIONS_SCANNED_METRIC_NAME = "REGIONS_SCANNED";
-static final String RPC_RETRIES_METRIC_NAME = "RPC_RETRIES";
-static final String REMOTE_RPC_RETRIES_METRIC_NAME = "REMOTE_RPC_RETRIES";
-static final String COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME = "ROWS_SCANNED";
-static final String COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME = 
"ROWS_FILTERED";
-static final String GLOBAL_BYTES_IN_RESULTS_METRIC_NAME = 
"BYTES_IN_RESULTS";
-
 public ScanningResultIterator(ResultScanner scanner, Scan scan, 
ScanMetricsHolder scanMetricsHolder) {
 this.scanner = scanner;
-this.scan = scan;
 this.scanMetricsHolder = scanMetricsHolder;
 scanMetricsUpdated = false;
 scanMetricsEnabled = scan.isScanMetricsEnabled();
@@ -81,24 +76,25 @@ public class ScanningResultIterator implements 
ResultIterator {
 scanner.close();
 }
 
-private static void changeMetric(CombinableMetric metric, Long value) {
+private void