use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class DependentAccessNode method prepareNextCommand.
/**
* @see org.teiid.query.processor.relational.AccessNode#prepareNextCommand(org.teiid.query.sql.lang.Command)
*/
protected boolean prepareNextCommand(Command atomicCommand) throws TeiidComponentException, TeiidProcessingException {
Assertion.assertTrue(atomicCommand instanceof Query);
Query query = (Query) atomicCommand;
try {
if (this.criteriaProcessor == null) {
this.criteriaProcessor = new DependentCriteriaProcessor(this.maxSetSize, this.maxPredicates, this, query.getCriteria());
this.criteriaProcessor.setPushdown(pushdown);
this.criteriaProcessor.setUseBindings(useBindings);
this.criteriaProcessor.setComplexQuery(complexQuery);
}
if (this.dependentCrit == null) {
dependentCrit = criteriaProcessor.prepareCriteria();
}
query.setCriteria(dependentCrit);
} catch (BlockedException be) {
// $NON-NLS-1$
throw new AssertionError("Should not block prior to declining the sort");
// TODO: the logic could proactively decline the sort rather than throwing an exception
}
// walk up the tree and notify the parent join it is responsible for the sort
if (sort && query.getOrderBy() != null && criteriaProcessor.hasNextCommand()) {
declineSort();
}
if (!sort) {
query.setOrderBy(null);
}
boolean result = RelationalNodeUtil.shouldExecute(atomicCommand, true);
dependentCrit = null;
criteriaProcessor.consumedCriteria();
return result;
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class JoinNode method nextBatchDirectInternal.
/**
* @see org.teiid.query.processor.relational.RelationalNode#nextBatchDirect()
* @since 4.2
*/
protected TupleBatch nextBatchDirectInternal() throws BlockedException, TeiidComponentException, TeiidProcessingException {
try {
if (state == State.LOAD_LEFT) {
boolean rightDep = false;
// dependent semi joins are processed right first
if (isDependent() && (this.joinType == JoinType.JOIN_ANTI_SEMI || this.joinType == JoinType.JOIN_SEMI)) {
rightDep = true;
this.joinStrategy.openRight();
this.joinStrategy.loadRight();
TupleBuffer buffer = this.joinStrategy.rightSource.getTupleBuffer();
// the tuplebuffer may be from a lower node, so pass in the schema
dvs = new DependentValueSource(buffer, this.joinStrategy.rightSource.getSource().getElements());
dvs.setDistinct(this.joinStrategy.rightSource.isExpresssionDistinct());
this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, dvs);
}
if (this.joinType != JoinType.JOIN_FULL_OUTER || this.getJoinCriteria() == null) {
this.joinStrategy.leftSource.setImplicitBuffer(ImplicitBuffer.NONE);
}
this.joinStrategy.openLeft();
this.joinStrategy.loadLeft();
if (isDependent() && !rightDep) {
TupleBuffer buffer = this.joinStrategy.leftSource.getTupleBuffer();
// the tuplebuffer may be from a lower node, so pass in the schema
dvs = new DependentValueSource(buffer, this.joinStrategy.leftSource.getSource().getElements());
dvs.setDistinct(this.joinStrategy.leftSource.isExpresssionDistinct());
this.getContext().getVariableContext().setGlobalValue(this.dependentValueSource, dvs);
}
state = State.LOAD_RIGHT;
}
} catch (BlockedException e) {
if (!isDependent()) {
if (getJoinType() != JoinType.JOIN_FULL_OUTER && this.joinStrategy.leftSource.getSortUtility() == null && this.joinStrategy.leftSource.rowCountLE(0)) {
this.terminateBatches();
return pullBatch();
}
this.joinStrategy.openRight();
this.joinStrategy.loadRight();
prefetch(this.joinStrategy.rightSource, this.joinStrategy.leftSource);
}
throw e;
}
try {
if (state == State.LOAD_RIGHT) {
if (getJoinType() != JoinType.JOIN_FULL_OUTER && this.joinStrategy.leftSource.getSortUtility() == null && this.joinStrategy.leftSource.rowCountLE(0)) {
this.terminateBatches();
return pullBatch();
}
this.joinStrategy.openRight();
this.joinStrategy.loadRight();
state = State.EXECUTE;
}
this.joinStrategy.process();
this.terminateBatches();
} catch (BatchAvailableException e) {
// pull the batch
} catch (BlockedException e) {
// could track which side is blocking
try {
prefetch(this.joinStrategy.leftSource, this.joinStrategy.rightSource);
} catch (BlockedException e1) {
}
prefetch(this.joinStrategy.rightSource, this.joinStrategy.leftSource);
throw e;
}
return pullBatch();
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class ProjectIntoNode method nextBatchDirect.
/**
* Get batch from child node
* Walk through each row of child batch
* Bind values to insertCommand
* Execute insertCommand
* Update insertCount
* When no more data is available, output batch with single row containing insertCount
*/
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
while (phase == REQUEST_CREATION) {
/* If we don't have a batch to work, get the next
*/
if (currentBatch == null) {
if (sourceDone) {
phase = RESPONSE_PROCESSING;
break;
}
// can throw BlockedException
currentBatch = getChildren()[0].nextBatch();
sourceDone = currentBatch.getTerminationFlag();
this.batchRow = currentBatch.getBeginRow();
// and for implicit temp tables we need to issue an empty insert
if (currentBatch.getRowCount() == 0 && (!currentBatch.getTerminationFlag() || mode != Mode.ITERATOR)) {
currentBatch = null;
continue;
}
if (this.constraint != null) {
// row based security check
if (eval == null) {
eval = new Evaluator(createLookupMap(this.intoElements), this.getDataManager(), getContext());
}
List<List<?>> tuples = this.currentBatch.getTuples();
for (int i = 0; i < tuples.size(); i++) {
if (!eval.evaluate(constraint, tuples.get(i))) {
throw new QueryProcessingException(QueryPlugin.Event.TEIID31130, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31130, new Insert(intoGroup, this.intoElements, convertValuesToConstants(tuples.get(i), intoElements))));
}
}
}
}
if (mode != Mode.ITERATOR) {
// delay the check in the iterator case to accumulate batches
checkExitConditions();
}
int batchSize = currentBatch.getRowCount();
int requests = 1;
switch(mode) {
case ITERATOR:
if (buffer == null) {
buffer = getBufferManager().createTupleBuffer(intoElements, getConnectionID(), TupleSourceType.PROCESSOR);
}
if (sourceDone) {
// if there is a pending request we can't process the last until it is done
checkExitConditions();
}
for (List<?> tuple : currentBatch.getTuples()) {
buffer.addTuple(tuple);
}
try {
checkExitConditions();
} catch (BlockedException e) {
// move to the next batch
this.batchRow += batchSize;
currentBatch = null;
continue;
}
if (currentBatch.getTerminationFlag() && (buffer.getRowCount() != 0 || intoGroup.isImplicitTempGroupSymbol())) {
registerIteratorRequest();
} else if (buffer.getRowCount() >= buffer.getBatchSize() * 4) {
registerIteratorRequest();
} else {
requests = 0;
}
break;
case BATCH:
// Register batched update command against source
long endRow = currentBatch.getEndRow();
List<Command> rows = new ArrayList<Command>((int) (endRow - batchRow));
for (long rowNum = batchRow; rowNum <= endRow; rowNum++) {
Insert insert = new Insert(intoGroup, intoElements, convertValuesToConstants(currentBatch.getTuple(rowNum), intoElements));
insert.setSourceHint(sourceHint);
insert.setUpsert(upsert);
rows.add(insert);
}
registerRequest(new BatchedUpdateCommand(rows));
break;
case SINGLE:
batchSize = 1;
// Register insert command against source
// Defect 16036 - submit a new INSERT command to the DataManager.
Insert insert = new Insert(intoGroup, intoElements, convertValuesToConstants(currentBatch.getTuple(batchRow), intoElements));
insert.setSourceHint(sourceHint);
insert.setUpsert(upsert);
registerRequest(insert);
}
this.batchRow += batchSize;
if (batchRow > currentBatch.getEndRow()) {
currentBatch = null;
}
this.requestsRegistered += requests;
}
checkExitConditions();
if (this.buffer != null) {
this.buffer.remove();
this.buffer = null;
}
// End this node's work
// report only a max int
int count = (int) Math.min(Integer.MAX_VALUE, insertCount);
addBatchRow(Arrays.asList(count));
terminateBatches();
return pullBatch();
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class RelationalNode method getBuffer.
/**
* return the final tuple buffer or null if not available
* @return
* @throws TeiidProcessingException
* @throws TeiidComponentException
* @throws BlockedException
*/
public final TupleBuffer getBuffer(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
CommandContext context = this.getContext();
if (context != null && context.isCancelled()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, getContext().getRequestId()));
}
boolean recordStats = context != null && context.getCollectNodeStatistics() && !isLastBatch();
try {
// start timer for this batch
if (recordStats) {
this.getProcessingState().nodeStatistics.startBatchTimer();
}
TupleBuffer buffer = getBufferDirect(maxRows);
terminateBatches();
if (recordStats) {
// stop timer for this batch (normal)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(buffer.getRowCount(), RelationalNodeStatistics.BATCHCOMPLETE_STOP);
this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren());
if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_DQP, MessageLevel.TRACE) && !buffer.isForwardOnly()) {
for (long i = 1; i <= buffer.getRowCount(); i += buffer.getBatchSize()) {
TupleBatch tb = buffer.getBatch(i);
recordBatch(tb);
}
}
recordStats = false;
}
return buffer;
} catch (BlockedException e) {
if (recordStats) {
// stop timer for this batch (BlockedException)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
recordStats = false;
}
throw e;
} finally {
if (recordStats) {
this.getProcessingState().nodeStatistics.stopBatchTimer();
}
}
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class RelationalNode method nextBatch.
/**
* Wrapper for nextBatchDirect that does performance timing - callers
* should always call this rather than nextBatchDirect().
* @return
* @throws BlockedException
* @throws TeiidComponentException
* @since 4.2
*/
public final TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
CommandContext context = this.getContext();
if (context != null && context.isCancelled()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, getContext().getRequestId()));
}
boolean recordStats = context != null && context.getCollectNodeStatistics();
try {
while (true) {
// start timer for this batch
if (recordStats) {
this.getProcessingState().nodeStatistics.startBatchTimer();
}
TupleBatch batch = nextBatchDirect();
if (recordStats) {
// stop timer for this batch (normal)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats((long) batch.getRowCount(), RelationalNodeStatistics.BATCHCOMPLETE_STOP);
if (batch.getTerminationFlag()) {
this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren());
// this.nodeStatistics.dumpProperties(this.getClassName());
}
this.recordBatch(batch);
recordStats = false;
}
// this processing style however against the spirit of batch processing (but was already utilized by Sort and Grouping nodes)
if (batch.getRowCount() != 0 || batch.getTerminationFlag()) {
if (batch.getTerminationFlag()) {
close();
}
return batch;
}
}
} catch (BlockedException e) {
if (recordStats) {
// stop timer for this batch (BlockedException)
this.getProcessingState().nodeStatistics.stopBatchTimer();
this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
recordStats = false;
}
throw e;
} finally {
if (recordStats) {
this.getProcessingState().nodeStatistics.stopBatchTimer();
}
}
}
Aggregations