This is an automated email from the ASF dual-hosted git repository. ipavlukhin 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 4ce6826 IGNITE-12338 Use IgniteThread to notify about long query - Fixes #7025. 4ce6826 is described below commit 4ce68267922920a87d2d8998b88d79083e473b80 Author: ktkalenko <ktkale...@gridgain.com> AuthorDate: Fri Nov 1 12:00:43 2019 +0300 IGNITE-12338 Use IgniteThread to notify about long query - Fixes #7025. Signed-off-by: ipavlukhin <vololo...@gmail.com> --- .../query/h2/LongRunningQueryManager.java | 8 +++- .../processors/query/LongRunningQueryTest.java | 52 +++++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/LongRunningQueryManager.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/LongRunningQueryManager.java index efc10d3..f406ff3 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/LongRunningQueryManager.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/LongRunningQueryManager.java @@ -24,6 +24,7 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.worker.GridWorker; +import org.apache.ignite.thread.IgniteThread; /** * Long running query manager. @@ -32,6 +33,9 @@ public final class LongRunningQueryManager { /** Check period in ms. */ private static final long CHECK_PERIOD = 1_000; + /** Message about the long execution of the query. */ + public static final String LONG_QUERY_EXEC_MSG = "Query execution is too long"; + /** Queries collection. Sorted collection isn't used to reduce 'put' time. */ private final ConcurrentHashMap<H2QueryInfo, TimeoutChecker> qrys = new ConcurrentHashMap<>(); @@ -73,7 +77,7 @@ public final class LongRunningQueryManager { timeout = ctx.config().getLongQueryWarningTimeout(); - Thread thread = new Thread(checkWorker); + IgniteThread thread = new IgniteThread(checkWorker); thread.setDaemon(true); thread.start(); @@ -117,7 +121,7 @@ public final class LongRunningQueryManager { H2QueryInfo qinfo = e.getKey(); if (e.getValue().checkTimeout(qinfo.time())) { - qinfo.printLogMessage(log, "Query execution is too long"); + qinfo.printLogMessage(log, LONG_QUERY_EXEC_MSG); if (e.getValue().timeoutMult <= 1) qrys.remove(qinfo); diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LongRunningQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LongRunningQueryTest.java index a5827c3..4ede7e3 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LongRunningQueryTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/LongRunningQueryTest.java @@ -31,11 +31,16 @@ import org.apache.ignite.cache.query.annotations.QuerySqlFunction; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest; import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; +import org.apache.ignite.internal.processors.query.h2.LongRunningQueryManager; +import org.apache.ignite.internal.util.worker.GridWorker; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.ListeningTestLogger; import org.apache.ignite.testframework.LogListener; import org.junit.Test; +import static java.lang.Thread.currentThread; +import static org.apache.ignite.internal.processors.query.h2.LongRunningQueryManager.LONG_QUERY_EXEC_MSG; + /** * Tests for log print for long running query. */ @@ -99,6 +104,26 @@ public class LongRunningQueryTest extends AbstractIndexingCommonTest { } /** + * Test checks the correctness of thread name when displaying errors + * about long queries. + */ + @Test + public void testCorrectThreadName() { + GridWorker checkWorker = GridTestUtils.getFieldValue(longRunningQueryManager(), "checkWorker"); + + LogListener logLsnr = LogListener + .matches(LONG_QUERY_EXEC_MSG) + .andMatches(logStr -> currentThread().getName().startsWith(checkWorker.name())) + .build(); + + testLog().registerListener(logLsnr); + + sqlCheckLongRunning(); + + assertTrue(logLsnr.check()); + } + + /** * Do several fast queries. * Log messages must not contain info about long query. */ @@ -106,7 +131,7 @@ public class LongRunningQueryTest extends AbstractIndexingCommonTest { ListeningTestLogger testLog = testLog(); LogListener lsnr = LogListener - .matches(Pattern.compile("Query execution is too long")) + .matches(Pattern.compile(LONG_QUERY_EXEC_MSG)) .build(); testLog.registerListener(lsnr); @@ -126,12 +151,12 @@ public class LongRunningQueryTest extends AbstractIndexingCommonTest { ListeningTestLogger testLog = testLog(); LogListener lsnr = LogListener - .matches("Query execution is too long") + .matches(LONG_QUERY_EXEC_MSG) .build(); testLog.registerListener(lsnr); - sqlCheckLongRunning("SELECT T0.id FROM test AS T0, test AS T1, test AS T2 where T0.id > ?", 0); + sqlCheckLongRunning(); assertTrue(lsnr.check()); } @@ -140,11 +165,18 @@ public class LongRunningQueryTest extends AbstractIndexingCommonTest { * @param sql SQL query. * @param args Query parameters. */ - private void sqlCheckLongRunning(String sql, Object ... args) { + private void sqlCheckLongRunning(String sql, Object... args) { GridTestUtils.assertThrowsAnyCause(log, () -> sql(sql, args).getAll(), QueryCancelledException.class, ""); } /** + * Execute long running sql with a check for errors. + */ + private void sqlCheckLongRunning() { + sqlCheckLongRunning("SELECT T0.id FROM test AS T0, test AS T1, test AS T2 where T0.id > ?", 0); + } + + /** * @param sql SQL query. * @param args Query parameters. * @return Results cursor. @@ -186,9 +218,17 @@ public class LongRunningQueryTest extends AbstractIndexingCommonTest { private ListeningTestLogger testLog() { ListeningTestLogger testLog = new ListeningTestLogger(false, log); - GridTestUtils.setFieldValue(((IgniteH2Indexing)grid().context().query().getIndexing()).longRunningQueries(), - "log", testLog); + GridTestUtils.setFieldValue(longRunningQueryManager(), "log", testLog); return testLog; } + + /** + * Getting {@link LongRunningQueryManager} from the node. + * + * @return LongRunningQueryManager. + */ + private LongRunningQueryManager longRunningQueryManager() { + return ((IgniteH2Indexing)grid().context().query().getIndexing()).longRunningQueries(); + } }