/** * Inserts a metadata dataset to the physical dataset index Should be performed * on a bootstrap of a new universe * * @param mdTxnCtx * @param indexes * @throws AlgebricksException */ public static void insertMetadataDatasets(MetadataTransactionContext mdTxnCtx, IMetadataIndex[] indexes) throws AlgebricksException { for (int i = 0; i < indexes.length; i++) { IDatasetDetails id = new InternalDatasetDetails(FileStructure.BTREE, PartitioningStrategy.HASH, indexes[i].getPartitioningExpr(), indexes[i].getPartitioningExpr(), null, indexes[i].getPartitioningExprType(), false, null); MetadataManager.INSTANCE.addDataset(mdTxnCtx, new Dataset(indexes[i].getDataverseName(), indexes[i].getIndexedDatasetName(), indexes[i].getDataverseName(), indexes[i].getPayloadRecordType().getTypeName(), indexes[i].getNodeGroupName(), GlobalConfig.DEFAULT_COMPACTION_POLICY_NAME, GlobalConfig.DEFAULT_COMPACTION_POLICY_PROPERTIES, id, new HashMap<String, String>(), DatasetType.INTERNAL, indexes[i].getDatasetId().getId(), MetadataUtil.PENDING_NO_OP)); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Finished inserting initial datasets."); } }
private <T> void searchIndex(TxnId txnId, IMetadataIndex index, ITupleReference searchKey, IValueExtractor<T> valueExtractor, List<T> results) throws AlgebricksException, HyracksDataException, RemoteException { IBinaryComparatorFactory[] comparatorFactories = index.getKeyBinaryComparatorFactory(); if (index.getFile() == null) { throw new AlgebricksException("No file for Index " + index.getDataverseName() + "." + index.getIndexName()); } String resourceName = index.getFile().getRelativePath(); IIndex indexInstance = datasetLifecycleManager.get(resourceName); datasetLifecycleManager.open(resourceName); IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpIndexAccessParameters.INSTANCE); try { IBinaryComparator[] searchCmps = null; MultiComparator searchCmp = null; if (searchKey != null) { searchCmps = new IBinaryComparator[searchKey.getFieldCount()]; for (int i = 0; i < searchKey.getFieldCount(); i++) { searchCmps[i] = comparatorFactories[i].createBinaryComparator(); } searchCmp = new MultiComparator(searchCmps); } RangePredicate rangePred = new RangePredicate(searchKey, searchKey, true, true, searchCmp, searchCmp); search(indexAccessor, rangePred, results, valueExtractor, txnId); } finally { indexAccessor.destroy(); } datasetLifecycleManager.close(resourceName); }