Search in sources :

Example 6 with RequestID

use of org.teiid.dqp.message.RequestID in project teiid by teiid.

the class TestRequestID method testSerialize2.

public void testSerialize2() throws Exception {
    RequestID copy = UnitTestUtil.helpSerialize(new RequestID(100));
    assertEquals(null, copy.getConnectionID());
    assertEquals(100, copy.getExecutionID());
    // $NON-NLS-1$
    assertEquals("C.100", copy.toString());
}
Also used : RequestID(org.teiid.dqp.message.RequestID)

Example 7 with RequestID

use of org.teiid.dqp.message.RequestID in project teiid by teiid.

the class DQPCore method executeRequest.

public ResultsFuture<ResultsMessage> executeRequest(long reqID, RequestMessage requestMsg, Long queryTimeout) throws TeiidProcessingException {
    DQPWorkContext workContext = DQPWorkContext.getWorkContext();
    checkActive(workContext);
    RequestID requestID = workContext.getRequestID(reqID);
    requestMsg.setFetchSize(Math.min(requestMsg.getFetchSize(), this.config.getMaxRowsFetchSize()));
    Request request = null;
    if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || requestMsg.getRequestOptions().isContinuous()) {
        request = new PreparedStatementRequest(prepPlanCache);
    } else {
        request = new Request();
    }
    ClientState state = this.getClientState(workContext.getSessionId(), true);
    if (state.session == null) {
        state.session = workContext.getSession();
    }
    request.initialize(requestMsg, bufferManager, dataTierMgr, transactionService, state.sessionTables, workContext, this.prepPlanCache);
    request.setOptions(options);
    request.setExecutor(this.processWorkerPool);
    request.setResultSetCacheEnabled(this.rsCache != null);
    request.setAuthorizationValidator(this.authorizationValidator);
    final PreParser preparser = workContext.getVDB().getAttachment(PreParser.class);
    if (preparser != null) {
        if (this.config.getPreParser() != null) {
            // chain the preparsing effect
            request.setPreParser(new PreParser() {

                @Override
                public String preParse(String command, org.teiid.CommandContext context) {
                    String preParse = config.getPreParser().preParse(command, context);
                    return preparser.preParse(preParse, context);
                }
            });
        } else {
            request.setPreParser(preparser);
        }
    } else {
        request.setPreParser(this.config.getPreParser());
    }
    request.setUserRequestConcurrency(this.getUserRequestSourceConcurrency());
    ResultsFuture<ResultsMessage> resultsFuture = new ResultsFuture<ResultsMessage>();
    final RequestWorkItem workItem = new RequestWorkItem(this, requestMsg, request, resultsFuture.getResultsReceiver(), requestID, workContext);
    logMMCommand(workItem, Event.NEW, null, null);
    addRequest(requestID, workItem, state);
    long timeout = workContext.getVDB().getQueryTimeout();
    timeout = Math.min(timeout > 0 ? timeout : Long.MAX_VALUE, config.getQueryTimeout() > 0 ? config.getQueryTimeout() : Long.MAX_VALUE);
    if (queryTimeout != null && queryTimeout > 0) {
        timeout = Math.min(timeout > 0 ? timeout : Long.MAX_VALUE, queryTimeout);
    }
    if (timeout < Long.MAX_VALUE) {
        final long finalTimeout = timeout;
        workItem.setCancelTask(this.cancellationTimer.add(new Runnable() {

            WeakReference<RequestWorkItem> workItemRef = new WeakReference<RequestWorkItem>(workItem);

            @Override
            public void run() {
                try {
                    RequestWorkItem wi = workItemRef.get();
                    if (wi != null) {
                        String reason = QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31096, finalTimeout);
                        wi.requestCancel(reason);
                    }
                } catch (TeiidComponentException e) {
                    LogManager.logError(LogConstants.CTX_DQP, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30018));
                }
            }
        }, timeout));
    }
    boolean runInThread = requestMsg.isSync();
    synchronized (waitingPlans) {
        if (runInThread || currentlyActivePlans < maxActivePlans) {
            startActivePlan(workItem, !runInThread);
        } else {
            if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_DQP, workItem.requestID, "Queuing plan, since max plans has been reached.");
            }
            waitingPlans.add(workItem);
            maxWaitingPlans = Math.max(this.maxWaitingPlans, waitingPlans.size());
        }
    }
    if (runInThread) {
        workItem.useCallingThread = true;
        workItem.run();
    }
    return resultsFuture;
}
Also used : RequestID(org.teiid.dqp.message.RequestID) ResultsMessage(org.teiid.client.ResultsMessage) PreParser(org.teiid.PreParser) ResultsFuture(org.teiid.client.util.ResultsFuture) WeakReference(java.lang.ref.WeakReference) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 8 with RequestID

use of org.teiid.dqp.message.RequestID in project teiid by teiid.

the class DQPCore method logMMCommand.

void logMMCommand(RequestWorkItem workItem, Event status, Long rowCount, Long cpuTime) {
    if ((status != Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.INFO)) || (status == Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE))) {
        return;
    }
    RequestMessage msg = workItem.requestMsg;
    DQPWorkContext workContext = DQPWorkContext.getWorkContext();
    RequestID rID = workItem.requestID;
    String txnID = null;
    TransactionContext tc = workItem.getTransactionContext();
    if (tc != null && tc.getTransactionType() != Scope.NONE) {
        txnID = tc.getTransactionId();
    }
    String appName = workContext.getAppName();
    // Log to request log
    CommandLogMessage message = null;
    if (status == Event.NEW) {
        message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), appName, workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), msg.getCommandString(), cpuTime);
    } else {
        QueryProcessor qp = workItem.getProcessor();
        PlanNode plan = null;
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE) && qp != null) {
            plan = qp.getProcessorPlan().getDescriptionProperties();
        }
        message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), rowCount, status, plan);
    }
    LogManager.log(status == Event.PLAN ? MessageLevel.TRACE : MessageLevel.INFO, LogConstants.CTX_COMMANDLOGGING, message);
}
Also used : PlanNode(org.teiid.client.plan.PlanNode) RequestID(org.teiid.dqp.message.RequestID) TransactionContext(org.teiid.dqp.service.TransactionContext) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) CommandLogMessage(org.teiid.logging.CommandLogMessage) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 9 with RequestID

use of org.teiid.dqp.message.RequestID in project teiid by teiid.

the class DQPCore method getPlan.

public PlanNode getPlan(String sessionId, long executionId) {
    RequestID requestID = new RequestID(sessionId, executionId);
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
        // $NON-NLS-1$
        LogManager.logDetail(LogConstants.CTX_DQP, "getPlan for requestID=" + requestID);
    }
    RequestWorkItem workItem = safeGetWorkItem(requestID);
    if (workItem == null) {
        return null;
    }
    QueryProcessor qp = workItem.getProcessor();
    if (qp == null) {
        return null;
    }
    return qp.getProcessorPlan().getDescriptionProperties();
}
Also used : RequestID(org.teiid.dqp.message.RequestID) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 10 with RequestID

use of org.teiid.dqp.message.RequestID in project teiid by teiid.

the class DQPCore method stop.

/**
 * perform a full shutdown and wait for 10 seconds for all threads to finish
 */
public void stop() {
    shutdown = true;
    for (RequestID request : requests.keySet()) {
        try {
            // $NON-NLS-1$
            cancelRequest(request, "server shutdown");
        } catch (TeiidComponentException e) {
        }
    }
    processWorkerPool.shutdownNow();
    try {
        processWorkerPool.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
    this.timeoutExecutor.shutdownNow();
    try {
        timeoutExecutor.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
    // TODO: Should we be doing more cleanup here??
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_DQP, "Stopping the DQP");
}
Also used : RequestID(org.teiid.dqp.message.RequestID) TeiidComponentException(org.teiid.core.TeiidComponentException)

Aggregations

RequestID (org.teiid.dqp.message.RequestID)25 RequestMessage (org.teiid.client.RequestMessage)8 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)8 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)6 RequestMetadata (org.teiid.adminapi.impl.RequestMetadata)4 HashSet (java.util.HashSet)3 TeiidComponentException (org.teiid.core.TeiidComponentException)2 QueryProcessor (org.teiid.query.processor.QueryProcessor)2 Command (org.teiid.query.sql.lang.Command)2 CommandContext (org.teiid.query.util.CommandContext)2 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 PreParser (org.teiid.PreParser)1 CacheConfiguration (org.teiid.cache.CacheConfiguration)1 DefaultCacheFactory (org.teiid.cache.DefaultCacheFactory)1 ResultsMessage (org.teiid.client.ResultsMessage)1 PlanNode (org.teiid.client.plan.PlanNode)1 ResultsFuture (org.teiid.client.util.ResultsFuture)1 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)1