[NO-ISSUE][IDX] Illegal state for primary / external array indexes.
- user model changes: no
- storage format changes: no
- interface changes: no
Now raising an illegal state exception when we encounter a primary
array index or an array index on an external dataset in the
BTree resource provider.
Change-Id: I2731e4164363040319003f1379d14df4e9030fe3
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/10924
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/ArrayBTreeResourceFactoryProvider.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/ArrayBTreeResourceFactoryProvider.java
index fc76428..7c19282 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/ArrayBTreeResourceFactoryProvider.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/ArrayBTreeResourceFactoryProvider.java
@@ -26,8 +26,6 @@
import org.apache.asterix.common.context.IStorageComponentProvider;
import org.apache.asterix.common.exceptions.CompilationException;
import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.external.indexing.FilesIndexDescription;
-import org.apache.asterix.external.indexing.IndexingConstants;
import org.apache.asterix.metadata.api.IResourceFactoryProvider;
import org.apache.asterix.metadata.entities.Dataset;
import org.apache.asterix.metadata.entities.Index;
@@ -43,8 +41,6 @@
import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
import org.apache.hyracks.api.dataflow.value.ITypeTraits;
import org.apache.hyracks.storage.am.common.api.IMetadataPageManagerFactory;
-import org.apache.hyracks.storage.am.lsm.btree.dataflow.ExternalBTreeLocalResourceFactory;
-import org.apache.hyracks.storage.am.lsm.btree.dataflow.ExternalBTreeWithBuddyLocalResourceFactory;
import org.apache.hyracks.storage.am.lsm.btree.dataflow.LSMBTreeLocalResourceFactory;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallbackFactory;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationSchedulerProvider;
@@ -72,7 +68,6 @@
IStorageComponentProvider storageComponentProvider = mdProvider.getStorageComponentProvider();
ITypeTraits[] typeTraits = getTypeTraits(mdProvider, dataset, index, recordType, metaType);
IBinaryComparatorFactory[] cmpFactories = getCmpFactories(mdProvider, dataset, index, recordType, metaType);
- int[] bloomFilterFields = getBloomFilterFields(dataset, index);
double bloomFilterFalsePositiveRate = mdProvider.getStorageProperties().getBloomFilterFalsePositiveRate();
ILSMOperationTrackerFactory opTrackerFactory = dataset.getIndexOperationTrackerFactory(index);
ILSMIOOperationCallbackFactory ioOpCallbackFactory = dataset.getIoOperationCallbackFactory(index);
@@ -82,28 +77,18 @@
storageComponentProvider.getMetadataPageManagerFactory();
ILSMIOOperationSchedulerProvider ioSchedulerProvider =
storageComponentProvider.getIoOperationSchedulerProvider();
- boolean hasBloomFilter = bloomFilterFields != null;
switch (dataset.getDatasetType()) {
case EXTERNAL:
- return index.getIndexName().equals(IndexingConstants.getFilesIndexName(dataset.getDatasetName()))
- ? new ExternalBTreeLocalResourceFactory(storageManager, typeTraits, cmpFactories,
- filterTypeTraits, filterCmpFactories, filterFields, opTrackerFactory,
- ioOpCallbackFactory, pageWriteCallbackFactory, metadataPageManagerFactory,
- ioSchedulerProvider, mergePolicyFactory, mergePolicyProperties, true, bloomFilterFields,
- bloomFilterFalsePositiveRate, false, btreeFields, hasBloomFilter)
- : new ExternalBTreeWithBuddyLocalResourceFactory(storageManager, typeTraits, cmpFactories,
- filterTypeTraits, filterCmpFactories, filterFields, opTrackerFactory,
- ioOpCallbackFactory, pageWriteCallbackFactory, metadataPageManagerFactory,
- ioSchedulerProvider, mergePolicyFactory, mergePolicyProperties, true, bloomFilterFields,
- bloomFilterFalsePositiveRate, false, btreeFields, hasBloomFilter);
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE,
+ "Array indexes are not " + "supported for external datasets.");
case INTERNAL:
AsterixVirtualBufferCacheProvider vbcProvider =
new AsterixVirtualBufferCacheProvider(dataset.getDatasetId());
final ICompressorDecompressorFactory compDecompFactory;
if (index.isPrimaryIndex()) {
- //Compress only primary index
- compDecompFactory = mdProvider.getCompressionManager().getFactory(dataset.getCompressionScheme());
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE,
+ "Array indexes cannot be " + "primary indexes.");
} else {
compDecompFactory = NoOpCompressorDecompressorFactory.INSTANCE;
}
@@ -111,9 +96,8 @@
return new LSMBTreeLocalResourceFactory(storageManager, typeTraits, cmpFactories, filterTypeTraits,
filterCmpFactories, filterFields, opTrackerFactory, ioOpCallbackFactory,
pageWriteCallbackFactory, metadataPageManagerFactory, vbcProvider, ioSchedulerProvider,
- mergePolicyFactory, mergePolicyProperties, true, bloomFilterFields,
- bloomFilterFalsePositiveRate, index.isPrimaryIndex(), btreeFields, compDecompFactory,
- hasBloomFilter);
+ mergePolicyFactory, mergePolicyProperties, true, null, bloomFilterFalsePositiveRate,
+ index.isPrimaryIndex(), btreeFields, compDecompFactory, false);
default:
throw new CompilationException(ErrorCode.COMPILATION_UNKNOWN_DATASET_TYPE,
dataset.getDatasetType().toString());
@@ -124,10 +108,11 @@
ARecordType recordType, ARecordType metaType) throws AlgebricksException {
ITypeTraits[] primaryTypeTraits = dataset.getPrimaryTypeTraits(metadataProvider, recordType, metaType);
if (index.isPrimaryIndex()) {
- return primaryTypeTraits;
- } else if (dataset.getDatasetType() == DatasetType.EXTERNAL
- && index.getIndexName().equals(IndexingConstants.getFilesIndexName(dataset.getDatasetName()))) {
- return FilesIndexDescription.EXTERNAL_FILE_INDEX_TYPE_TRAITS;
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE,
+ "Array indexes cannot be " + "primary indexes.");
+ } else if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE,
+ "Array indexes are not " + "supported for external datasets.");
}
ITypeTraitProvider typeTraitProvider = metadataProvider.getStorageComponentProvider().getTypeTraitProvider();
int numPrimaryKeys = dataset.getPrimaryKeys().size();
@@ -163,10 +148,11 @@
IBinaryComparatorFactory[] primaryCmpFactories =
dataset.getPrimaryComparatorFactories(metadataProvider, recordType, metaType);
if (index.isPrimaryIndex()) {
- return dataset.getPrimaryComparatorFactories(metadataProvider, recordType, metaType);
- } else if (dataset.getDatasetType() == DatasetType.EXTERNAL
- && index.getIndexName().equals(IndexingConstants.getFilesIndexName(dataset.getDatasetName()))) {
- return FilesIndexDescription.FILES_INDEX_COMP_FACTORIES;
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE,
+ "Array indexes cannot be " + "primary indexes.");
+ } else if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
+ throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE,
+ "Array indexes are not " + "supported for external datasets.");
}
Index.ArrayIndexDetails arrayIndexDetails = (Index.ArrayIndexDetails) index.getIndexDetails();
int numSecondaryKeys =
@@ -198,22 +184,4 @@
System.arraycopy(primaryCmpFactories, 0, secondaryCmpFactories, numSecondaryKeys, numPrimaryKeys);
return secondaryCmpFactories;
}
-
- private static int[] getBloomFilterFields(Dataset dataset, Index index) throws AlgebricksException {
- // both the Primary index and the Primary Key index have bloom filters
- if (index.isPrimaryIndex() || index.isPrimaryKeyIndex()) {
- return dataset.getPrimaryBloomFilterFields();
- }
- if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
- if (index.getIndexName().equals(IndexingConstants.getFilesIndexName(dataset.getDatasetName()))) {
- return FilesIndexDescription.BLOOM_FILTER_FIELDS;
- } else {
- Index.ArrayIndexDetails arrayIndexDetails = (Index.ArrayIndexDetails) index.getIndexDetails();
- return new int[] { arrayIndexDetails.getElementList().stream().map(e -> e.getProjectList().size())
- .reduce(0, Integer::sum) };
- }
- }
- // secondary btrees and rtrees do not have bloom filters
- return null;
- }
}