You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tl...@apache.org on 2022/05/20 16:59:53 UTC

[ignite] branch master updated: IGNITE-17001 Don't print error on user input into node log (#10026)

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

tledkov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 649e98f7171 IGNITE-17001 Don't print error on user input into node log (#10026)
649e98f7171 is described below

commit 649e98f7171fb868c4bb7ab6735e94d4532c7083
Author: Taras Ledkov <tl...@gridgain.com>
AuthorDate: Fri May 20 19:59:44 2022 +0300

    IGNITE-17001 Don't print error on user input into node log (#10026)
---
 .../jdbc/thin/JdbcThinInsertStatementSelfTest.java | 39 ++++++++++++++++++----
 .../processors/odbc/jdbc/JdbcRequestHandler.java   | 34 +++++++++++++++++--
 2 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinInsertStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinInsertStatementSelfTest.java
index 5bdff4d9e25..44f3ddad44f 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinInsertStatementSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinInsertStatementSelfTest.java
@@ -24,7 +24,10 @@ import java.sql.Statement;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.concurrent.Callable;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
 import org.junit.Test;
 
 /**
@@ -41,6 +44,9 @@ public class JdbcThinInsertStatementSelfTest extends JdbcThinAbstractDmlStatemen
     private static final String SQL_PREPARED = "insert into Person(_key, id, firstName, lastName, age) values " +
         "(?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?, ?, ?, ?)";
 
+    /** Test logger. */
+    private static ListeningTestLogger srvLog;
+
     /** Arguments for prepared statement. */
     private final Object[][] args = new Object[][] {
         {"p1", 1, "John", "White", 25},
@@ -54,6 +60,19 @@ public class JdbcThinInsertStatementSelfTest extends JdbcThinAbstractDmlStatemen
     /** Prepared statement. */
     private PreparedStatement prepStmt;
 
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        srvLog = new ListeningTestLogger(log);
+
+        super.beforeTestsStarted();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setGridLogger(srvLog);
+    }
+
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
@@ -174,17 +193,25 @@ public class JdbcThinInsertStatementSelfTest extends JdbcThinAbstractDmlStatemen
      *
      */
     @Test
-    public void testDuplicateKeys() {
+    public void testDuplicateKeys() throws InterruptedException {
         jcache(0).put("p2", new Person(2, "Joe", "Black", 35));
 
+        LogListener lsnr = LogListener
+            .matches("Failed to execute SQL query")
+            .build();
+
+        srvLog.registerListener(lsnr);
+
         GridTestUtils.assertThrowsAnyCause(log, new Callable<Object>() {
-            /** {@inheritDoc} */
-            @Override public Object call() throws Exception {
-                return stmt.execute(SQL);
-            }
-        }, SQLException.class,
+                /** {@inheritDoc} */
+                @Override public Object call() throws Exception {
+                    return stmt.execute(SQL);
+                }
+            }, SQLException.class,
             "Failed to INSERT some keys because they are already in cache [keys=[p2]]");
 
+        assertFalse(lsnr.check(1000L));
+
         assertEquals(3, jcache(0).withKeepBinary().getAll(new HashSet<>(Arrays.asList("p1", "p2", "p3"))).size());
     }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcRequestHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcRequestHandler.java
index d3d35648265..10937a9c393 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcRequestHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcRequestHandler.java
@@ -63,6 +63,7 @@ import org.apache.ignite.internal.processors.odbc.ClientListenerRequestHandler;
 import org.apache.ignite.internal.processors.odbc.ClientListenerResponse;
 import org.apache.ignite.internal.processors.odbc.ClientListenerResponseSender;
 import org.apache.ignite.internal.processors.odbc.SqlListenerUtils;
+import org.apache.ignite.internal.processors.odbc.SqlStateCode;
 import org.apache.ignite.internal.processors.query.GridQueryCancel;
 import org.apache.ignite.internal.processors.query.IgniteSQLException;
 import org.apache.ignite.internal.processors.query.NestedTxMode;
@@ -738,12 +739,29 @@ public class JdbcRequestHandler implements ClientListenerRequestHandler {
 
             unregisterReq = true;
 
-            U.error(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req=" + req + ']', e);
+            if (X.cause(e, QueryCancelledException.class) != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Failed to execute SQL query " +
+                        "[reqId=" + req.requestId() +
+                        ", req=" + req +
+                        "]. Error:" + X.getFullStackTrace(e));
+                }
 
-            if (X.cause(e, QueryCancelledException.class) != null)
                 return exceptionToResult(new QueryCancelledException());
-            else
+            }
+            else if (X.cause(e, IgniteSQLException.class) != null) {
+                IgniteSQLException e0 = X.cause(e, IgniteSQLException.class);
+
+                if (isNeedToNodeLog(e0))
+                    U.warn(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req=" + req + ']', e);
+
+                return exceptionToResult(e0);
+            }
+            else {
+                U.warn(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req=" + req + ']', e);
+
                 return exceptionToResult(e);
+            }
         }
         finally {
             cleanupQueryCancellationMeta(unregisterReq, req.requestId());
@@ -1605,4 +1623,14 @@ public class JdbcRequestHandler implements ClientListenerRequestHandler {
     @Override public ClientListenerProtocolVersion protocolVersion() {
         return protocolVer;
     }
+
+    /**
+     * Checks SQL error to print into node log.
+     *
+     * @param e Exception to handle.
+     * @return {@code true} is the exception should be printed into node log. Otherwise, returns {@code false}.
+     */
+    private static boolean isNeedToNodeLog(IgniteSQLException e) {
+        return SqlStateCode.INTERNAL_ERROR.equals(e.sqlState());
+    }
 }