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


##########
phoenix-core-server/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java:
##########
@@ -201,40 +233,141 @@ public long getMaxResultSize() {
       return scanner.getMaxResultSize();
     }
 
+    /**
+     * Applies the scan changes that preScannerOpen did not apply. The checker 
usually changes the
+     * scan before HBase opens the region scanner, so this method has no 
effect. A scanner that
+     * another observer creates directly can receive a scan that the checker 
did not change. Then
+     * this method changes the scan and replaces the region scanner. HBase 
does not ship the
+     * replacement scanner, so the stream read switch applies to it.
+     */
     private void init() throws IOException {
+      boolean scanChanged = false;
       PageFilter pageFilter = ScanUtil.removePageFilter(scan);
       if (pageFilter != null) {
         pageSize = pageFilter.getPageSize();
+        scanChanged = true;
+      }
+      if (addUnverifiedRowFilter(scan, indexMaintainer)) {
+        scanChanged = true;
+      }
+      if (scanChanged) {
         scanner.close();
-        scanner = ((DelegateRegionScanner) delegate).getNewRegionScanner(scan);
-      } else {
-        pageSize = Long.MAX_VALUE;
+        scanner = openScanner(scan);
       }
+    }
+
+    /**
+     * Opens a scanner on the index region and records it as a scanner that 
the checker owns.
+     */
+    private RegionScanner openScanner(Scan newScan) throws IOException {
+      RegionScanner newScanner = ((DelegateRegionScanner) 
delegate).getNewRegionScanner(newScan);
+      streamReadSwitch.scannerOpened(newScan);
+      return newScanner;
+    }
 
-      Filter filter = scan.getFilter();
-      Filter delegateFilter = filter;
-      if (filter instanceof PagingFilter) {
-        delegateFilter = ((PagingFilter) filter).getDelegateFilter();
+    /**
+     * Gets the scan for the scanners that the checker opens to continue the 
index scan. Read repair
+     * writes index rows that are newer than the read point of the original 
scan. The scan has no
+     * read point, so that each new scanner can see the repaired rows.
+     */
+    private Scan getIndexScan() throws IOException {
+      if (indexScan == null) {
+        indexScan = new Scan(scan);
+        PackagePrivateFieldAccessor.setMvccReadPoint(indexScan, -1);
       }
-      if (shouldCreateUnverifiedRowFilter(delegateFilter)) {
-        // we need to ensure that the PagingFilter remains the
-        // topmost (or outermost) filter so wrap the UnverifiedRowFilter
-        // around the original delegate and then set the UnverifiedRowFilter
-        // as the delegate of the PagingFilter
-        UnverifiedRowFilter unverifiedRowFilter =
-          new UnverifiedRowFilter(delegateFilter, emptyCF, emptyCQ);
-        if (filter instanceof PagingFilter) {
-          ((PagingFilter) filter).setDelegateFilter(unverifiedRowFilter);
-        } else {
-          scan.setFilter(unverifiedRowFilter);
+      return indexScan;
+    }
+
+    /**
+     * Gives the scan a new filter chain. A filter object that two scanners 
share gets state from
+     * both scanners. For example, a skip scan filter can then issue a seek 
hint behind its previous
+     * hint. The new chain has the same structure as the filter chain of the 
main scan.
+     */
+    private void setNewFilter(Scan newScan) throws IOException {
+      if (clientFilterProto == null) {
+        Filter clientFilter = getDelegateFilter(scan);
+        if (clientFilter instanceof UnverifiedRowFilter) {
+          clientFilter = ((UnverifiedRowFilter) 
clientFilter).getDelegateFilter();
         }
-        scanner.close();
-        scanner = ((DelegateRegionScanner) delegate).getNewRegionScanner(scan);
+        if (clientFilter != null) {
+          // The serialized form holds only the filter configuration, not the 
scan position. Thus
+          // one serialized form serves all new chains. The stream read switch 
is rare, so one
+          // parse for each new chain is acceptable.
+          clientFilterProto = ProtobufUtil.toFilter(clientFilter);
+          distinctPrefixFilter = 
ScanUtil.findDistinctPrefixFilter(clientFilter);
+        }
+      }
+      Filter filter = clientFilterProto == null
+        ? null
+        : shareDistinctPrefixFilter(ProtobufUtil.toFilter(clientFilterProto));

Review Comment:
   For a reverse DISTINCT/GROUP BY scan that switches to streaming after read 
repair, the shared DistinctPrefixFilter already has reversed=true, but 
deserialization recreates the other filters with reversed=false. 
shareDistinctPrefixFilter then constructs a FilterList containing mixed 
directions, which HBase rejects with IllegalArgumentException, failing the 
query. Set the deserialized chain's reversed flag to scan.isReversed() before 
inserting the shared distinct filter.



-- 
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