Search in sources :

Example 16 with IIndexAccessor

use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.

the class FramewriterTest method mockIndexAccessors.

private IIndexAccessor[] mockIndexAccessors() throws HyracksDataException {
    IIndexCursor[] cursors = mockIndexCursors();
    IIndexAccessor[] accessors = new IIndexAccessor[cursors.length * 2];
    int j = 0;
    for (int i = 0; i < cursors.length; i++) {
        IIndexCursor cursor = cursors[i];
        IIndexAccessor accessor = Mockito.mock(IIndexAccessor.class);
        Mockito.when(accessor.createSearchCursor(Matchers.anyBoolean())).thenReturn(cursor);
        accessors[j] = accessor;
        j++;
        accessor = Mockito.mock(IIndexAccessor.class);
        Mockito.when(accessor.createSearchCursor(Matchers.anyBoolean())).thenReturn(cursor);
        Mockito.doAnswer(new Answer<Object>() {

            private int k = 0;

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                k++;
                if (k % 2 == 0) {
                    throw new HyracksDataException("Couldn't search index");
                }
                return null;
            }
        }).when(accessor).search(Matchers.any(), Matchers.any());
        accessors[j] = accessor;
        j++;
    }
    return accessors;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 17 with IIndexAccessor

use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.

the class MetadataNode method initializeDatasetIdFactory.

@Override
public void initializeDatasetIdFactory(JobId jobId) throws MetadataException, RemoteException {
    int mostRecentDatasetId = MetadataIndexImmutableProperties.FIRST_AVAILABLE_USER_DATASET_ID;
    try {
        String resourceName = MetadataPrimaryIndexes.DATASET_DATASET.getFile().getRelativePath();
        IIndex indexInstance = datasetLifecycleManager.get(resourceName);
        datasetLifecycleManager.open(resourceName);
        try {
            IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            IIndexCursor rangeCursor = indexAccessor.createSearchCursor(false);
            DatasetTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getDatasetTupleTranslator(false);
            IValueExtractor<Dataset> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
            RangePredicate rangePred = new RangePredicate(null, null, true, true, null, null);
            indexAccessor.search(rangeCursor, rangePred);
            int datasetId;
            try {
                while (rangeCursor.hasNext()) {
                    rangeCursor.next();
                    final ITupleReference ref = rangeCursor.getTuple();
                    final Dataset ds = valueExtractor.getValue(jobId, ref);
                    datasetId = ds.getDatasetId();
                    if (mostRecentDatasetId < datasetId) {
                        mostRecentDatasetId = datasetId;
                    }
                }
            } finally {
                rangeCursor.close();
            }
        } finally {
            datasetLifecycleManager.close(resourceName);
        }
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
    DatasetIdFactory.initialize(mostRecentDatasetId);
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) DatasetTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.DatasetTupleTranslator) ExtensionMetadataDataset(org.apache.asterix.metadata.api.ExtensionMetadataDataset) Dataset(org.apache.asterix.metadata.entities.Dataset) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor)

Example 18 with IIndexAccessor

use of org.apache.hyracks.storage.common.IIndexAccessor 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 19 with IIndexAccessor

use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.

the class AbstractModificationOperationCallbackTest method modificationCallbackTest.

@Test
public void modificationCallbackTest() throws Exception {
    IIndexAccessor accessor = index.createAccessor(cb, NoOpOperationCallback.INSTANCE);
    isFoundNull = true;
    for (int i = 0; i < AccessMethodTestsConfig.BTREE_NUM_TUPLES_TO_INSERT; i++) {
        TupleUtils.createIntegerTuple(builder, tuple, i);
        accessor.insert(tuple);
    }
    isFoundNull = false;
    for (int i = 0; i < AccessMethodTestsConfig.BTREE_NUM_TUPLES_TO_INSERT; i++) {
        TupleUtils.createIntegerTuple(builder, tuple, i);
        accessor.upsert(tuple);
    }
    isFoundNull = false;
    for (int i = 0; i < AccessMethodTestsConfig.BTREE_NUM_TUPLES_TO_INSERT; i++) {
        TupleUtils.createIntegerTuple(builder, tuple, i);
        accessor.delete(tuple);
    }
}
Also used : IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor) Test(org.junit.Test)

Example 20 with IIndexAccessor

use of org.apache.hyracks.storage.common.IIndexAccessor in project asterixdb by apache.

the class OrderedIndexExamplesTest method twoFixedLengthKeysOneFixedLengthValueExample.

/**
     * Composite Key Example (Non-Unique Index). Create a tree index with two
     * fixed-length key fields and one fixed-length value field. Fill index with
     * random values using insertions (not bulk load) Perform scans and range
     * search.
     */
@Test
public void twoFixedLengthKeysOneFixedLengthValueExample() throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Composite Key Test");
    }
    // Declare fields.
    int fieldCount = 3;
    ITypeTraits[] typeTraits = new ITypeTraits[fieldCount];
    typeTraits[0] = IntegerPointable.TYPE_TRAITS;
    typeTraits[1] = IntegerPointable.TYPE_TRAITS;
    typeTraits[2] = IntegerPointable.TYPE_TRAITS;
    // Declare field serdes.
    ISerializerDeserializer[] fieldSerdes = { IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE, IntegerSerializerDeserializer.INSTANCE };
    // declare keys
    int keyFieldCount = 2;
    IBinaryComparatorFactory[] cmpFactories = new IBinaryComparatorFactory[keyFieldCount];
    cmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
    cmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
    // This is only used for the LSM-BTree.
    int[] bloomFilterKeyFields = new int[keyFieldCount];
    bloomFilterKeyFields[0] = 0;
    bloomFilterKeyFields[1] = 1;
    ITreeIndex treeIndex = createTreeIndex(typeTraits, cmpFactories, bloomFilterKeyFields, null, null, null, null);
    treeIndex.create();
    treeIndex.activate();
    long start = System.currentTimeMillis();
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Inserting into tree...");
    }
    ArrayTupleBuilder tb = new ArrayTupleBuilder(fieldCount);
    ArrayTupleReference tuple = new ArrayTupleReference();
    IIndexAccessor indexAccessor = treeIndex.createAccessor(TestOperationCallback.INSTANCE, TestOperationCallback.INSTANCE);
    int numInserts = 10000;
    for (int i = 0; i < 10000; i++) {
        int f0 = rnd.nextInt() % 2000;
        int f1 = rnd.nextInt() % 1000;
        int f2 = 5;
        TupleUtils.createIntegerTuple(tb, tuple, f0, f1, f2);
        if (LOGGER.isLoggable(Level.INFO)) {
            if (i % 1000 == 0) {
                LOGGER.info("Inserting " + i + " : " + f0 + " " + f1 + " " + f2);
            }
        }
        try {
            indexAccessor.insert(tuple);
        } catch (HyracksDataException e) {
            if (e.getErrorCode() != ErrorCode.DUPLICATE_KEY) {
                throw e;
            }
        }
    }
    long end = System.currentTimeMillis();
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info(numInserts + " inserts in " + (end - start) + "ms");
    }
    orderedScan(indexAccessor, fieldSerdes);
    diskOrderScan(indexAccessor, fieldSerdes);
    // Build low key.
    ArrayTupleBuilder lowKeyTb = new ArrayTupleBuilder(1);
    ArrayTupleReference lowKey = new ArrayTupleReference();
    TupleUtils.createIntegerTuple(lowKeyTb, lowKey, -3);
    // Build high key.
    ArrayTupleBuilder highKeyTb = new ArrayTupleBuilder(1);
    ArrayTupleReference highKey = new ArrayTupleReference();
    TupleUtils.createIntegerTuple(highKeyTb, highKey, 3);
    // Prefix-Range search in [-3, 3]
    rangeSearch(cmpFactories, indexAccessor, fieldSerdes, lowKey, highKey, null, null);
    treeIndex.validate();
    treeIndex.deactivate();
    treeIndex.destroy();
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) ArrayTupleReference(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ITreeIndex(org.apache.hyracks.storage.am.common.api.ITreeIndex) Test(org.junit.Test)

Aggregations

IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)28 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)16 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)16 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)16 ITreeIndex (org.apache.hyracks.storage.am.common.api.ITreeIndex)16 Test (org.junit.Test)16 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)15 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)15 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)14 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)9 IPrimitiveValueProviderFactory (org.apache.hyracks.storage.am.common.api.IPrimitiveValueProviderFactory)7 UTF8StringSerializerDeserializer (org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer)6 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)5 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)4 ArrayList (java.util.ArrayList)3 AMutableString (org.apache.asterix.om.base.AMutableString)3 AString (org.apache.asterix.om.base.AString)3 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)3 IIndex (org.apache.hyracks.storage.common.IIndex)3 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)3