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


##########
phoenix-core-server/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java:
##########
@@ -237,6 +254,60 @@ private boolean shouldCreateUnverifiedRowFilter(Filter 
delegateFilter) {
       return delegateFilter != null && !indexMaintainer.isUncovered();
     }
 
+    /**
+     * Builds a new filter chain for a repair scan of one row. 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 Filter newSingleRowIndexScanFilter() throws IOException {
+      if (clientFilter != null && clientFilterProto == null) {
+        // The serialized form holds only the filter configuration, not the 
scan position. Thus
+        // one serialized form serves all repair scans. Repair is rare, so one 
parse for each
+        // repair scan is acceptable.
+        clientFilterProto = ProtobufUtil.toFilter(clientFilter);
+      }
+      Filter filter = null;
+      if (clientFilterProto != null) {
+        // The serialized form does not hold the scan direction. The shared 
distinct prefix filter
+        // has the direction of the main scan, and a filter list needs one 
direction for all of
+        // its filters.
+        filter = ProtobufUtil.toFilter(clientFilterProto);
+        filter.setReversed(clientFilter.isReversed());
+        filter = shareDistinctPrefixFilter(filter);
+        if (shouldCreateUnverifiedRowFilter(filter)) {
+          filter = new UnverifiedRowFilter(filter, emptyCF, emptyCQ);
+        }

Review Comment:
   The scan direction (`reversed`) can be lost when `shareDistinctPrefixFilter` 
rebuilds a `FilterList`. You set `filter.setReversed(...)` before calling 
`shareDistinctPrefixFilter(filter)`, but if that method returns a *new* 
`FilterList` (line 306), the new instance won’t inherit the reversed flag. This 
can lead to incorrect behavior for reversed scans. Fix by applying 
`setReversed(...)` after `shareDistinctPrefixFilter(...)` returns, and/or 
explicitly copying the reversed flag onto the newly constructed `FilterList` 
(and ensuring children have consistent direction if required by the filter 
implementations).



##########
phoenix-core-server/src/main/java/org/apache/phoenix/index/GlobalIndexChecker.java:
##########
@@ -237,6 +254,60 @@ private boolean shouldCreateUnverifiedRowFilter(Filter 
delegateFilter) {
       return delegateFilter != null && !indexMaintainer.isUncovered();
     }
 
+    /**
+     * Builds a new filter chain for a repair scan of one row. 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 Filter newSingleRowIndexScanFilter() throws IOException {
+      if (clientFilter != null && clientFilterProto == null) {
+        // The serialized form holds only the filter configuration, not the 
scan position. Thus
+        // one serialized form serves all repair scans. Repair is rare, so one 
parse for each
+        // repair scan is acceptable.
+        clientFilterProto = ProtobufUtil.toFilter(clientFilter);
+      }
+      Filter filter = null;
+      if (clientFilterProto != null) {
+        // The serialized form does not hold the scan direction. The shared 
distinct prefix filter
+        // has the direction of the main scan, and a filter list needs one 
direction for all of
+        // its filters.
+        filter = ProtobufUtil.toFilter(clientFilterProto);
+        filter.setReversed(clientFilter.isReversed());
+        filter = shareDistinctPrefixFilter(filter);
+        if (shouldCreateUnverifiedRowFilter(filter)) {
+          filter = new UnverifiedRowFilter(filter, emptyCF, emptyCQ);
+        }
+      }
+      if (hasPagingFilter) {
+        filter = new PagingFilter(filter, 
ScanUtil.getPageSizeMsForFilter(scan));
+      }
+      return filter;
+    }
+
+    /**
+     * Puts the distinct prefix filter of the main scan into a copy of the 
client filter. This
+     * filter keeps the row key prefix of the last row that the scan returns. 
All scanners of the
+     * scan must share this state. Otherwise the scan can return two rows with 
the same prefix.
+     */
+    private Filter shareDistinctPrefixFilter(Filter filter) {
+      if (distinctPrefixFilter == null) {
+        return filter;
+      }
+      if (filter instanceof DistinctPrefixFilter) {
+        return distinctPrefixFilter;
+      }
+      if (filter instanceof FilterList) {
+        FilterList filterList = (FilterList) filter;
+        List<Filter> filters = new ArrayList<>(filterList.getFilters().size());
+        for (Filter child : filterList.getFilters()) {
+          filters.add(shareDistinctPrefixFilter(child));
+        }
+        return new FilterList(filterList.getOperator(), filters);
+      }

Review Comment:
   The scan direction (`reversed`) can be lost when `shareDistinctPrefixFilter` 
rebuilds a `FilterList`. You set `filter.setReversed(...)` before calling 
`shareDistinctPrefixFilter(filter)`, but if that method returns a *new* 
`FilterList` (line 306), the new instance won’t inherit the reversed flag. This 
can lead to incorrect behavior for reversed scans. Fix by applying 
`setReversed(...)` after `shareDistinctPrefixFilter(...)` returns, and/or 
explicitly copying the reversed flag onto the newly constructed `FilterList` 
(and ensuring children have consistent direction if required by the filter 
implementations).



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