fix size calculation

This commit is contained in:
nishantmonu51 2014-12-04 17:22:24 +05:30
parent 4dc0fdba8a
commit 269a51964e
2 changed files with 27 additions and 2 deletions

View File

@ -231,7 +231,7 @@ public class OffheapIncrementalIndex extends IncrementalIndex<BufferAggregator>
*/
public boolean isFull()
{
return (size() + 1) * totalAggSize > bufferHolder.get().limit() || getCurrentSize() > sizeLimit ;
return getCurrentSize() > sizeLimit;
}
private int getMetricPosition(int rowOffset, int metricIndex)
@ -426,6 +426,9 @@ public class OffheapIncrementalIndex extends IncrementalIndex<BufferAggregator>
private long getCurrentSize()
{
return Store.forDB(db).getCurrSize() + Store.forDB(factsDb).getCurrSize() + bufferHolder.get().limit();
return Store.forDB(db).getCurrSize() +
Store.forDB(factsDb).getCurrSize()
// Size of aggregators
+ (size() + 1) * totalAggSize;
}
}

View File

@ -208,4 +208,26 @@ public class IncrementalIndexTest
}
Assert.assertEquals(elementsPerThread, curr);
}
@Test
public void testOffheapIndexIsFull()
{
OffheapIncrementalIndex index = new OffheapIncrementalIndex(
0L,
QueryGranularity.NONE,
new AggregatorFactory[]{new CountAggregatorFactory("count")},
TestQueryRunners.pool,
true,
2 * 1024 * 1024
);
int rowCount = 0;
for (int i = 0; i < 500; i++) {
rowCount = index.add(getRow(System.currentTimeMillis(), i, 100));
if (index.isFull()) {
break;
}
}
Assert.assertTrue("rowCount : " + rowCount, rowCount > 200 && rowCount < 600);
}
}