Author: shawkins
Date: 2011-10-18 12:04:46 -0400 (Tue, 18 Oct 2011)
New Revision: 3561
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
Log:
TEIID-1784 fix for sort batch accounting issue
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-10-18
16:03:32 UTC (rev 3560)
+++
branches/7.4.x/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2011-10-18
16:04:46 UTC (rev 3561)
@@ -457,6 +457,10 @@
public int getMaxProcessingKB() {
return maxProcessingKB;
}
+
+ public int getReserveBatchKB() {
+ return reserveBatchKB;
+ }
/**
* Get processor batch size
@@ -597,12 +601,17 @@
//don't wait for more than is available
int waitCount = Math.min(count, this.maxReserveKB);
while (waitCount > 0 && waitCount > this.reserveBatchKB) {
+ int reserveBatchSample = this.reserveBatchKB;
try {
- batchesFreed.await(100, TimeUnit.MILLISECONDS);
+ batchesFreed.await(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new TeiidRuntimeException(e);
}
- waitCount /= 2;
+ if (reserveBatchSample >= this.reserveBatchKB) {
+ waitCount >>= 3;
+ } else {
+ waitCount >>= 1;
+ }
}
}
if (this.reserveBatchKB >= count || mode == BufferReserveMode.FORCE) {
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2011-10-18
16:03:32 UTC (rev 3560)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2011-10-18
16:04:46 UTC (rev 3561)
@@ -230,10 +230,10 @@
if (workingTuples.size() >= maxRows) {
int reserved = bufferManager.reserveBuffers(schemaSize,
(totalReservedBuffers + schemaSize <=
bufferManager.getMaxProcessingKB())?BufferReserveMode.FORCE:BufferReserveMode.NO_WAIT);
- if (reserved != schemaSize) {
+ totalReservedBuffers += reserved;
+ if (reserved != schemaSize) {
break;
- }
- totalReservedBuffers += reserved;
+ }
maxRows += bufferManager.getProcessorBatchSize();
}
try {
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java 2011-10-18
16:03:32 UTC (rev 3560)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/relational/TestSortNode.java 2011-10-18
16:04:46 UTC (rev 3561)
@@ -37,6 +37,7 @@
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.common.buffer.TupleSource;
import org.teiid.common.buffer.BufferManager.TupleSourceType;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.DataTypeManager;
@@ -52,7 +53,8 @@
public static final int BATCH_SIZE = 100;
private void helpTestSort(List elements, List[] data, List sortElements, List
sortTypes, List[] expected, Mode mode) throws TeiidComponentException,
TeiidProcessingException {
- BufferManager mgr = BufferManagerFactory.getTestBufferManager(100, BATCH_SIZE,
BATCH_SIZE);
+ BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(4000,
BATCH_SIZE, BATCH_SIZE);
+ int reserve = mgr.getReserveBatchKB();
CommandContext context = new CommandContext ("pid", "test",
null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
BlockingFakeRelationalNode dataNode = new BlockingFakeRelationalNode(2, data);
@@ -87,6 +89,7 @@
}
}
assertEquals(expected.length, currentRow - 1);
+ assertEquals(reserve, mgr.getReserveBatchKB());
}
/*