use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class DataTierManagerImpl method handleThreadBound.
/**
* thread bound work is tricky for our execution model
*
* the strategy here is that
*
* - if the result is not already a copying tuplesource (from caching)
* then wrap in a copying tuple source
*
* - submit a workitem that will pull the results/fill the buffer,
*
* - return a tuplesource off of the buffer for use by the caller
*/
private TupleSource handleThreadBound(final RequestWorkItem workItem, AtomicRequestMessage aqr, ConnectorWork work, CacheID cid, TupleSource result, DataTierTupleSource dtts, TupleBuffer tb) throws AssertionError, TeiidComponentException, TeiidProcessingException {
if (workItem.useCallingThread) {
// in any case we want the underlying work done in the thread accessing the connectorworkitem
aqr.setSerial(true);
// simple case, just rely on the client using the same thread
return result;
}
if (tb == null) {
tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR);
}
final TupleSource ts = tb.createIndexedTupleSource(cid == null);
if (cid == null) {
result = new CopyOnReadTupleSource(tb, result) {
@Override
public void closeSource() {
ts.closeSource();
}
};
}
final ThreadBoundTask callable = new ThreadBoundTask(workItem, result, dtts);
// but we do so lazily just in case the results aren't needed
if (aqr.isSerial()) {
return new TupleSource() {
boolean processed = false;
@Override
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
if (!processed) {
callable.call();
callable.onCompletion(null);
processed = true;
}
return ts.nextTuple();
}
@Override
public void closeSource() {
if (!processed) {
callable.onCompletion(null);
processed = true;
}
ts.closeSource();
}
};
}
aqr.setSerial(true);
final FutureWork<Void> future = workItem.addWork(callable, callable, 100);
final TupleBuffer buffer = tb;
// return a thread-safe TupleSource
return new TupleSource() {
boolean checkedDone;
@Override
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
// TODO: could refactor as completion listener
if (!checkedDone && future.isDone()) {
checkedDone = true;
try {
future.get();
} catch (InterruptedException e) {
throw new TeiidComponentException(e);
} catch (ExecutionException e) {
if (e.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException) e.getCause();
}
if (e.getCause() instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e.getCause();
}
throw new TeiidComponentException(e);
}
}
synchronized (buffer) {
return ts.nextTuple();
}
}
@Override
public void closeSource() {
synchronized (buffer) {
ts.closeSource();
}
callable.done.set(true);
}
};
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class DataTierManagerImpl method createRequest.
private AtomicRequestMessage createRequest(RequestWorkItem workItem, Command command, String modelName, String connectorBindingId, int nodeID) throws TeiidComponentException {
RequestMessage request = workItem.requestMsg;
// build the atomic request based on original request + context info
AtomicRequestMessage aqr = new AtomicRequestMessage(request, workItem.getDqpWorkContext(), nodeID);
aqr.setCommand(command);
aqr.setModelName(modelName);
aqr.setMaxResultRows(requestMgr.getMaxSourceRows());
aqr.setExceptionOnMaxRows(requestMgr.isExceptionOnMaxSourceRows());
aqr.setPartialResults(request.supportsPartialResults());
aqr.setSerial(requestMgr.getUserRequestSourceConcurrency() == 1);
aqr.setTransactionContext(workItem.getTransactionContext());
aqr.setBufferManager(this.getBufferManager());
if (connectorBindingId == null) {
VDBMetaData vdb = workItem.getDqpWorkContext().getVDB();
ModelMetaData model = vdb.getModel(modelName);
List<String> bindings = model.getSourceNames();
if (bindings == null || bindings.size() != 1) {
// this should not happen, but it did occur when setting up the SystemAdmin models
throw new TeiidComponentException(QueryPlugin.Event.TEIID30554, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30554, modelName, workItem.getDqpWorkContext().getVdbName(), workItem.getDqpWorkContext().getVdbVersion()));
}
connectorBindingId = bindings.get(0);
// $NON-NLS-1$
Assertion.isNotNull(connectorBindingId, "could not obtain connector id");
}
aqr.setConnectorName(connectorBindingId);
return aqr;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class DataTierTupleSource method asynchGet.
private AtomicResultsMessage asynchGet() throws BlockedException, TeiidProcessingException, TeiidComponentException, TranslatorException {
if (futureResult == null) {
addWork();
}
if (!futureResult.isDone()) {
// $NON-NLS-1$
throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking on source query", aqr.getAtomicRequestID());
}
FutureWork<AtomicResultsMessage> currentResults = futureResult;
futureResult = null;
AtomicResultsMessage results = null;
try {
results = currentResults.get();
if (results.getFinalRow() < 0) {
addWork();
}
} catch (CancellationException e) {
throw new TeiidProcessingException(e);
} catch (InterruptedException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30503, e);
} catch (ExecutionException e) {
if (e.getCause() instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e.getCause();
}
if (e.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException) e.getCause();
}
if (e.getCause() instanceof TranslatorException) {
throw (TranslatorException) e.getCause();
}
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
// shouldn't happen
throw new RuntimeException(e);
}
return results;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class DataTierTupleSource method exceptionOccurred.
AtomicResultsMessage exceptionOccurred(TranslatorException exception) throws TeiidComponentException, TeiidProcessingException {
if (workItem.requestMsg.supportsPartialResults()) {
AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0]);
emptyResults.setWarnings(Arrays.asList((Exception) exception));
emptyResults.setFinalRow(this.rowsProcessed);
return emptyResults;
}
fullyCloseSource();
if (exception.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException) exception.getCause();
}
if (exception.getCause() instanceof TeiidProcessingException) {
throw (TeiidProcessingException) exception.getCause();
}
// $NON-NLS-1$
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30504, exception, this.getConnectorName() + ": " + exception.getMessage());
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class Request method getTransactionContext.
TransactionContext getTransactionContext(boolean startAutoWrap) throws TeiidComponentException {
if (this.transactionContext != null) {
return this.transactionContext;
}
TransactionContext tc = transactionService.getOrCreateTransactionContext(workContext.getSessionId());
if (tc.getTransactionType() == TransactionContext.Scope.REQUEST && this.workContext.isDerived()) {
// to a sub-request, request scope should appear as global - which means associated and non-suspendable
tc = tc.clone();
tc.setTransactionType(TransactionContext.Scope.INHERITED);
}
// $NON-NLS-1$
Assertion.assertTrue(tc.getTransactionType() != TransactionContext.Scope.REQUEST, "Transaction already associated with request.");
// If local or global transaction is not started.
if (tc.getTransactionType() == Scope.NONE && !requestMsg.isNoExec()) {
if (!startAutoWrap) {
return null;
}
Boolean startAutoWrapTxn = false;
if (RequestMessage.TXN_WRAP_ON.equals(requestMsg.getTxnAutoWrapMode())) {
startAutoWrapTxn = true;
} else if (RequestMessage.TXN_WRAP_DETECT.equals(requestMsg.getTxnAutoWrapMode())) {
boolean transactionalRead = requestMsg.getTransactionIsolation() == Connection.TRANSACTION_REPEATABLE_READ || requestMsg.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE;
startAutoWrapTxn = processPlan.requiresTransaction(transactionalRead);
if (startAutoWrapTxn == null) {
startAutoWrapTxn = false;
}
}
if (startAutoWrapTxn) {
try {
transactionService.begin(tc);
} catch (XATransactionException err) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30493, err);
}
}
}
tc.setIsolationLevel(requestMsg.getTransactionIsolation());
this.transactionContext = tc;
return this.transactionContext;
}
Aggregations