Search in sources :

Example 1 with QueryCanceledException

use of mondrian.olap.QueryCanceledException in project mondrian by pentaho.

the class SegmentCacheIndexImpl method cancel.

public void cancel(Execution exec) {
    checkThread();
    List<SegmentHeader> toRemove = new ArrayList<SegmentHeader>();
    for (Entry<SegmentHeader, HeaderInfo> entry : headerMap.entrySet()) {
        if (entry.getValue().clients.remove(exec)) {
            if (entry.getValue().slot != null && !entry.getValue().slot.isDone() && entry.getValue().clients.isEmpty()) {
                toRemove.add(entry.getKey());
            }
        }
    }
    // Make sure to cleanup the orphaned segments.
    for (SegmentHeader header : toRemove) {
        final Statement stmt = headerMap.get(header).stmt;
        loadFailed(header, new QueryCanceledException("Canceling due to an absence of interested parties."));
        // We only want to cancel the statement, but we can't close it.
        // Some drivers will not notice the interruption flag on their
        // own thread before a considerable time has passed. If we were
        // using a pooling layer, calling close() would make the
        // underlying connection available again, despite the first
        // statement still being processed. Some drivers will fail
        // there. It is therefore important to close and release the
        // resources on the proper thread, namely, the thread which
        // runs the actual statement.
        Util.cancelStatement(stmt);
    }
}
Also used : QueryCanceledException(mondrian.olap.QueryCanceledException) Statement(java.sql.Statement) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with QueryCanceledException

use of mondrian.olap.QueryCanceledException in project mondrian by pentaho.

the class BasicQueryTest method executeAndCancelAtSqlFetch.

private Long executeAndCancelAtSqlFetch(final String query, final String triggerSql, final String component) throws Exception {
    // avoid cache to ensure sql executes
    TestContext context = getTestContext().withFreshConnection();
    context.flushSchemaCache();
    RolapConnection conn = (RolapConnection) context.getConnection();
    final mondrian.server.Statement stmt = conn.getInternalStatement();
    // use the logger to block and trigger cancelation at the right time
    Logger sqlLog = RolapUtil.SQL_LOGGER;
    propSaver.set(sqlLog, org.apache.logging.log4j.Level.DEBUG);
    final Execution exec = new Execution(stmt, 50000);
    final CountDownLatch okToGo = new CountDownLatch(1);
    AtomicLong rows = new AtomicLong();
    Appender canceler = new SqlCancelingAppender(component, triggerSql, exec, okToGo, rows);
    stmt.setQuery(conn.parseQuery(query));
    // sqlLog.addAppender( canceler );
    Util.addAppender(canceler, sqlLog, null);
    try {
        conn.execute(exec);
        Assert.fail("Query not canceled.");
    } catch (QueryCanceledException e) {
        // 5 sec just in case it all goes wrong
        if (!okToGo.await(5, TimeUnit.SECONDS)) {
            Assert.fail("Timeout reading sql statement end from log.");
        }
        return rows.longValue();
    } finally {
        // sqlLog.removeAppender( canceler );
        Util.removeAppender(canceler, sqlLog);
        context.close();
    }
    return null;
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) RolapConnection(mondrian.rolap.RolapConnection) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryCanceledException(mondrian.olap.QueryCanceledException) Execution(mondrian.server.Execution) Logger(org.apache.logging.log4j.Logger) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

QueryCanceledException (mondrian.olap.QueryCanceledException)2 Statement (java.sql.Statement)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 RolapConnection (mondrian.rolap.RolapConnection)1 Execution (mondrian.server.Execution)1 Logger (org.apache.logging.log4j.Logger)1 Appender (org.apache.logging.log4j.core.Appender)1 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)1