Search in sources :

Example 1 with LSMBTreeOpContext

use of org.apache.hyracks.storage.am.lsm.btree.impls.LSMBTreeOpContext in project asterixdb by apache.

the class LSMBTreeTestWorker method performOp.

@Override
public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException {
    LSMTreeIndexAccessor accessor = (LSMTreeIndexAccessor) indexAccessor;
    IIndexCursor searchCursor = accessor.createSearchCursor(false);
    LSMBTreeOpContext concreteCtx = (LSMBTreeOpContext) accessor.getCtx();
    MultiComparator cmp = concreteCtx.getCmp();
    RangePredicate rangePred = new RangePredicate(tuple, tuple, true, true, cmp, cmp);
    switch(op) {
        case INSERT:
            try {
                accessor.insert(tuple);
            } catch (HyracksDataException e) {
                if (e.getErrorCode() != ErrorCode.DUPLICATE_KEY) {
                    // Ignore duplicate keys, since we get random tuples.
                    throw e;
                }
            }
            break;
        case DELETE:
            // Create a tuple reference with only key fields.
            deleteTb.reset();
            for (int i = 0; i < numKeyFields; i++) {
                deleteTb.addField(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
            }
            deleteTuple.reset(deleteTb.getFieldEndOffsets(), deleteTb.getByteArray());
            try {
                accessor.delete(deleteTuple);
            } catch (HyracksDataException e) {
                // Ignore non-existant keys, since we get random tuples.
                if (e.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY) {
                    throw e;
                }
            }
            break;
        case UPDATE:
            try {
                accessor.update(tuple);
            } catch (HyracksDataException e) {
                if (e.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY && e.getErrorCode() != ErrorCode.INDEX_NOT_UPDATABLE) {
                    // Ignore not updateable exception due to numKeys == numFields.
                    throw e;
                }
            }
            break;
        case POINT_SEARCH:
            searchCursor.reset();
            rangePred.setLowKey(tuple, true);
            rangePred.setHighKey(tuple, true);
            accessor.search(searchCursor, rangePred);
            consumeCursorTuples(searchCursor);
            break;
        case SCAN:
            searchCursor.reset();
            rangePred.setLowKey(null, true);
            rangePred.setHighKey(null, true);
            accessor.search(searchCursor, rangePred);
            consumeCursorTuples(searchCursor);
            break;
        case MERGE:
            accessor.scheduleMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback(), lsmBTree.getImmutableComponents());
            break;
        default:
            throw new HyracksDataException("Op " + op.toString() + " not supported.");
    }
}
Also used : LSMBTreeOpContext(org.apache.hyracks.storage.am.lsm.btree.impls.LSMBTreeOpContext) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) LSMTreeIndexAccessor(org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)1 LSMBTreeOpContext (org.apache.hyracks.storage.am.lsm.btree.impls.LSMBTreeOpContext)1 LSMTreeIndexAccessor (org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor)1 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)1 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)1