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

lokiore pushed a commit to branch 5.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.2 by this push:
     new 4b72b8da6e PHOENIX-7299 (Addendum) :- ScanningResultIterator should 
not time out a query after receiving a valid result (#1876) (#1879)
4b72b8da6e is described below

commit 4b72b8da6e486892b3253d2fdd9a9478c6b38614
Author: Lokesh Khurana <khuranalokes...@gmail.com>
AuthorDate: Wed Apr 10 10:21:36 2024 -0700

    PHOENIX-7299 (Addendum) :- ScanningResultIterator should not time out a 
query after receiving a valid result (#1876) (#1879)
    
    Co-authored-by: Lokesh Khurana <lokesh.khur...@salesforce.com>
---
 .../java/org/apache/phoenix/compile/StatementContext.java    | 12 ++++++++++++
 .../org/apache/phoenix/iterate/ScanningResultIterator.java   |  6 ++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.java
index f795254a36..a7abbd5dd5 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/compile/StatementContext.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
@@ -84,6 +85,7 @@ public class StatementContext {
     private QueryLogger queryLogger;
     private boolean isClientSideUpsertSelect;
     private boolean isUncoveredIndex;
+    private AtomicBoolean hasFirstValidResult;
     
     public StatementContext(PhoenixStatement statement) {
         this(statement, new Scan());
@@ -111,6 +113,7 @@ public class StatementContext {
         this.queryLogger = context.queryLogger;
         this.isClientSideUpsertSelect = context.isClientSideUpsertSelect;
         this.isUncoveredIndex = context.isUncoveredIndex;
+        this.hasFirstValidResult = new 
AtomicBoolean(context.getHasFirstValidResult());
     }
     /**
      *  Constructor that lets you override whether or not to collect request 
level metrics.
@@ -155,6 +158,7 @@ public class StatementContext {
         this.readMetricsQueue = new 
ReadMetricQueue(isRequestMetricsEnabled,connection.getLogLevel());
         this.overAllQueryMetrics = new 
OverAllQueryMetrics(isRequestMetricsEnabled,connection.getLogLevel());
         this.retryingPersistentCache = Maps.<Long, Boolean> newHashMap();
+        this.hasFirstValidResult = new AtomicBoolean(false);
     }
 
     /**
@@ -230,6 +234,14 @@ public class StatementContext {
         return currentTable;
     }
 
+    public boolean getHasFirstValidResult() {
+        return hasFirstValidResult.get();
+    }
+
+    public void setHasFirstValidResult(boolean hasValidResult) {
+        hasFirstValidResult.set(hasValidResult);
+    }
+
     public void setCurrentTable(TableRef table) {
         this.currentTable = table;
     }
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 979bd1f41a..0b60b6d3e6 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
@@ -85,8 +85,6 @@ public class ScanningResultIterator implements ResultIterator 
{
 
     private long dummyRowCounter = 0;
 
-    private boolean hasFirstValidResult = false;
-
     private final ScanningResultPostDummyResultCaller 
scanningResultPostDummyResultCaller;
     private final ScanningResultPostValidResultCaller 
scanningResultPostValidResultCaller;
 
@@ -207,7 +205,7 @@ public class ScanningResultIterator implements 
ResultIterator {
             while (result != null && (result.isEmpty() || isDummy(result))) {
                 dummyRowCounter += 1;
                 long timeOutForScan = maxQueryEndTime - 
EnvironmentEdgeManager.currentTimeMillis();
-                if (!hasFirstValidResult && timeOutForScan < 0) {
+                if (!context.getHasFirstValidResult() && timeOutForScan < 0) {
                     throw new 
SQLExceptionInfo.Builder(OPERATION_TIMED_OUT).setMessage(
                             ". Query couldn't be completed in the allotted 
time : "
                                     + 
context.getStatement().getQueryTimeoutInMillis() + " 
ms").build().buildException();
@@ -227,7 +225,7 @@ public class ScanningResultIterator implements 
ResultIterator {
                 close(); // Free up resources early
                 return null;
             }
-            hasFirstValidResult = true;
+            context.setHasFirstValidResult(true);
             // TODO: use ResultTuple.setResult(result)?
             // Need to create a new one if holding on to it (i.e. 
OrderedResultIterator)
             processAfterRetrievingValidResult();

Reply via email to