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