Search in sources :

Example 6 with ITreeIndexAccessor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor in project asterixdb by apache.

the class AbstractRTreeExamplesTest method diskOrderScan.

protected void diskOrderScan(IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes) throws Exception {
    try {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Disk-Order Scan:");
        }
        ITreeIndexAccessor treeIndexAccessor = (ITreeIndexAccessor) indexAccessor;
        TreeIndexDiskOrderScanCursor diskOrderCursor = (TreeIndexDiskOrderScanCursor) treeIndexAccessor.createDiskOrderScanCursor();
        treeIndexAccessor.diskOrderScan(diskOrderCursor);
        try {
            while (diskOrderCursor.hasNext()) {
                diskOrderCursor.next();
                ITupleReference frameTuple = diskOrderCursor.getTuple();
                String rec = TupleUtils.printTuple(frameTuple, fieldSerdes);
                if (LOGGER.isLoggable(Level.INFO)) {
                    LOGGER.info(rec);
                }
            }
        } finally {
            diskOrderCursor.close();
        }
    } catch (UnsupportedOperationException e) {
        // support disk-order scan.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    } catch (ClassCastException e) {
        // an ITreeIndexAccessor, e.g., for the LSMRTree.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    }
}
Also used : TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)

Example 7 with ITreeIndexAccessor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor in project asterixdb by apache.

the class LSMBuddyBTreeMergeCursor method open.

@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
    LSMBTreeWithBuddyCursorInitialState lsmInitialState = (LSMBTreeWithBuddyCursorInitialState) initialState;
    cmp = lsmInitialState.getBuddyBTreeCmp();
    operationalComponents = lsmInitialState.getOperationalComponents();
    // We intentionally set the lsmHarness to null so that we don't call
    // lsmHarness.endSearch() because we already do that when we merge
    // actual index.
    lsmHarness = null;
    int numBTrees = operationalComponents.size();
    rangeCursors = new IIndexCursor[numBTrees];
    RangePredicate btreePredicate = new RangePredicate(null, null, true, true, cmp, cmp);
    IIndexAccessor[] btreeAccessors = new ITreeIndexAccessor[numBTrees];
    for (int i = 0; i < numBTrees; i++) {
        ILSMComponent component = operationalComponents.get(i);
        IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getBuddyBTreeLeafFrameFactory().createFrame();
        rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
        BTree buddyBtree = ((LSMBTreeWithBuddyDiskComponent) component).getBuddyBTree();
        btreeAccessors[i] = buddyBtree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        btreeAccessors[i].search(rangeCursors[i], btreePredicate);
    }
    setPriorityQueueComparator();
    initPriorityQueue();
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor)

Example 8 with ITreeIndexAccessor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor in project asterixdb by apache.

the class TreeIndexDiskOrderScanOperatorNodePushable method initialize.

@Override
public void initialize() throws HyracksDataException {
    treeIndexHelper.open();
    ITreeIndex treeIndex = (ITreeIndex) treeIndexHelper.getIndexInstance();
    try {
        ITreeIndexFrame cursorFrame = treeIndex.getLeafFrameFactory().createFrame();
        ITreeIndexCursor cursor = new TreeIndexDiskOrderScanCursor(cursorFrame);
        LocalResource resource = treeIndexHelper.getResource();
        ISearchOperationCallback searchCallback = searchCallbackFactory.createSearchOperationCallback(resource.getId(), ctx, null);
        ITreeIndexAccessor indexAccessor = (ITreeIndexAccessor) treeIndex.createAccessor(NoOpOperationCallback.INSTANCE, searchCallback);
        try {
            writer.open();
            indexAccessor.diskOrderScan(cursor);
            int fieldCount = treeIndex.getFieldCount();
            FrameTupleAppender appender = new FrameTupleAppender(new VSizeFrame(ctx));
            ArrayTupleBuilder tb = new ArrayTupleBuilder(fieldCount);
            DataOutput dos = tb.getDataOutput();
            while (cursor.hasNext()) {
                tb.reset();
                cursor.next();
                ITupleReference frameTuple = cursor.getTuple();
                for (int i = 0; i < frameTuple.getFieldCount(); i++) {
                    dos.write(frameTuple.getFieldData(i), frameTuple.getFieldStart(i), frameTuple.getFieldLength(i));
                    tb.addFieldEndOffset();
                }
                FrameUtils.appendToWriter(writer, appender, tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize());
            }
            appender.write(writer, true);
        } catch (Throwable th) {
            writer.fail();
            throw new HyracksDataException(th);
        } finally {
            try {
                cursor.close();
            } catch (Exception cursorCloseException) {
                throw new IllegalStateException(cursorCloseException);
            } finally {
                writer.close();
            }
        }
    } catch (Throwable th) {
        treeIndexHelper.close();
        throw new HyracksDataException(th);
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) DataOutput(java.io.DataOutput) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) LocalResource(org.apache.hyracks.storage.common.LocalResource) TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) ITreeIndexFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexFrame) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ITreeIndex(org.apache.hyracks.storage.am.common.api.ITreeIndex)

Example 9 with ITreeIndexAccessor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor in project asterixdb by apache.

the class LSMRTreeDeletedKeysBTreeMergeCursor method open.

@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
    LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState;
    cmp = lsmInitialState.getBTreeCmp();
    operationalComponents = lsmInitialState.getOperationalComponents();
    // We intentionally set the lsmHarness to null so that we don't call lsmHarness.endSearch() because we already do that when we merge r-trees.
    lsmHarness = null;
    int numBTrees = operationalComponents.size();
    rangeCursors = new IIndexCursor[numBTrees];
    RangePredicate btreePredicate = new RangePredicate(null, null, true, true, cmp, cmp);
    IIndexAccessor[] btreeAccessors = new ITreeIndexAccessor[numBTrees];
    for (int i = 0; i < numBTrees; i++) {
        ILSMComponent component = operationalComponents.get(i);
        IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame();
        rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
        BTree btree = ((LSMRTreeDiskComponent) component).getBTree();
        btreeAccessors[i] = btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        btreeAccessors[i].search(rangeCursors[i], btreePredicate);
    }
    setPriorityQueueComparator();
    initPriorityQueue();
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor)

Example 10 with ITreeIndexAccessor

use of org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor in project asterixdb by apache.

the class LSMRTreeWithAntiMatterTuples method flush.

@Override
public ILSMDiskComponent flush(ILSMIOOperation operation) throws HyracksDataException {
    LSMRTreeFlushOperation flushOp = (LSMRTreeFlushOperation) operation;
    // Renaming order is critical because we use assume ordering when we
    // read the file names when we open the tree.
    // The RTree should be renamed before the BTree.
    LSMRTreeMemoryComponent flushingComponent = (LSMRTreeMemoryComponent) flushOp.getFlushingComponent();
    ITreeIndexAccessor memRTreeAccessor = flushingComponent.getRTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    RTreeSearchCursor rtreeScanCursor = (RTreeSearchCursor) memRTreeAccessor.createSearchCursor(false);
    SearchPredicate rtreeNullPredicate = new SearchPredicate(null, null);
    memRTreeAccessor.search(rtreeScanCursor, rtreeNullPredicate);
    LSMRTreeDiskComponent component = createDiskComponent(componentFactory, flushOp.getTarget(), null, null, true);
    ILSMDiskComponentBulkLoader componentBulkLoader = createComponentBulkLoader(component, 1.0f, false, 0L, false, false);
    // Since the LSM-RTree is used as a secondary assumption, the
    // primary key will be the last comparator in the BTree comparators
    TreeTupleSorter rTreeTupleSorter = new TreeTupleSorter(flushingComponent.getRTree().getFileId(), linearizerArray, rtreeLeafFrameFactory.createFrame(), rtreeLeafFrameFactory.createFrame(), flushingComponent.getRTree().getBufferCache(), comparatorFields);
    boolean isEmpty = true;
    try {
        while (rtreeScanCursor.hasNext()) {
            isEmpty = false;
            rtreeScanCursor.next();
            rTreeTupleSorter.insertTupleEntry(rtreeScanCursor.getPageId(), rtreeScanCursor.getTupleOffset());
        }
    } finally {
        rtreeScanCursor.close();
    }
    if (!isEmpty) {
        rTreeTupleSorter.sort();
    }
    // scan the memory BTree
    ITreeIndexAccessor memBTreeAccessor = flushingComponent.getBTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    BTreeRangeSearchCursor btreeScanCursor = (BTreeRangeSearchCursor) memBTreeAccessor.createSearchCursor(false);
    RangePredicate btreeNullPredicate = new RangePredicate(null, null, true, true, null, null);
    memBTreeAccessor.search(btreeScanCursor, btreeNullPredicate);
    TreeTupleSorter bTreeTupleSorter = new TreeTupleSorter(flushingComponent.getBTree().getFileId(), linearizerArray, btreeLeafFrameFactory.createFrame(), btreeLeafFrameFactory.createFrame(), flushingComponent.getBTree().getBufferCache(), comparatorFields);
    isEmpty = true;
    try {
        while (btreeScanCursor.hasNext()) {
            isEmpty = false;
            btreeScanCursor.next();
            bTreeTupleSorter.insertTupleEntry(btreeScanCursor.getPageId(), btreeScanCursor.getTupleOffset());
        }
    } finally {
        btreeScanCursor.close();
    }
    if (!isEmpty) {
        bTreeTupleSorter.sort();
    }
    LSMRTreeWithAntiMatterTuplesFlushCursor cursor = new LSMRTreeWithAntiMatterTuplesFlushCursor(rTreeTupleSorter, bTreeTupleSorter, comparatorFields, linearizerArray);
    cursor.open(null, null);
    try {
        while (cursor.hasNext()) {
            cursor.next();
            ITupleReference frameTuple = cursor.getTuple();
            componentBulkLoader.add(frameTuple);
        }
    } finally {
        cursor.close();
    }
    if (component.getLSMComponentFilter() != null) {
        List<ITupleReference> filterTuples = new ArrayList<>();
        filterTuples.add(flushingComponent.getLSMComponentFilter().getMinTuple());
        filterTuples.add(flushingComponent.getLSMComponentFilter().getMaxTuple());
        getFilterManager().updateFilter(component.getLSMComponentFilter(), filterTuples);
        getFilterManager().writeFilter(component.getLSMComponentFilter(), component.getRTree());
    }
    flushingComponent.getMetadata().copy(component.getMetadata());
    componentBulkLoader.end();
    return component;
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) ArrayList(java.util.ArrayList) ILSMDiskComponentBulkLoader(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentBulkLoader) RTreeSearchCursor(org.apache.hyracks.storage.am.rtree.impls.RTreeSearchCursor) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Aggregations

ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)16 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)9 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)8 IBTreeLeafFrame (org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame)8 BTree (org.apache.hyracks.storage.am.btree.impls.BTree)8 ArrayList (java.util.ArrayList)7 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)7 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)7 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)7 BTreeRangeSearchCursor (org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor)6 IMetadataPageManager (org.apache.hyracks.storage.am.common.api.IMetadataPageManager)6 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)6 ITreeIndexFrameFactory (org.apache.hyracks.storage.am.common.api.ITreeIndexFrameFactory)6 LinkedMetaDataPageManager (org.apache.hyracks.storage.am.common.freepage.LinkedMetaDataPageManager)6 IBufferCache (org.apache.hyracks.storage.common.buffercache.IBufferCache)6 Test (org.junit.Test)6 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)5 BTreeNSMInteriorFrameFactory (org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrameFactory)5 BTreeNSMLeafFrameFactory (org.apache.hyracks.storage.am.btree.frames.BTreeNSMLeafFrameFactory)5 AbstractBTreeTest (org.apache.hyracks.storage.am.btree.util.AbstractBTreeTest)5