This is an automated email from the ASF dual-hosted git repository. tdsilva pushed a commit to branch 4.x-HBase-1.4 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x-HBase-1.4 by this push: new 7ae9737 PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE 7ae9737 is described below commit 7ae97373259153e71a656ae8fd9c0185b4237724 Author: Thomas D'Silva <tdsi...@apache.org> 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 e00fab3..8f1abf0 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 @@ -271,6 +271,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 9a656ee..d86a27a 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 @@ -72,8 +72,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) { @@ -88,7 +89,7 @@ public class ScanningResultIterator implements ResultIterator { } } - private void getScanMetrics() { + private void updateMetrics() { if (scanMetricsEnabled && !scanMetricsUpdated) { ScanMetrics scanMetrics = scanner.getScanMetrics();