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