Skip to content
Permalink
Browse files
IGNITE-17001 Don't print error on user input into node log (#10026)
  • Loading branch information
Taras Ledkov committed May 20, 2022
1 parent f22b520 commit 649e98f7171fb868c4bb7ab6735e94d4532c7083
Showing 2 changed files with 64 additions and 9 deletions.
@@ -24,7 +24,10 @@
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 void testPreparedExecute() throws SQLException {
*
*/
@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());
}
}
@@ -63,6 +63,7 @@
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 @@ private JdbcResponse executeQuery(JdbcQueryExecuteRequest req) {

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 @@ private static boolean isClientPartitionAwarenessApplicable(boolean partResReque
@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());
}
}

0 comments on commit 649e98f

Please sign in to comment.