[ 
https://issues.apache.org/jira/browse/PHOENIX-6185?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17214876#comment-17214876
 ] 

ASF GitHub Bot commented on PHOENIX-6185:
-----------------------------------------

virajjasani commented on a change in pull request #919:
URL: https://github.com/apache/phoenix/pull/919#discussion_r505730341



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/OperationTimeoutWithReasonIT.java
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.end2end;
+
+import org.apache.phoenix.util.EnvironmentEdge;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static 
org.apache.phoenix.exception.SQLExceptionCode.OPERATION_TIMED_OUT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class OperationTimeoutWithReasonIT extends ParallelStatsDisabledIT {
+
+    private static final class MyClock extends EnvironmentEdge {
+        private long time;
+        private final long delay;
+
+        public MyClock (long time, long delay) {
+            this.time = time;
+            this.delay = delay;
+        }
+
+        @Override
+        public long currentTime() {
+            long currentTime = this.time;
+            this.time += this.delay;
+            return currentTime;
+        }
+    }
+
+    @Test
+    public void testOperationTimeout() throws SQLException {
+        final String tableName = generateUniqueName();
+        final String ddl = "CREATE TABLE " + tableName
+            + " (COL1 VARCHAR NOT NULL PRIMARY KEY, COL2 VARCHAR)";
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                 Statement stmt = conn.createStatement()) {
+            stmt.execute(ddl);
+            final String dml = String.format("UPSERT INTO %s VALUES (?, ?)",
+                tableName);
+            try(PreparedStatement prepStmt = conn.prepareStatement(dml)) {
+                for (int i = 1; i <= 100; i++) {
+                    prepStmt.setString(1, "key" + i);
+                    prepStmt.setString(2, "value" + i);
+                    prepStmt.executeUpdate();
+                }
+            }
+            conn.commit();
+        }
+
+        try (Connection conn = DriverManager.getConnection(getUrl());
+             Statement stmt = conn.createStatement()) {
+            stmt.setQueryTimeout(5); // 5 sec
+            ResultSet rs = stmt.executeQuery(String.format("SELECT * FROM %s",
+                tableName));
+            // Use custom EnvironmentEdge to timeout query with a longer delay 
in ms
+            MyClock clock = new MyClock(10, 10000);
+            EnvironmentEdgeManager.injectEdge(clock);
+            try {
+                rs.next();
+                fail();
+            } catch (SQLException e) {
+                assertEquals(OPERATION_TIMED_OUT.getErrorCode(),
+                    e.getErrorCode());
+                assertTrue(e.getMessage().contains("Query couldn't be " +
+                    "completed in the allotted time: 5000 ms"));

Review comment:
       Actually it is null in this case because for the test, rootCause is not 
provided here (BaseResultIterators):
   ```
                               throw new 
SQLExceptionInfo.Builder(OPERATION_TIMED_OUT).setMessage(
                                       ". Query couldn't be completed in the 
allotted time: "
                                               + queryTimeOut + " 
ms").build().buildException();
   ```
   However, I tested by manually adding rootCause and receiving on test side.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> OPERATION_TIMED_OUT#newException method swallows the exception message and 
> root cause exception.
> ------------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-6185
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6185
>             Project: Phoenix
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 4.14.3
>            Reporter: Rushabh Shah
>            Assignee: Viraj Jasani
>            Priority: Major
>             Fix For: 5.1.0, 4.16.0
>
>
> BaseResultIterators#getIterators encountered TimeoutException 
> [here|https://github.com/apache/phoenix/blob/master/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java#L1383-L1389]
> {code:java}
>         } catch (TimeoutException e) {
>             context.getOverallQueryMetrics().queryTimedOut();
>             GLOBAL_QUERY_TIMEOUT_COUNTER.increment();
>             // thrown when a thread times out waiting for the future.get() 
> call to return
>             toThrow = new SQLExceptionInfo.Builder(OPERATION_TIMED_OUT)
>                     .setMessage(". Query couldn't be completed in the 
> allotted time: "
>                             + queryTimeOut + " 
> ms").setRootCause(e).build().buildException();
> {code}
> It creates SQLExceptionInfo object with message indicating the timeout and 
> the root cause exception.
> But 
> [SQLExceptionCode#OPERATION_TIMED_OUT#newException|https://github.com/apache/phoenix/blob/master/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java#L453-L459]
>  ignores all that information and creates SQLException with just template 
> message and loses the root cause exception also.
> {code:java}
>     OPERATION_TIMED_OUT(6000, "TIM01", "Operation timed out.", new Factory() {
>         @Override
>         public SQLException newException(SQLExceptionInfo info) {
>             return new SQLTimeoutException(OPERATION_TIMED_OUT.getMessage(),
>                     OPERATION_TIMED_OUT.getSQLState(), 
> OPERATION_TIMED_OUT.getErrorCode());
>         }
>     }),
> {code}
> Instead it should create SQLTimeoutException from SQLExceptionInfo object.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to