Search in sources :

Example 1 with SqlMemoryQuotaExceededException

use of org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException in project gridgain by gridgain.

the class QueryMemoryTrackerSelfTest method testGlobalQuota.

/**
 * {@inheritDoc}
 */
@Test
@Override
public void testGlobalQuota() throws Exception {
    final List<QueryCursor> cursors = new ArrayList<>();
    try {
        for (int i = 0; i < 100; i++) {
            QueryCursor<List<?>> cur = query("select DISTINCT T.name, T.id from T ORDER BY T.name", true);
            cursors.add(cur);
            Iterator<List<?>> iter = cur.iterator();
            iter.next();
        }
        fail("Exception not thrown.");
    } catch (SqlMemoryQuotaExceededException ex) {
        assertTrue(ex.getMessage().contains("SQL query ran out of memory: Global quota was exceeded."));
        assertEquals(IgniteQueryErrorCode.QUERY_OUT_OF_MEMORY, ex.statusCode());
        assertEquals(IgniteQueryErrorCode.codeToSqlState(IgniteQueryErrorCode.QUERY_OUT_OF_MEMORY), ex.sqlState());
        assertTrue(localResults.size() > 0);
        assertTrue(cursors.size() > 0);
        IgniteH2Indexing h2 = (IgniteH2Indexing) grid(1).context().query().getIndexing();
        long globalAllocated = h2.memoryManager().reserved();
        assertTrue(h2.memoryManager().memoryLimit() < globalAllocated + MB);
    } finally {
        for (QueryCursor c : cursors) IgniteUtils.closeQuiet(c);
    }
}
Also used : SqlMemoryQuotaExceededException(org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Test(org.junit.Test)

Example 2 with SqlMemoryQuotaExceededException

use of org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException in project gridgain by gridgain.

the class MemoryQuotaStaticConfigurationTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    initGrid("0", "50%", false);
    String qry = "SELECT listagg(p1.name), listagg(p1.name), listagg(p1.name), listagg(p1.name), " + "listagg(p1.name), listagg(p1.name), listagg(p1.name), listagg(p1.name), " + "listagg(p1.name), listagg(p1.name), listagg(p1.name), listagg(p1.name) " + "FROM person p1 JOIN person p2 WHERE p1.id < ";
    int param = 0;
    // Find queries which consume 10%, 25%, 50% and more than 60% of heap.
    for (int i = PERS_CNT; i >= 0; i -= 100) {
        try {
            grid("client").cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery(qry + i).setLazy(true)).getAll();
            // We found first value with memory consumption less than 60%.
            param = i;
            break;
        } catch (SqlMemoryQuotaExceededException e) {
            assertTrue("Wrong message:" + e.getMessage(), e.getMessage().contains("Query quota was exceeded."));
        }
    }
    if (param <= 0 || param >= PERS_CNT)
        throw new IllegalStateException("Can not start test, quota can not be determined. " + "Consider changing the query. Query parameter=" + param);
    qry50Percent = qry + param;
    qry25Percent = qry + (param / 2);
    qry10Percent = qry + (param / 5);
    qryMore60Percent = qry + PERS_CNT;
    if (log.isInfoEnabled()) {
        log.info("Query with memory consumption more than 60%: " + qryMore60Percent);
        log.info("Query with memory consumption a bit less than 50%: " + qry50Percent);
        log.info("Query with memory consumption about 25%: " + qry25Percent);
        log.info("Query with memory consumption about 10%: " + qry10Percent);
    }
    afterTest();
}
Also used : SqlMemoryQuotaExceededException(org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 3 with SqlMemoryQuotaExceededException

use of org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException in project gridgain by gridgain.

the class GridReduceQueryExecutor method fail.

/**
 * @param r Query run.
 * @param nodeId Failed node ID.
 * @param msg Error message.
 * @param failCode Fail code.
 */
private void fail(ReduceQueryRun r, UUID nodeId, String msg, byte failCode, int sqlErrCode) {
    if (r != null) {
        CacheException e;
        String mapperFailedMsg = "Failed to execute map query on remote node [nodeId=" + nodeId + ", errMsg=" + msg + ']';
        if (failCode == GridQueryFailResponse.CANCELLED_BY_ORIGINATOR)
            e = new CacheException(mapperFailedMsg, new QueryCancelledException());
        else if (failCode == GridQueryFailResponse.RETRY_QUERY)
            e = new CacheException(mapperFailedMsg, new QueryRetryException(msg));
        else if (sqlErrCode == IgniteQueryErrorCode.QUERY_OUT_OF_MEMORY) {
            e = new SqlMemoryQuotaExceededException(msg);
            e.addSuppressed(new IgniteSQLMapStepException(msg));
        } else {
            Throwable mapExc = sqlErrCode > 0 ? new IgniteSQLMapStepException(mapperFailedMsg, new IgniteSQLException(msg, sqlErrCode)) : null;
            e = new CacheException(mapperFailedMsg, mapExc);
        }
        r.setStateOnException(nodeId, e);
    }
}
Also used : QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) SqlMemoryQuotaExceededException(org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException) CacheException(javax.cache.CacheException) SqlCacheException(org.apache.ignite.cache.query.exceptions.SqlCacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteSQLMapStepException(org.apache.ignite.internal.processors.query.IgniteSQLMapStepException) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException)

Example 4 with SqlMemoryQuotaExceededException

use of org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException in project gridgain by gridgain.

the class DiskSpillingAbstractTest method checkQuery.

/**
 */
protected void checkQuery(Result res, String sql, int threadNum, int iterations) {
    WatchService watchSvc = null;
    WatchKey watchKey = null;
    try {
        watchSvc = FileSystems.getDefault().newWatchService();
        Path workDir = getWorkDir();
        watchKey = workDir.register(watchSvc, ENTRY_CREATE, ENTRY_DELETE);
        final AtomicBoolean oomExThrown = new AtomicBoolean();
        multithreaded(() -> {
            try {
                for (int i = 0; i < iterations; i++) {
                    IgniteEx grid = fromClient() ? grid("client") : grid(0);
                    grid.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery(sql)).getAll();
                }
            } catch (SqlMemoryQuotaExceededException e) {
                oomExThrown.set(true);
                assertFalse("Unexpected exception:" + X.getFullStackTrace(e), res.success);
                if (res == Result.ERROR_GLOBAL_QUOTA)
                    assertTrue("Wrong message:" + X.getFullStackTrace(e), e.getMessage().contains("Global quota was exceeded."));
                else
                    assertTrue("Wrong message:" + X.getFullStackTrace(e), e.getMessage().contains("Query quota was exceeded."));
            } catch (Throwable t) {
                log.error("Caught exception:" + X.getFullStackTrace(t));
                throw t;
            }
        }, threadNum);
        assertEquals("Exception expected=" + !res.success + ", exception thrown=" + oomExThrown.get(), !res.success, oomExThrown.get());
    } catch (Exception e) {
        fail(X.getFullStackTrace(e));
    } finally {
        try {
            if (watchKey != null) {
                List<WatchEvent<?>> dirEvts = watchKey.pollEvents();
                assertEquals("Disk spilling " + (res.offload ? "not" : "") + " happened.", res.offload, !dirEvts.isEmpty());
            }
            assertWorkDirClean();
            checkMemoryManagerState();
        } finally {
            U.closeQuiet(watchSvc);
        }
    }
}
Also used : Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlMemoryQuotaExceededException(org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException) IgniteEx(org.apache.ignite.internal.IgniteEx) WatchKey(java.nio.file.WatchKey) WatchEvent(java.nio.file.WatchEvent) WatchService(java.nio.file.WatchService) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlMemoryQuotaExceededException(org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Aggregations

SqlMemoryQuotaExceededException (org.apache.ignite.cache.query.exceptions.SqlMemoryQuotaExceededException)4 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 WatchEvent (java.nio.file.WatchEvent)1 WatchKey (java.nio.file.WatchKey)1 WatchService (java.nio.file.WatchService)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CacheException (javax.cache.CacheException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)1 QueryCursor (org.apache.ignite.cache.query.QueryCursor)1 QueryRetryException (org.apache.ignite.cache.query.QueryRetryException)1 SqlCacheException (org.apache.ignite.cache.query.exceptions.SqlCacheException)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1 IgniteSQLMapStepException (org.apache.ignite.internal.processors.query.IgniteSQLMapStepException)1