Skip to content

Commit

Permalink
TEIID-2728 ensuring desired space calculation doesn't overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Nov 7, 2013
1 parent 4f1a16e commit 9f4d562
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected void initialSort(boolean onePass) throws TeiidComponentException, Teii
*/
this.workingBuffer.close();
schemaSize = Math.max(1, this.workingBuffer.getRowSizeEstimate()*this.batchSize);
long memorySpaceNeeded = workingBuffer.getRowCount()*this.workingBuffer.getRowSizeEstimate();
long memorySpaceNeeded = workingBuffer.getRowCount()*(long)this.workingBuffer.getRowSizeEstimate();
if (onePass) {
//one pass just needs small sub-lists
memorySpaceNeeded = Math.min(memorySpaceNeeded, bufferManager.getMaxProcessingSize());
Expand Down Expand Up @@ -396,10 +396,16 @@ protected void mergePhase() throws TeiidComponentException, TeiidProcessingExcep
if (twoPass < activeTupleBuffers.size()) {
//wait for 2-pass
int needed = (int)Math.ceil(Math.pow(activeTupleBuffers.size(), .5));
while (activeTupleBuffers.size()/needed + activeTupleBuffers.size()%needed > needed) {
needed++;
}
reserved += bufferManager.reserveBuffersBlocking(needed * schemaSize - toForce, attempts, false);
if (reserved == 0 && twoPass*subLists < activeTupleBuffers.size()) {
//force 3-pass
needed = (int)Math.ceil(Math.pow(activeTupleBuffers.size(), 1/3d));
while (activeTupleBuffers.size()/(needed*needed) + activeTupleBuffers.size()%needed > needed) {
needed++;
}
reserved += bufferManager.reserveBuffersBlocking(needed * schemaSize - toForce, attempts, true);
}
} else if (desiredSpace < Integer.MAX_VALUE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ public Object clone() {
helpTestLargeSort(4, 1, 100000);
}

//tests a sort where the desired space is above 2 GB
@Test public void runWideSort_1_500000() throws Exception {
helpTestLargeSort(1, 1, 500000);
}

@Test public void runWideSort_4_100000() throws Exception {
helpTestLargeSort(2, 4, 100000);
}
Expand Down

0 comments on commit 9f4d562

Please sign in to comment.