Search in sources :

Example 6 with DatasetTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.DatasetTupleTranslator 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

DatasetTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.DatasetTupleTranslator)6 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)6 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)6 ExtensionMetadataDataset (org.apache.asterix.metadata.api.ExtensionMetadataDataset)4 Dataset (org.apache.asterix.metadata.entities.Dataset)4 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)4 ArrayList (java.util.ArrayList)3 ACIDException (org.apache.asterix.common.exceptions.ACIDException)2 IIndex (org.apache.hyracks.storage.common.IIndex)2 IMetadataIndex (org.apache.asterix.metadata.api.IMetadataIndex)1 Index (org.apache.asterix.metadata.entities.Index)1 InternalDatasetDetails (org.apache.asterix.metadata.entities.InternalDatasetDetails)1 AMutableString (org.apache.asterix.om.base.AMutableString)1 AString (org.apache.asterix.om.base.AString)1 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)1 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)1 AbstractLSMIndex (org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndex)1 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)1 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)1