Search in sources :

Example 6 with IIndex

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

the class AbstractInvertedIndexDeleteTest method runTest.

protected void runTest(LSMInvertedIndexTestContext testCtx, TupleGenerator tupleGen) throws IOException {
    IIndex invIndex = testCtx.getIndex();
    if ((invIndexType != InvertedIndexType.LSM) && (invIndexType != InvertedIndexType.PARTITIONED_LSM) || !bulkLoad) {
        invIndex.create();
        invIndex.activate();
    }
    for (int i = 0; i < numInsertRounds; i++) {
        // Start generating documents ids from 0 again.
        tupleGen.reset();
        if (bulkLoad) {
            if ((invIndexType != InvertedIndexType.LSM) && (invIndexType != InvertedIndexType.PARTITIONED_LSM)) {
                LSMInvertedIndexTestUtils.bulkLoadInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT, false);
            } else {
                LSMInvertedIndexTestUtils.bulkLoadInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT, true);
            }
        } else {
            LSMInvertedIndexTestUtils.insertIntoInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT);
        }
        // Delete all documents in a couple of rounds.
        int numTuplesPerDeleteRound = (int) Math.ceil((float) testCtx.getDocumentCorpus().size() / (float) numDeleteRounds);
        for (int j = 0; j < numDeleteRounds; j++) {
            LSMInvertedIndexTestUtils.deleteFromInvIndex(testCtx, harness.getRandom(), numTuplesPerDeleteRound);
            validateAndCheckIndex(testCtx);
            runTinySearchWorkload(testCtx, tupleGen);
        }
    }
    invIndex.deactivate();
    invIndex.destroy();
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex)

Example 7 with IIndex

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

the class AbstractInvertedIndexLoadTest method runTest.

protected void runTest(LSMInvertedIndexTestContext testCtx, TupleGenerator tupleGen) throws IOException {
    IIndex invIndex = testCtx.getIndex();
    invIndex.create();
    invIndex.activate();
    if (bulkLoad) {
        LSMInvertedIndexTestUtils.bulkLoadInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT, true);
    } else {
        LSMInvertedIndexTestUtils.insertIntoInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT);
    }
    validateAndCheckIndex(testCtx);
    runTinySearchWorkload(testCtx, tupleGen);
    invIndex.deactivate();
    invIndex.destroy();
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex)

Example 8 with IIndex

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

the class RecoveryManager method getLocalMinFirstLSN.

@Override
public long getLocalMinFirstLSN() throws HyracksDataException {
    IDatasetLifecycleManager datasetLifecycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    List<IIndex> openIndexList = datasetLifecycleManager.getOpenResources();
    long firstLSN;
    //the min first lsn can only be the current append or smaller
    long minFirstLSN = logMgr.getAppendLSN();
    if (!openIndexList.isEmpty()) {
        for (IIndex index : openIndexList) {
            AbstractLSMIOOperationCallback ioCallback = (AbstractLSMIOOperationCallback) ((ILSMIndex) index).getIOOperationCallback();
            if (!((AbstractLSMIndex) index).isCurrentMutableComponentEmpty() || ioCallback.hasPendingFlush()) {
                firstLSN = ioCallback.getFirstLSN();
                minFirstLSN = Math.min(minFirstLSN, firstLSN);
            }
        }
    }
    return minFirstLSN;
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) IIndex(org.apache.hyracks.storage.common.IIndex) AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback) AbstractLSMIndex(org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndex)

Example 9 with IIndex

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

the class IndexBuilder method build.

@Override
public void build() throws HyracksDataException {
    IResourceLifecycleManager<IIndex> lcManager = storageManager.getLifecycleManager(ctx);
    synchronized (lcManager) {
        // The previous resource Id needs to be removed since calling IIndex.create() may possibly destroy any
        // physical artifact that the LocalResourceRepository is managing (e.g. a file containing the resource Id).
        // Once the index has been created, a new resource Id can be generated.
        ILocalResourceRepository localResourceRepository = storageManager.getLocalResourceRepository(ctx);
        LocalResource lr = localResourceRepository.get(resourceRef.getRelativePath());
        long resourceId = lr == null ? -1 : lr.getId();
        if (resourceId != -1) {
            localResourceRepository.delete(resourceRef.getRelativePath());
        }
        resourceId = resourceIdFactory.createId();
        IResource resource = localResourceFactory.createResource(resourceRef);
        lr = new LocalResource(resourceId, ITreeIndexFrame.Constants.VERSION, durable, resource);
        IIndex index = lcManager.get(resourceRef.getRelativePath());
        if (index != null) {
            //how is this right?????????? <needs to be fixed>
            //The reason for this is to handle many cases such as:
            //1. Crash while delete index is running (we don't do global cleanup on restart)
            //2. Node leaves and then join with old data
            lcManager.unregister(resourceRef.getRelativePath());
        } else {
            index = resource.createInstance(ctx);
        }
        index.create();
        try {
            localResourceRepository.insert(lr);
        } catch (IOException e) {
            throw HyracksDataException.create(e);
        }
        lcManager.register(resourceRef.getRelativePath(), index);
    }
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) IOException(java.io.IOException) ILocalResourceRepository(org.apache.hyracks.storage.common.ILocalResourceRepository) IResource(org.apache.hyracks.storage.common.IResource) LocalResource(org.apache.hyracks.storage.common.LocalResource)

Example 10 with IIndex

use of org.apache.hyracks.storage.common.IIndex 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)

Aggregations

IIndex (org.apache.hyracks.storage.common.IIndex)17 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)5 ACIDException (org.apache.asterix.common.exceptions.ACIDException)3 AMutableString (org.apache.asterix.om.base.AMutableString)3 AString (org.apache.asterix.om.base.AString)3 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)3 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)3 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)2 DatasetId (org.apache.asterix.common.transactions.DatasetId)2 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)2 ITransactionSubsystem (org.apache.asterix.common.transactions.ITransactionSubsystem)2 ExternalFile (org.apache.asterix.external.indexing.ExternalFile)2 FileIndexTupleTranslator (org.apache.asterix.external.indexing.FileIndexTupleTranslator)2 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)2 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)2 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)2 AbstractOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractOperatorNodePushable)2 IIndexDataflowHelper (org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper)2 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)2 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)2