use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class RelationalNode method getBuffer.
/**
* return the final tuple buffer or null if not available
* @return
* @throws TeiidProcessingException
* @throws TeiidComponentException
* @throws BlockedException
*/
public final TupleBuffer getBuffer(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
CommandContext context = this.getContext();
if (context != null && context.isCancelled()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, getContext().getRequestId()));
}
boolean recordStats = context != null && context.getCollectNodeStatistics() && !isLastBatch();
try {
// start timer for this batch
if (recordStats) {
this.getProcessingState().nodeStatistics.startBatchTimer();
}
TupleBuffer buffer = getBufferDirect(maxRows);
terminateBatches();
if (recordStats) {
// stop timer for this batch (normal)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(buffer.getRowCount(), RelationalNodeStatistics.BATCHCOMPLETE_STOP);
this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren());
if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_DQP, MessageLevel.TRACE) && !buffer.isForwardOnly()) {
for (long i = 1; i <= buffer.getRowCount(); i += buffer.getBatchSize()) {
TupleBatch tb = buffer.getBatch(i);
recordBatch(tb);
}
}
recordStats = false;
}
return buffer;
} catch (BlockedException e) {
if (recordStats) {
// stop timer for this batch (BlockedException)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
recordStats = false;
}
throw e;
} finally {
if (recordStats) {
this.getProcessingState().nodeStatistics.stopBatchTimer();
}
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class RelationalNode method nextBatch.
/**
* Wrapper for nextBatchDirect that does performance timing - callers
* should always call this rather than nextBatchDirect().
* @return
* @throws BlockedException
* @throws TeiidComponentException
* @since 4.2
*/
public final TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
CommandContext context = this.getContext();
if (context != null && context.isCancelled()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, getContext().getRequestId()));
}
boolean recordStats = context != null && context.getCollectNodeStatistics();
try {
while (true) {
// start timer for this batch
if (recordStats) {
this.getProcessingState().nodeStatistics.startBatchTimer();
}
TupleBatch batch = nextBatchDirect();
if (recordStats) {
// stop timer for this batch (normal)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats((long) batch.getRowCount(), RelationalNodeStatistics.BATCHCOMPLETE_STOP);
if (batch.getTerminationFlag()) {
this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren());
// this.nodeStatistics.dumpProperties(this.getClassName());
}
this.recordBatch(batch);
recordStats = false;
}
// this processing style however against the spirit of batch processing (but was already utilized by Sort and Grouping nodes)
if (batch.getRowCount() != 0 || batch.getTerminationFlag()) {
if (batch.getTerminationFlag()) {
close();
}
return batch;
}
}
} catch (BlockedException e) {
if (recordStats) {
// stop timer for this batch (BlockedException)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
recordStats = false;
}
throw e;
} finally {
if (recordStats) {
this.getProcessingState().nodeStatistics.stopBatchTimer();
}
}
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class QueryProcessor method nextBatchDirect.
private TupleBatch nextBatchDirect() throws BlockedException, TeiidProcessingException, TeiidComponentException {
boolean done = false;
TupleBatch result = null;
try {
init();
long currentTime = System.currentTimeMillis();
Assertion.assertTrue(!processorClosed);
while (currentTime < context.getTimeSliceEnd() || context.isNonBlocking()) {
if (requestCanceled) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, this.context.getRequestId()));
}
if (currentTime > context.getTimeoutEnd()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30161, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30161));
}
result = processPlan.nextBatch();
if (continuous) {
result.setRowOffset(rowOffset);
if (result.getTerminationFlag()) {
result.setTermination(TupleBatch.ITERATION_TERMINATED);
List<Object> terminationTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
result.getTuples().add(terminationTuple);
this.context.getTupleSourceCache().close();
this.processPlan.close();
this.processPlan.reset();
this.context.incrementReuseCount();
this.open = false;
}
rowOffset = result.getEndRow() + 1;
}
if (result.getTermination() != TupleBatch.NOT_TERMINATED) {
if (result.getTerminationFlag()) {
done = true;
}
break;
}
if (result.getRowCount() > 0) {
break;
}
}
} catch (BlockedException e) {
throw e;
} catch (TeiidException e) {
closeProcessing();
if (e instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e;
}
if (e instanceof TeiidComponentException) {
throw (TeiidComponentException) e;
}
throw new TeiidComponentException(QueryPlugin.Event.TEIID30162, e);
}
if (done) {
closeProcessing();
}
if (result == null) {
RequestWorkItem workItem = this.getContext().getWorkItem();
if (workItem != null) {
// if we have a workitem (non-test scenario) then before
// throwing exprired time slice we need to indicate there's more work
workItem.moreWork();
}
throw EXPIRED_TIME_SLICE;
}
return result;
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TestAsyncTupleSource method testTupleSource.
@Test
public void testTupleSource() throws TeiidComponentException, TeiidProcessingException {
AsyncTupleSource ats = new AsyncTupleSource(new Callable<TupleSource>() {
@Override
public TupleSource call() throws Exception {
return new CollectionTupleSource(Arrays.asList(Arrays.asList(1), Arrays.asList(2)).iterator());
}
}, new CommandContext());
for (int i = 0; i < 20; i++) {
try {
assertEquals(Arrays.asList(1), ats.nextTuple());
break;
} catch (BlockedException e) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
}
}
}
assertEquals(Arrays.asList(2), ats.nextTuple());
assertNull(ats.nextTuple());
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TestSocketRemoting method testMethodInvocation.
@Test
public void testMethodInvocation() throws Exception {
ClientServiceRegistryImpl csr = new ClientServiceRegistryImpl() {
@Override
public ClassLoader getCallerClassloader() {
return getClass().getClassLoader();
}
};
csr.registerClientService(ILogon.class, new ILogon() {
public ResultsFuture<?> logoff() throws InvalidSessionException {
ResultsFuture<?> result = new ResultsFuture<Void>();
// $NON-NLS-1$
result.getResultsReceiver().exceptionOccurred(new TeiidComponentException("some exception"));
return result;
}
public LogonResult logon(Properties connectionProperties) throws LogonException, TeiidComponentException {
return new LogonResult();
}
// tests asynch where we don't care about the result
public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
return null;
}
@Override
public ResultsFuture<?> ping(Collection<String> sessions) throws TeiidComponentException, CommunicationException {
return null;
}
@Override
public void assertIdentity(SessionToken sessionId) throws InvalidSessionException, TeiidComponentException {
}
@Override
public LogonResult neogitiateGssLogin(Properties connectionProperties, byte[] serviceToken, boolean createSession) throws LogonException {
return null;
}
}, // $NON-NLS-1$
"foo");
// $NON-NLS-1$
csr.registerClientService(FakeService.class, new FakeServiceImpl(), "foo");
final FakeClientServerInstance serverInstance = new FakeClientServerInstance(csr);
SocketServerConnection connection = createFakeConnection(serverInstance);
ILogon logon = connection.getService(ILogon.class);
Future<?> result = logon.ping();
assertNull(result.get(0, TimeUnit.MILLISECONDS));
result = logon.logoff();
try {
result.get(0, TimeUnit.MICROSECONDS);
// $NON-NLS-1$
fail("exception expected");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof TeiidComponentException);
}
FakeService service = connection.getService(FakeService.class);
Future<Integer> asynchInteger = service.asynchResult();
assertEquals(new Integer(5), asynchInteger.get(0, TimeUnit.MILLISECONDS));
try {
service.exceptionMethod();
// $NON-NLS-1$
fail("exception expected");
} catch (TeiidProcessingException e) {
}
DQP dqp = connection.getService(DQP.class);
try {
ResultsFuture<?> future = dqp.begin();
future.get();
// $NON-NLS-1$
fail("exception expected");
} catch (Exception e) {
// $NON-NLS-1$
assertTrue(e.getMessage().indexOf("Component not found:") != -1);
}
}
Aggregations