This is an automated email from the ASF dual-hosted git repository.
vjasani pushed a commit to branch 5.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.3 by this push:
new 819c8d2502 PHOENIX-7729 Identify top N slowest parallel scans for
metrics reporting (Addendum) (#2409) (#2408)
819c8d2502 is described below
commit 819c8d2502d414d58e9fec1148b72bf7cc94ad4b
Author: sanjeet006py <[email protected]>
AuthorDate: Wed Apr 15 08:53:56 2026 +0530
PHOENIX-7729 Identify top N slowest parallel scans for metrics reporting
(Addendum) (#2409) (#2408)
---
.../phoenix/iterate/ScanningResultIterator.java | 4 +-
.../phoenix/monitoring/ScanMetricsHolder.java | 17 ++++---
.../phoenix/coprocessor/DataTableScanMetrics.java | 5 +-
.../phoenix/compat/hbase/CompatScanMetrics.java | 41 ++++++++++++++++
.../phoenix/compat/hbase/CompatScanMetrics.java | 41 ++++++++++++++++
.../phoenix/compat/hbase/CompatScanMetrics.java | 41 ++++++++++++++++
.../phoenix/compat/hbase/CompatScanMetrics.java | 54 ++++++++++++++++++++++
7 files changed, 190 insertions(+), 13 deletions(-)
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
index 28fead5048..850a5ecac6 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
@@ -29,6 +29,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.hadoop.util.ReflectionUtils;
+import org.apache.phoenix.compat.hbase.CompatScanMetrics;
import
org.apache.phoenix.compile.ExplainPlanAttributes.ExplainPlanAttributesBuilder;
import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.exception.SQLExceptionCode;
@@ -106,7 +107,8 @@ public class ScanningResultIterator implements
ResultIterator {
PhoenixConnection connection = context.getConnection();
int slowestScanMetricsCount = connection.getSlowestScanMetricsCount();
if (slowestScanMetricsCount > 0) {
-
scanMetricsHolder.setScanMetricsByRegion(scanMetrics.collectMetricsByRegion());
+ scanMetricsHolder
+
.setScanMetricsByRegion(CompatScanMetrics.collectRegionMetrics(scanMetrics));
context.getSlowestScanMetricsQueue().add(scanMetricsHolder);
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/ScanMetricsHolder.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/ScanMetricsHolder.java
index 0630e1456c..cc0fec7c2c 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/ScanMetricsHolder.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/ScanMetricsHolder.java
@@ -40,11 +40,12 @@ import static
org.apache.phoenix.monitoring.MetricType.SCAN_BYTES;
import java.io.IOException;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
-import org.apache.hadoop.hbase.client.metrics.ScanMetricsRegionInfo;
import org.apache.hadoop.hbase.util.JsonMapper;
+import org.apache.phoenix.compat.hbase.CompatScanMetrics;
import org.apache.phoenix.log.LogLevel;
import org.apache.hbase.thirdparty.com.google.gson.JsonArray;
@@ -53,7 +54,7 @@ import org.apache.hbase.thirdparty.com.google.gson.JsonObject;
public class ScanMetricsHolder {
private Map<String, Long> scanMetricMap;
- private Map<ScanMetricsRegionInfo, Map<String, Long>> scanMetricsByRegion;
+ private List<CompatScanMetrics.RegionMetricsInfo> scanMetricsByRegion;
private Object scan;
private final String tableName;
private final Map<MetricType, CombinableMetric> metricTypeToMetric;
@@ -81,7 +82,7 @@ public class ScanMetricsHolder {
this.scan = scan;
if (scan != null) {
scan.setScanMetricsEnabled(true);
- scan.setEnableScanMetricsByRegion(isScanMetricsByRegionEnabled);
+ CompatScanMetrics.enableScanMetricsByRegion(scan,
isScanMetricsByRegionEnabled);
}
metricTypeToMetric = new HashMap<>();
metricTypeToMetric.put(PAGED_ROWS_COUNTER,
@@ -180,7 +181,7 @@ public class ScanMetricsHolder {
}
public void
- setScanMetricsByRegion(Map<ScanMetricsRegionInfo, Map<String, Long>>
scanMetricsByRegion) {
+ setScanMetricsByRegion(List<CompatScanMetrics.RegionMetricsInfo>
scanMetricsByRegion) {
this.scanMetricsByRegion = scanMetricsByRegion;
}
@@ -219,13 +220,11 @@ public class ScanMetricsHolder {
if (scanMetricsByRegion != null && !scanMetricsByRegion.isEmpty()) {
tableJson.addProperty("table", tableName);
JsonArray regionMetrics = new JsonArray();
- for (Map.Entry<ScanMetricsRegionInfo, Map<String, Long>> entry :
scanMetricsByRegion
- .entrySet()) {
+ for (CompatScanMetrics.RegionMetricsInfo regionInfo :
scanMetricsByRegion) {
JsonObject regionJson = new JsonObject();
- ScanMetricsRegionInfo regionInfo = entry.getKey();
regionJson.addProperty("region", regionInfo.getEncodedRegionName());
- regionJson.addProperty("server",
regionInfo.getServerName().toString());
- for (Map.Entry<String, Long> scanMetricEntry :
entry.getValue().entrySet()) {
+ regionJson.addProperty("server", regionInfo.getServerName());
+ for (Map.Entry<String, Long> scanMetricEntry :
regionInfo.getMetrics().entrySet()) {
MetricType metricType =
MetricType.getMetricType(scanMetricEntry.getKey());
if (metricType == null) {
continue;
diff --git
a/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/DataTableScanMetrics.java
b/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/DataTableScanMetrics.java
index e72216586c..2c06a2fdae 100644
---
a/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/DataTableScanMetrics.java
+++
b/phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/DataTableScanMetrics.java
@@ -18,7 +18,6 @@
package org.apache.phoenix.coprocessor;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
-import org.apache.hadoop.hbase.monitoring.ThreadLocalServerSideScanMetrics;
import org.apache.phoenix.compat.hbase.CompatScanMetrics;
import org.apache.phoenix.compat.hbase.CompatThreadLocalServerSideScanMetrics;
@@ -29,8 +28,8 @@ import
org.apache.phoenix.compat.hbase.CompatThreadLocalServerSideScanMetrics;
* <li>Read repair operations</li>
* </ul>
* These metrics help identify latency variations that occur when both data
table and index table
- * are scanned together, and are used to populate {@link
ThreadLocalServerSideScanMetrics} for index
- * table RPC calls.
+ * are scanned together, and are used to populate
ThreadLocalServerSideScanMetrics for index table
+ * RPC calls.
*/
public class DataTableScanMetrics {
private final long fsReadTimeInMs;
diff --git
a/phoenix-hbase-compat-2.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
b/phoenix-hbase-compat-2.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
index fd7641f033..aed488020b 100644
---
a/phoenix-hbase-compat-2.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
+++
b/phoenix-hbase-compat-2.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
@@ -17,9 +17,39 @@
*/
package org.apache.phoenix.compat.hbase;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
public class CompatScanMetrics {
+
+ public static class RegionMetricsInfo {
+ private final String encodedRegionName;
+ private final String serverName;
+ private final Map<String, Long> metrics;
+
+ public RegionMetricsInfo(String encodedRegionName, String serverName,
+ Map<String, Long> metrics) {
+ this.encodedRegionName = encodedRegionName;
+ this.serverName = serverName;
+ this.metrics = metrics;
+ }
+
+ public String getEncodedRegionName() {
+ return encodedRegionName;
+ }
+
+ public String getServerName() {
+ return serverName;
+ }
+
+ public Map<String, Long> getMetrics() {
+ return metrics;
+ }
+ }
+
public static final String FS_READ_TIME_METRIC_NAME = "FS_READ_TIME";
public static final String BYTES_READ_FROM_FS_METRIC_NAME =
"BYTES_READ_FROM_FS";
public static final String BYTES_READ_FROM_MEMSTORE_METRIC_NAME =
"BYTES_READ_FROM_MEMSTORE";
@@ -56,4 +86,15 @@ public class CompatScanMetrics {
public static Long getBlockReadOpsCount(ScanMetrics scanMetrics) {
return 0L;
}
+
+ public static boolean supportsScanMetricsByRegion() {
+ return false;
+ }
+
+ public static void enableScanMetricsByRegion(Scan scan, boolean enabled) {
+ }
+
+ public static List<RegionMetricsInfo> collectRegionMetrics(ScanMetrics
scanMetrics) {
+ return Collections.emptyList();
+ }
}
diff --git
a/phoenix-hbase-compat-2.5.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
b/phoenix-hbase-compat-2.5.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
index fd7641f033..aed488020b 100644
---
a/phoenix-hbase-compat-2.5.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
+++
b/phoenix-hbase-compat-2.5.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
@@ -17,9 +17,39 @@
*/
package org.apache.phoenix.compat.hbase;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
public class CompatScanMetrics {
+
+ public static class RegionMetricsInfo {
+ private final String encodedRegionName;
+ private final String serverName;
+ private final Map<String, Long> metrics;
+
+ public RegionMetricsInfo(String encodedRegionName, String serverName,
+ Map<String, Long> metrics) {
+ this.encodedRegionName = encodedRegionName;
+ this.serverName = serverName;
+ this.metrics = metrics;
+ }
+
+ public String getEncodedRegionName() {
+ return encodedRegionName;
+ }
+
+ public String getServerName() {
+ return serverName;
+ }
+
+ public Map<String, Long> getMetrics() {
+ return metrics;
+ }
+ }
+
public static final String FS_READ_TIME_METRIC_NAME = "FS_READ_TIME";
public static final String BYTES_READ_FROM_FS_METRIC_NAME =
"BYTES_READ_FROM_FS";
public static final String BYTES_READ_FROM_MEMSTORE_METRIC_NAME =
"BYTES_READ_FROM_MEMSTORE";
@@ -56,4 +86,15 @@ public class CompatScanMetrics {
public static Long getBlockReadOpsCount(ScanMetrics scanMetrics) {
return 0L;
}
+
+ public static boolean supportsScanMetricsByRegion() {
+ return false;
+ }
+
+ public static void enableScanMetricsByRegion(Scan scan, boolean enabled) {
+ }
+
+ public static List<RegionMetricsInfo> collectRegionMetrics(ScanMetrics
scanMetrics) {
+ return Collections.emptyList();
+ }
}
diff --git
a/phoenix-hbase-compat-2.6.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
b/phoenix-hbase-compat-2.6.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
index fd7641f033..aed488020b 100644
---
a/phoenix-hbase-compat-2.6.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
+++
b/phoenix-hbase-compat-2.6.0/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
@@ -17,9 +17,39 @@
*/
package org.apache.phoenix.compat.hbase;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
public class CompatScanMetrics {
+
+ public static class RegionMetricsInfo {
+ private final String encodedRegionName;
+ private final String serverName;
+ private final Map<String, Long> metrics;
+
+ public RegionMetricsInfo(String encodedRegionName, String serverName,
+ Map<String, Long> metrics) {
+ this.encodedRegionName = encodedRegionName;
+ this.serverName = serverName;
+ this.metrics = metrics;
+ }
+
+ public String getEncodedRegionName() {
+ return encodedRegionName;
+ }
+
+ public String getServerName() {
+ return serverName;
+ }
+
+ public Map<String, Long> getMetrics() {
+ return metrics;
+ }
+ }
+
public static final String FS_READ_TIME_METRIC_NAME = "FS_READ_TIME";
public static final String BYTES_READ_FROM_FS_METRIC_NAME =
"BYTES_READ_FROM_FS";
public static final String BYTES_READ_FROM_MEMSTORE_METRIC_NAME =
"BYTES_READ_FROM_MEMSTORE";
@@ -56,4 +86,15 @@ public class CompatScanMetrics {
public static Long getBlockReadOpsCount(ScanMetrics scanMetrics) {
return 0L;
}
+
+ public static boolean supportsScanMetricsByRegion() {
+ return false;
+ }
+
+ public static void enableScanMetricsByRegion(Scan scan, boolean enabled) {
+ }
+
+ public static List<RegionMetricsInfo> collectRegionMetrics(ScanMetrics
scanMetrics) {
+ return Collections.emptyList();
+ }
}
diff --git
a/phoenix-hbase-compat-2.6.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
b/phoenix-hbase-compat-2.6.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
index 9a8e2f8cd6..f26a9a60b0 100644
---
a/phoenix-hbase-compat-2.6.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
+++
b/phoenix-hbase-compat-2.6.4/src/main/java/org/apache/phoenix/compat/hbase/CompatScanMetrics.java
@@ -17,11 +17,43 @@
*/
package org.apache.phoenix.compat.hbase;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
+import org.apache.hadoop.hbase.client.metrics.ScanMetricsRegionInfo;
import org.apache.hadoop.hbase.client.metrics.ServerSideScanMetrics;
public class CompatScanMetrics {
+
+ public static class RegionMetricsInfo {
+ private final String encodedRegionName;
+ private final String serverName;
+ private final Map<String, Long> metrics;
+
+ public RegionMetricsInfo(String encodedRegionName, String serverName,
+ Map<String, Long> metrics) {
+ this.encodedRegionName = encodedRegionName;
+ this.serverName = serverName;
+ this.metrics = metrics;
+ }
+
+ public String getEncodedRegionName() {
+ return encodedRegionName;
+ }
+
+ public String getServerName() {
+ return serverName;
+ }
+
+ public Map<String, Long> getMetrics() {
+ return metrics;
+ }
+ }
+
public static final String FS_READ_TIME_METRIC_NAME =
ServerSideScanMetrics.FS_READ_TIME_METRIC_NAME;
public static final String BYTES_READ_FROM_FS_METRIC_NAME =
@@ -70,4 +102,26 @@ public class CompatScanMetrics {
AtomicLong counter = scanMetrics.getCounter(metricName);
return counter != null ? counter.get() : 0L;
}
+
+ public static boolean supportsScanMetricsByRegion() {
+ return true;
+ }
+
+ public static void enableScanMetricsByRegion(Scan scan, boolean enabled) {
+ scan.setEnableScanMetricsByRegion(enabled);
+ }
+
+ public static List<RegionMetricsInfo> collectRegionMetrics(ScanMetrics
scanMetrics) {
+ Map<ScanMetricsRegionInfo, Map<String, Long>> byRegion =
scanMetrics.collectMetricsByRegion();
+ if (byRegion == null || byRegion.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<RegionMetricsInfo> result = new ArrayList<>();
+ for (Map.Entry<ScanMetricsRegionInfo, Map<String, Long>> entry :
byRegion.entrySet()) {
+ ScanMetricsRegionInfo regionInfo = entry.getKey();
+ result.add(new RegionMetricsInfo(regionInfo.getEncodedRegionName(),
+ regionInfo.getServerName().toString(), entry.getValue()));
+ }
+ return result;
+ }
}