Copilot commented on code in PR #2672:
URL: https://github.com/apache/phoenix/pull/2672#discussion_r4543867600


##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/UncoveredGlobalIndexRegionScanner.java:
##########
@@ -332,6 +331,29 @@ protected void scanDataTableRows(long startTime) throws 
IOException {
     }
   }
 
+  // Returns the end keys of the data table regions that hold the given row 
keys, in key order. The
+  // locations come from the location cache of the connection. A cache miss 
reads only the meta row
+  // of that region, not the meta rows of all the regions of the table. A 
stale location changes
+  // only how the row keys go into tasks. Each task scans through the client, 
so its scan is correct
+  // across region boundaries
+  private byte[][] getRegionEndKeys(TreeSet<byte[]> dataRowKeys) throws 
IOException {
+    List<byte[]> endKeys = new ArrayList<>();
+    try (RegionLocator locator =
+      hTableFactory.getConnection().getRegionLocator(dataHTable.getName())) {
+      byte[] rowKey = dataRowKeys.first();

Review Comment:
   `dataRowKeys.first()` will throw `NoSuchElementException` when `dataRowKeys` 
is empty. Since `dataRowKeys` is built from `indexToDataRowKeyMap.values()` 
earlier in the method, it can be empty for a page with no mapped rows. Add a 
fast-path guard (e.g., return an empty `byte[][]` or skip task creation) when 
`dataRowKeys.isEmpty()` to avoid crashing the scan.



##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/UncoveredGlobalIndexRegionScanner.java:
##########
@@ -332,6 +331,29 @@ protected void scanDataTableRows(long startTime) throws 
IOException {
     }
   }
 
+  // Returns the end keys of the data table regions that hold the given row 
keys, in key order. The
+  // locations come from the location cache of the connection. A cache miss 
reads only the meta row
+  // of that region, not the meta rows of all the regions of the table. A 
stale location changes
+  // only how the row keys go into tasks. Each task scans through the client, 
so its scan is correct
+  // across region boundaries
+  private byte[][] getRegionEndKeys(TreeSet<byte[]> dataRowKeys) throws 
IOException {

Review Comment:
   The new per-page region-boundary discovery logic lacks direct unit coverage 
in this PR. Consider adding tests that mock `RegionLocator#getRegionLocation` 
to verify: (1) empty `dataRowKeys` returns a safe result (no exception), (2) 
multiple row keys spanning multiple regions yield ordered end keys, and (3) the 
stale-location condition (`endKey <= rowKey`) follows the intended behavior.



##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/UncoveredGlobalIndexRegionScanner.java:
##########
@@ -332,6 +331,29 @@ protected void scanDataTableRows(long startTime) throws 
IOException {
     }
   }
 
+  // Returns the end keys of the data table regions that hold the given row 
keys, in key order. The
+  // locations come from the location cache of the connection. A cache miss 
reads only the meta row
+  // of that region, not the meta rows of all the regions of the table. A 
stale location changes
+  // only how the row keys go into tasks. Each task scans through the client, 
so its scan is correct
+  // across region boundaries
+  private byte[][] getRegionEndKeys(TreeSet<byte[]> dataRowKeys) throws 
IOException {
+    List<byte[]> endKeys = new ArrayList<>();
+    try (RegionLocator locator =
+      hTableFactory.getConnection().getRegionLocator(dataHTable.getName())) {

Review Comment:
   `getRegionEndKeys(...)` opens/closes a `RegionLocator` each time 
`scanDataTableRows(...)` runs (i.e., per page). Even if the region-location 
cache is connection-scoped, repeatedly constructing/closing the locator adds 
overhead on a hot path. Consider creating a single `RegionLocator` once (e.g., 
during scanner initialization) and reusing it for the scanner lifetime, closing 
it when the scanner is closed.



##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/UncoveredGlobalIndexRegionScanner.java:
##########
@@ -332,6 +331,29 @@ protected void scanDataTableRows(long startTime) throws 
IOException {
     }
   }
 
+  // Returns the end keys of the data table regions that hold the given row 
keys, in key order. The
+  // locations come from the location cache of the connection. A cache miss 
reads only the meta row
+  // of that region, not the meta rows of all the regions of the table. A 
stale location changes
+  // only how the row keys go into tasks. Each task scans through the client, 
so its scan is correct
+  // across region boundaries
+  private byte[][] getRegionEndKeys(TreeSet<byte[]> dataRowKeys) throws 
IOException {
+    List<byte[]> endKeys = new ArrayList<>();
+    try (RegionLocator locator =
+      hTableFactory.getConnection().getRegionLocator(dataHTable.getName())) {
+      byte[] rowKey = dataRowKeys.first();
+      while (rowKey != null) {
+        byte[] endKey = 
locator.getRegionLocation(rowKey).getRegion().getEndKey();
+        endKeys.add(endKey);
+        // A location holds its row key, so its end key is after the row key. 
The check stops the
+        // walk at a location that does not hold its row key. Then one task 
set holds the rest
+        rowKey = endKey.length == 0 || Bytes.compareTo(endKey, rowKey) <= 0

Review Comment:
   When `endKey <= rowKey`, the code stops the walk (`rowKey = null`). If this 
happens due to a stale cache entry, the method returns only a partial end-key 
list, which can collapse most remaining keys into a single task and 
significantly reduce parallelism. Instead of terminating immediately, consider 
forcing a cache refresh for that `rowKey` (e.g., using a reload-capable 
region-location API if available) and continuing the walk; alternatively, fall 
back to a safe (but slower) strategy for deriving boundaries only in this 
stale-location case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to