Search in sources :

Example 61 with TeiidComponentException

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);
        }
    };
}
Also used : CopyOnReadTupleSource(org.teiid.dqp.internal.process.TupleSourceCache.CopyOnReadTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) CopyOnReadTupleSource(org.teiid.dqp.internal.process.TupleSourceCache.CopyOnReadTupleSource) TeiidComponentException(org.teiid.core.TeiidComponentException) ExecutionException(java.util.concurrent.ExecutionException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 62 with TeiidComponentException

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;
}
Also used : RequestMessage(org.teiid.client.RequestMessage) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) TeiidComponentException(org.teiid.core.TeiidComponentException) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 63 with TeiidComponentException

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;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CancellationException(java.util.concurrent.CancellationException) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TeiidComponentException(org.teiid.core.TeiidComponentException) TranslatorException(org.teiid.translator.TranslatorException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 64 with TeiidComponentException

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());
}
Also used : AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) CancellationException(java.util.concurrent.CancellationException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 65 with TeiidComponentException

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;
}
Also used : TransactionContext(org.teiid.dqp.service.TransactionContext) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)109 TeiidProcessingException (org.teiid.core.TeiidProcessingException)33 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)23 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)23 ArrayList (java.util.ArrayList)18 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)17 BlockedException (org.teiid.common.buffer.BlockedException)16 IOException (java.io.IOException)15 List (java.util.List)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 Test (org.junit.Test)12 LanguageObject (org.teiid.query.sql.LanguageObject)12 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)11 CommandContext (org.teiid.query.util.CommandContext)11 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)10 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 HashMap (java.util.HashMap)7 TeiidException (org.teiid.core.TeiidException)7 LogonException (org.teiid.client.security.LogonException)6