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); Assertion.isNotNull(connectorBindingId, "could not obtain connector id"); //$NON-NLS-1$ } aqr.setConnectorName(connectorBindingId); return aqr; }
ConnectorWorkItem(AtomicRequestMessage message, ConnectorManager manager) throws TeiidComponentException { this.id = message.getAtomicRequestID(); this.requestMsg = message; this.manager = manager; AtomicRequestID requestID = this.requestMsg.getAtomicRequestID(); this.securityContext = new ExecutionContextImpl(message.getCommandContext(), requestMsg.getConnectorName(), Integer.toString(requestID.getNodeID()), Integer.toString(requestID.getExecutionId()), this); SourceHint hint = message.getCommand().getSourceHint(); if (hint != null) { this.securityContext.setGeneralHints(hint.getGeneralHints()); SpecificHint specificHint = hint.getSpecificHint(message.getConnectorName()); if (specificHint != null) { this.securityContext.setHints(specificHint.getHints()); this.securityContext.setBatchSize(this.requestMsg.getFetchSize()); this.securityContext.setSession(requestMsg.getWorkContext().getSession()); VDBMetaData vdb = requestMsg.getWorkContext().getVDB(); QueryMetadataInterface qmi = vdb.getAttachment(QueryMetadataInterface.class); qmi = new TempMetadataAdapter(qmi, new TempMetadataStore()); this.queryMetadata = new RuntimeMetadataImpl(qmi); this.securityContext.setRuntimeMetadata(this.queryMetadata); this.securityContext.setTransactional(requestMsg.isTransactional()); LanguageBridgeFactory factory = new LanguageBridgeFactory(this.queryMetadata); CommandContext context = requestMsg.getCommandContext(); try { SourceCapabilities capabilities = manager.getCapabilities();
static AtomicRequestMessage createNewAtomicRequestMessage(int requestid, int nodeid) throws Exception { RequestMessage rm = new RequestMessage(); DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(EXAMPLE_BQT, RealMetadataFactory.exampleBQTVDB()); workContext.getSession().setSessionId(String.valueOf(1)); workContext.getSession().setUserName("foo"); //$NON-NLS-1$ AtomicRequestMessage request = new AtomicRequestMessage(rm, workContext, nodeid); request.setCommand(helpGetCommand("SELECT BQT1.SmallA.INTKEY FROM BQT1.SmallA", EXAMPLE_BQT)); //$NON-NLS-1$ request.setRequestID(new RequestID(requestid)); request.setConnectorName("testing"); //$NON-NLS-1$ request.setFetchSize(5); request.setCommandContext(new CommandContext()); return request; }
Command cmd = qr.getCommand(); sqlStr = cmd != null ? cmd.toString() : null; String userName = qr.getWorkContext().getUserName(); String transactionID = null; if ( qr.isTransactional() ) { transactionID = qr.getTransactionContext().getTransactionId(); String modelName = qr.getModelName(); AtomicRequestID sid = qr.getAtomicRequestID(); message = new CommandLogMessage(System.currentTimeMillis(), qr.getRequestID().toString(), sid.getNodeID(), transactionID, modelName, translatorName, qr.getWorkContext().getSessionId(), principal, sqlStr, context); message = new CommandLogMessage(System.currentTimeMillis(), qr.getRequestID().toString(), sid.getNodeID(), transactionID, modelName, translatorName, qr.getWorkContext().getSessionId(), principal, finalRowCnt, cmdStatus, context, cpuTime); if (cmdStatus == Event.SOURCE) { message.setSourceCommand(command);
public void fullyCloseSource() { cancelFutures(); cancelAsynch = true; if (closing.compareAndSet(false, true)) { if (!done && !errored) { this.cwi.cancel(false); } workItem.closeAtomicRequest(this.aqr.getAtomicRequestID()); if (aqr.isSerial() || futureResult == null) { this.cwi.close(); } else { futureResult.addCompletionListener(new CompletionListener<AtomicResultsMessage>() { @Override public void onCompletion(FutureWork<AtomicResultsMessage> future) { if (running) { return; //-- let the other thread close } if (closed.compareAndSet(false, true)) { cwi.close(); } } }); } } }
aqr.setCommandContext(context); if (parameterObject.fetchSize > 0) { aqr.setFetchSize(2*parameterObject.fetchSize); aqr.setFetchSize(Math.min(parameterObject.limit, aqr.getFetchSize())); aqr.setCopyStreamingLobs(parameterObject.copyStreamingLobs); Collection<GroupSymbol> accessedGroups = null; if (context.getDataObjects() != null) { ConnectorManager connectorManager = cmr.getConnectorManager(aqr.getConnectorName()); if (connectorManager == null) { LogManager.logDetail(LogConstants.CTX_DQP, "source", aqr.getConnectorName(), "no longer exists, returning dummy results"); //$NON-NLS-1$ //$NON-NLS-2$ return CollectionTupleSource.createNullTupleSource(); aqr.setSerial(true); cd = work.getCacheDirective(); } catch (TranslatorException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30504, e, aqr.getConnectorName() + ": " + e.getMessage()); //$NON-NLS-1$ LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "no cache directive"); //$NON-NLS-1$ LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "command not cachable"); //$NON-NLS-1$ TupleBuffer tb = null; if (cid != null) { tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR);
info.setThreadState(ThreadState.IDLE); info.setExecutionId(arm.getRequestID().getExecutionID()); info.setSessionId(holder.requestID.getConnectionID()); info.setCommand(arm.getCommand().toString()); info.setStartTime(arm.getProcessingTimestamp()); info.setSourceRequest(true); info.setNodeId(arm.getAtomicRequestID().getNodeID()); info.setState(conInfo.isCanceled()?ProcessingState.CANCELED:conInfo.isDone()?ProcessingState.DONE:ProcessingState.PROCESSING); results.add(info);
if (workItem.useCallingThread) { aqr.setSerial(true); return result; //simple case, just rely on the client using the same thread tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR); if (aqr.isSerial()) { return new TupleSource() { boolean processed = false; aqr.setSerial(true); final FutureWork<Void> future = workItem.addWork(callable, callable, 100); final TupleBuffer buffer = tb;
private AtomicRequestMessage helpSetupRequest(String sql, int nodeId, QueryMetadataInterface metadata) throws Exception { DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, vdb); Command command = helpGetCommand(sql, metadata); RequestMessage original = new RequestMessage(); original.setExecutionId(id++); original.setPartialResults(true); RequestID requestID = workContext.getRequestID(original.getExecutionId()); context = new CommandContext(); context.setSession(workContext.getSession()); context.setVdbName("test"); //$NON-NLS-1$ context.setVdbVersion(1); context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(dtm.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata)); workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, workContext); context.setWorkItem(workItem); AtomicRequestMessage request = new AtomicRequestMessage(original, workContext, nodeId); request.setCommand(command); request.setConnectorName("FakeConnectorID"); //$NON-NLS-1$ request.setCommandContext(context); return request; }
if (this.execution == null) { if (this.connection == null) { LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.requestMsg.getAtomicRequestID(), "Processing NEW request:", this.requestMsg.getCommand()}); //$NON-NLS-1$ try { this.connectionFactory = this.manager.getConnectionFactory(); Command command = this.requestMsg.getCommand(); this.expectedColumns = command.getProjectedSymbols().size(); if (command instanceof StoredProcedure) { Execution exec = this.requestMsg.getCommandContext().getReusableExecution(this.manager.getId()); if (exec != null) { ((ReusableExecution)exec).reset(translatedCommand, this.securityContext, connection); LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.requestMsg.getAtomicRequestID(), "Obtained execution"}); //$NON-NLS-1$
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException { if (waitUntil > 0 && waitUntil > System.currentTimeMillis()) { if (!this.cwi.isDataAvailable()) { throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking until", waitUntil); //$NON-NLS-1$ boolean noResults = false; try { if (futureResult != null || !aqr.isSerial()) { results = asynchGet(); } else { Command command = aqr.getCommand(); int commandIndex = 0; if (RelationalNodeUtil.isUpdate(command)) {
public DataTierTupleSource(AtomicRequestMessage aqr, RequestWorkItem workItem, ConnectorWork cwi, DataTierManagerImpl dtm, int limit) { this.aqr = aqr; this.workItem = workItem; this.cwi = cwi; this.dtm = dtm; this.limit = limit; Assertion.isNull(workItem.getConnectorRequest(aqr.getAtomicRequestID())); workItem.addConnectorRequest(aqr.getAtomicRequestID(), this); }
Object result = convertToRuntimeType(requestMsg.getBufferManager(), value, this.schema[i], this.requestMsg.getCommandContext()); if (value == result && !DataTypeManager.DefaultDataClasses.OBJECT.equals(this.schema[i])) { convertToRuntimeType[i] = false; if (isLob[i] && copyLobs) { if (lobStore == null) { lobStore = requestMsg.getBufferManager().createFileStore("lobs"); //$NON-NLS-1$ lobBuffer = new byte[1 << 14]; requestMsg.getBufferManager().persistLob((Streamable<?>) result, lobStore, lobBuffer); } else if (value == result) { convertToDesiredRuntimeType[i] = false; throw new TeiidComponentException(QueryPlugin.Event.TEIID31176, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31176, this.requestMsg.getCommand().getProjectedSymbols().get(i), DataTypeManager.getDataTypeName(this.schema[i]))); } catch (TransformationException e) { throw new TeiidException(QueryPlugin.Event.TEIID31176, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31176, this.requestMsg.getCommand().getProjectedSymbols().get(i), DataTypeManager.getDataTypeName(this.schema[i])));
@Ignore @Test public void testIsImmutablePropertySucceeds() throws Exception { /* * Setup: * 1. requestMsg.isTransactional() must be TRUE * 2. manager.isXa() must be FALSE () * 3. command must NOT be a SELECT * 4. Then, set isImmutable to TRUE, we should SUCCEED */ ConnectorManager cm = TestConnectorManager.getConnectorManager(); ((FakeConnector)cm.getExecutionFactory()).setImmutable(true); // command must not be a SELECT Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT); //$NON-NLS-1$ AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand(command); // To make the AtomicRequestMessage transactional, construct your own requestMsg.setTransactionContext( new TransactionContext(){ @Override public Xid getXid() { return Mockito.mock(Xid.class); }} ); new ConnectorWorkItem(requestMsg, cm); }
dtts.getAtomicRequestMessage().setSerial(true); while (dtts.scope != Scope.NONE) { if (item.isCanceled()) { LogManager.logDetail(LogConstants.CTX_DQP, dtts.getAtomicRequestMessage().getAtomicRequestID(), "Not using full results due to cancellation."); //$NON-NLS-1$ break; LogManager.logDetail(LogConstants.CTX_DQP, e, dtts.getAtomicRequestMessage().getAtomicRequestID(), "Not using full results due to error."); //$NON-NLS-1$ break;
ef.setCopyLobs(true); AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT)); //$NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute(); requestMsg.setCopyStreamingLobs(true); cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute();
return; //already closed LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Processing Close :", this.requestMsg.getCommand()}); //$NON-NLS-1$ try { timer.start(); LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.id, "Closed execution"}); //$NON-NLS-1$ if (execution instanceof ReusableExecution<?>) { this.requestMsg.getCommandContext().putReusableExecution(this.manager.getId(), (ReusableExecution<?>) execution);
public void testRemoveConnectorInfo() { DQPCore rm = new DQPCore(); rm.setTransactionService(new FakeTransactionService()); RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$ RequestID requestID = new RequestID(SESSION_STRING, 1); RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null); AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.getDqpWorkContext(), 1); DataTierTupleSource info = Mockito.mock(DataTierTupleSource.class); workItem.addConnectorRequest(atomicReq.getAtomicRequestID(), info); workItem.closeAtomicRequest(atomicReq.getAtomicRequestID()); DataTierTupleSource arInfo = workItem.getConnectorRequest(atomicReq.getAtomicRequestID()); assertNull(arInfo); } }
cm.start(); AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1); requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT)); //$NON-NLS-1$ requestMsg.setBufferManager(bm); ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm); cwi.execute();
@Test public void testCheckForUpdatesWithBatched() throws Exception { helpSetupDataTierManager(); QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached(); AtomicRequestMessage request = helpSetupRequest("delete from bqt1.smalla", 1, metadata); Command command = helpGetCommand("insert into bqt1.smalla (stringkey) values ('1')", metadata); BatchedUpdateCommand bac = new BatchedUpdateCommand(Arrays.asList(request.getCommand(), command)); request.setCommand(bac); DataTierTupleSource dtts = new DataTierTupleSource(request, workItem, connectorManager.registerRequest(request), dtm, limit); pullTuples(dtts, 2); }