use of org.apache.asterix.metadata.entities.Dataset 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);
}
use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.
the class MetadataManager method getDatasetIndexes.
@Override
public List<Index> getDatasetIndexes(MetadataTransactionContext ctx, String dataverseName, String datasetName) throws MetadataException {
List<Index> datasetIndexes = new ArrayList<>();
Dataset dataset = findDataset(ctx, dataverseName, datasetName);
if (dataset == null) {
return datasetIndexes;
}
if (dataset.getDatasetDetails().isTemp()) {
// for temp datsets
datasetIndexes = cache.getDatasetIndexes(dataverseName, datasetName);
} else {
try {
// for persistent datasets
datasetIndexes = metadataNode.getDatasetIndexes(ctx.getJobId(), dataverseName, datasetName);
} catch (RemoteException e) {
throw new MetadataException(e);
}
}
return datasetIndexes;
}
use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.
the class MetadataManager method addIndex.
@Override
public void addIndex(MetadataTransactionContext ctx, Index index) throws MetadataException {
String dataverseName = index.getDataverseName();
String datasetName = index.getDatasetName();
Dataset dataset = findDataset(ctx, dataverseName, datasetName);
if (dataset == null || !dataset.getDatasetDetails().isTemp()) {
try {
metadataNode.addIndex(ctx.getJobId(), index);
} catch (RemoteException e) {
throw new MetadataException(e);
}
}
ctx.addIndex(index);
}
use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.
the class MetadataManager method dropDataset.
@Override
public void dropDataset(MetadataTransactionContext ctx, String dataverseName, String datasetName) throws MetadataException {
Dataset dataset = findDataset(ctx, dataverseName, datasetName);
// If a dataset is not in the cache, then it could not be a temp dataset
if (dataset == null || !dataset.getDatasetDetails().isTemp()) {
try {
metadataNode.dropDataset(ctx.getJobId(), dataverseName, datasetName);
} catch (RemoteException e) {
throw new MetadataException(e);
}
}
// Drops the dataset from cache
ctx.dropDataset(dataverseName, datasetName);
}
use of org.apache.asterix.metadata.entities.Dataset in project asterixdb by apache.
the class MetadataManager method dropIndex.
@Override
public void dropIndex(MetadataTransactionContext ctx, String dataverseName, String datasetName, String indexName) throws MetadataException {
Dataset dataset = findDataset(ctx, dataverseName, datasetName);
// If the dataset is a temp dataset, then we do not need to call any MedataNode operations.
if (dataset == null || !dataset.getDatasetDetails().isTemp()) {
try {
metadataNode.dropIndex(ctx.getJobId(), dataverseName, datasetName, indexName);
} catch (RemoteException e) {
throw new MetadataException(e);
}
}
ctx.dropIndex(dataverseName, datasetName, indexName);
}
Aggregations