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);
}
}
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();
}
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);
}
}
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);
}
}
}
Aggregations