use of org.apache.hyracks.storage.am.lsm.common.impls.BlockingIOOperationCallbackWrapper in project asterixdb by apache.
the class LSMBTreeFilterMergeTestDriver method runTest.
@Override
protected void runTest(ISerializerDeserializer[] fieldSerdes, int numKeys, BTreeLeafFrameType leafType, ITupleReference lowKey, ITupleReference highKey, ITupleReference prefixLowKey, ITupleReference prefixHighKey) throws Exception {
OrderedIndexTestContext ctx = createTestContext(fieldSerdes, numKeys, leafType, true);
ctx.getIndex().create();
ctx.getIndex().activate();
// to determine which field types to generate.
if (fieldSerdes[0] instanceof IntegerSerializerDeserializer) {
orderedIndexTestUtils.bulkLoadIntTuples(ctx, numTuplesToInsert, true, getRandom());
} else if (fieldSerdes[0] instanceof UTF8StringSerializerDeserializer) {
orderedIndexTestUtils.bulkLoadStringTuples(ctx, numTuplesToInsert, true, getRandom());
}
int maxTreesToMerge = AccessMethodTestsConfig.LSM_BTREE_MAX_TREES_TO_MERGE;
ILSMIndexAccessor accessor = (ILSMIndexAccessor) ctx.getIndexAccessor();
IBinaryComparator comp = ctx.getComparatorFactories()[0].createBinaryComparator();
for (int i = 0; i < maxTreesToMerge; i++) {
int flushed = 0;
for (; flushed < i; flushed++) {
Pair<ITupleReference, ITupleReference> minMax = null;
if (fieldSerdes[0] instanceof IntegerSerializerDeserializer) {
minMax = orderedIndexTestUtils.insertIntTuples(ctx, numTuplesToInsert, true, getRandom());
} else {
minMax = orderedIndexTestUtils.insertStringTuples(ctx, numTuplesToInsert, true, getRandom());
}
if (minMax != null) {
ILSMComponentFilter f = ((LSMBTree) ctx.getIndex()).getCurrentMemoryComponent().getLSMComponentFilter();
Pair<ITupleReference, ITupleReference> obsMinMax = filterToMinMax(f);
Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getLeft(), minMax.getLeft(), comp));
Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getRight(), minMax.getRight(), comp));
}
StubIOOperationCallback stub = new StubIOOperationCallback();
BlockingIOOperationCallbackWrapper waiter = new BlockingIOOperationCallbackWrapper(stub);
accessor.scheduleFlush(waiter);
waiter.waitForIO();
if (minMax != null) {
Pair<ITupleReference, ITupleReference> obsMinMax = filterToMinMax(stub.getLastNewComponent().getLSMComponentFilter());
Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getLeft(), minMax.getLeft(), comp));
Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(obsMinMax.getRight(), minMax.getRight(), comp));
}
}
List<ILSMDiskComponent> flushedComponents = ((LSMBTree) ctx.getIndex()).getImmutableComponents();
MutablePair<ITupleReference, ITupleReference> expectedMergeMinMax = null;
for (ILSMDiskComponent f : flushedComponents) {
Pair<ITupleReference, ITupleReference> componentMinMax = filterToMinMax(f.getLSMComponentFilter());
if (expectedMergeMinMax == null) {
expectedMergeMinMax = MutablePair.of(componentMinMax.getLeft(), componentMinMax.getRight());
}
if (TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getLeft(), componentMinMax.getLeft(), comp) > 0) {
expectedMergeMinMax.setLeft(componentMinMax.getLeft());
}
if (TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getRight(), componentMinMax.getRight(), comp) < 0) {
expectedMergeMinMax.setRight(componentMinMax.getRight());
}
}
accessor.scheduleMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback(), ((LSMBTree) ctx.getIndex()).getImmutableComponents());
flushedComponents = ((LSMBTree) ctx.getIndex()).getImmutableComponents();
Pair<ITupleReference, ITupleReference> mergedMinMax = filterToMinMax(flushedComponents.get(0).getLSMComponentFilter());
Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getLeft(), mergedMinMax.getLeft(), comp));
Assert.assertEquals(0, TreeIndexTestUtils.compareFilterTuples(expectedMergeMinMax.getRight(), mergedMinMax.getRight(), comp));
orderedIndexTestUtils.checkPointSearches(ctx);
orderedIndexTestUtils.checkScan(ctx);
orderedIndexTestUtils.checkDiskOrderScan(ctx);
orderedIndexTestUtils.checkRangeSearch(ctx, lowKey, highKey, true, true);
if (prefixLowKey != null && prefixHighKey != null) {
orderedIndexTestUtils.checkRangeSearch(ctx, prefixLowKey, prefixHighKey, true, true);
}
}
ctx.getIndex().deactivate();
ctx.getIndex().destroy();
}
use of org.apache.hyracks.storage.am.lsm.common.impls.BlockingIOOperationCallbackWrapper in project asterixdb by apache.
the class ExternalBTree method deactivate.
@Override
public void deactivate(boolean flushOnExit) throws HyracksDataException {
if (!isActive) {
throw new HyracksDataException("Failed to deactivate the index since it is already deactivated.");
}
if (flushOnExit) {
BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(ioOpCallback);
cb.afterFinalize(LSMOperationType.FLUSH, null);
}
for (ILSMComponent c : diskComponents) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.deactivateCloseHandle();
bloomFilter.deactivate();
}
for (ILSMComponent c : secondDiskComponents) {
// Only deactivate non shared components (So components are not de-activated twice)
if (!diskComponents.contains(c)) {
LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
btree.deactivateCloseHandle();
bloomFilter.deactivate();
}
}
isActive = false;
}
use of org.apache.hyracks.storage.am.lsm.common.impls.BlockingIOOperationCallbackWrapper in project asterixdb by apache.
the class ExternalRTree method deactivate.
@Override
public void deactivate(boolean flushOnExit) throws HyracksDataException {
if (!isActive) {
throw new HyracksDataException("Failed to deactivate the index since it is already deactivated.");
}
if (flushOnExit) {
BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(ioOpCallback);
cb.afterFinalize(LSMOperationType.FLUSH, null);
}
for (ILSMComponent c : diskComponents) {
LSMRTreeDiskComponent component = (LSMRTreeDiskComponent) c;
RTree rtree = component.getRTree();
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
rtree.deactivateCloseHandle();
btree.deactivateCloseHandle();
bloomFilter.deactivate();
}
for (ILSMComponent c : secondDiskComponents) {
// Only deactivate non shared components
if (!diskComponents.contains(c)) {
LSMRTreeDiskComponent component = (LSMRTreeDiskComponent) c;
RTree rtree = component.getRTree();
BTree btree = component.getBTree();
BloomFilter bloomFilter = component.getBloomFilter();
rtree.deactivateCloseHandle();
btree.deactivateCloseHandle();
bloomFilter.deactivate();
}
}
isActive = false;
}
Aggregations