This is an automated email from the ASF dual-hosted git repository.

karanmehta93 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 eb5b82b  PHOENIX-5101 ScanningResultIterator getScanMetrics throws NPE
eb5b82b is described below

commit eb5b82b0c61255a9e4f30248d7e06e9612df1dd2
Author: Karan Mehta <karanmeht...@gmail.com>
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 changeMetric(CombinableMetric metric, Long value) {
         if(value != null) {
             metric.change(value);
         }
     }
 
+    private void changeMetric(GlobalClientMetrics metric, Long value) {
+        if(value != null) {
+            metric.update(value);
+        }
+    }
+
     private void getScanMetrics() {
 
-        if (!scanMetricsUpdated && scanMetricsEnabled) {
-            ScanMetrics scanMetrics = scan.getScanMetrics();
-            if (scanMetrics == null) {
-                return;
-            }
+        if (scanMetricsEnabled && !scanMetricsUpdated) {
+            ScanMetrics scanMetrics = scanner.getScanMetrics();
             Map<String, Long> scanMetricsMap = scanMetrics.getMetricsMap();
-            if(scanMetricsMap == null) {
-                return;
-            }
             scanMetricsHolder.setScanMetricMap(scanMetricsMap);
+
             changeMetric(scanMetricsHolder.getCountOfRPCcalls(),
                     scanMetricsMap.get(RPC_CALLS_METRIC_NAME));
             changeMetric(scanMetricsHolder.getCountOfRemoteRPCcalls(),
@@ -122,19 +118,30 @@ public class ScanningResultIterator implements 
ResultIterator {
             changeMetric(scanMetricsHolder.getCountOfRowsFiltered(),
                     
scanMetricsMap.get(COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME));
 
-            
GLOBAL_SCAN_BYTES.update(scanMetricsMap.get(GLOBAL_BYTES_IN_RESULTS_METRIC_NAME));
-
-            
GLOBAL_HBASE_COUNT_RPC_CALLS.update(scanMetricsMap.get(RPC_CALLS_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_REMOTE_RPC_CALLS.update(scanMetricsMap.get(REMOTE_RPC_CALLS_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_MILLS_BETWEEN_NEXTS.update(scanMetricsMap.get(MILLIS_BETWEEN_NEXTS_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_NOT_SERVING_REGION_EXCEPTION.update(scanMetricsMap.get(NOT_SERVING_REGION_EXCEPTION_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_BYTES_REGION_SERVER_RESULTS.update(scanMetricsMap.get(BYTES_IN_RESULTS_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_BYTES_IN_REMOTE_RESULTS.update(scanMetricsMap.get(BYTES_IN_REMOTE_RESULTS_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_SCANNED_REGIONS.update(scanMetricsMap.get(REGIONS_SCANNED_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_RPC_RETRIES.update(scanMetricsMap.get(RPC_RETRIES_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_REMOTE_RPC_RETRIES.update(scanMetricsMap.get(REMOTE_RPC_RETRIES_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_ROWS_SCANNED.update(scanMetricsMap.get(COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME));
-            
GLOBAL_HBASE_COUNT_ROWS_FILTERED.update(scanMetricsMap.get(COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME));
+            changeMetric(GLOBAL_SCAN_BYTES,
+                    scanMetricsMap.get(BYTES_IN_RESULTS_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_RPC_CALLS,
+                    scanMetricsMap.get(RPC_CALLS_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_REMOTE_RPC_CALLS
+                    , scanMetricsMap.get(REMOTE_RPC_CALLS_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_MILLS_BETWEEN_NEXTS,
+                    scanMetricsMap.get(MILLIS_BETWEEN_NEXTS_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_NOT_SERVING_REGION_EXCEPTION,
+                    
scanMetricsMap.get(NOT_SERVING_REGION_EXCEPTION_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_BYTES_REGION_SERVER_RESULTS,
+                    scanMetricsMap.get(BYTES_IN_RESULTS_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_BYTES_IN_REMOTE_RESULTS,
+                    scanMetricsMap.get(BYTES_IN_REMOTE_RESULTS_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_SCANNED_REGIONS,
+                    scanMetricsMap.get(REGIONS_SCANNED_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_RPC_RETRIES,
+                    scanMetricsMap.get(RPC_RETRIES_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_REMOTE_RPC_RETRIES,
+                    scanMetricsMap.get(REMOTE_RPC_RETRIES_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_ROWS_SCANNED,
+                    scanMetricsMap.get(COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME));
+            changeMetric(GLOBAL_HBASE_COUNT_ROWS_FILTERED,
+                    
scanMetricsMap.get(COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME));
 
             scanMetricsUpdated = true;
         }

Reply via email to