Search in sources :

Example 6 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class TextIndexTest method queryComplexDocumentsWithIndex.

@Nonnull
private List<Tuple> queryComplexDocumentsWithIndex(@Nonnull QueryComponent textFilter, @Nullable QueryComponent additionalFilter, boolean skipFilterCheck, long group, int planHash) throws InterruptedException, ExecutionException {
    if (!(textFilter instanceof ComponentWithComparison)) {
        throw new RecordCoreArgumentException("filter without comparison provided as text filter");
    }
    final Matcher<RecordQueryPlan> textScanMatcher = textIndexScan(allOf(indexName(COMPLEX_TEXT_BY_GROUP.getName()), groupingBounds(allOf(notNullValue(), hasTupleString("[[" + group + "],[" + group + "]]"))), textComparison(equalTo(((ComponentWithComparison) textFilter).getComparison()))));
    // Don't care whether it's covering or not
    final Matcher<RecordQueryPlan> textPlanMatcher = anyOf(textScanMatcher, coveringIndexScan(textScanMatcher));
    final Matcher<RecordQueryPlan> planMatcher;
    final QueryComponent filter;
    if (additionalFilter != null) {
        if (skipFilterCheck) {
            planMatcher = descendant(textPlanMatcher);
        } else {
            planMatcher = descendant(filter(additionalFilter, descendant(textPlanMatcher)));
        }
        filter = Query.and(textFilter, additionalFilter, Query.field("group").equalsValue(group));
    } else {
        planMatcher = descendant(textPlanMatcher);
        filter = Query.and(textFilter, Query.field("group").equalsValue(group));
    }
    return queryComplexDocumentsWithPlan(filter, planHash, planMatcher);
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) ComponentWithComparison(com.apple.foundationdb.record.query.expressions.ComponentWithComparison) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Example 7 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class GeophileSpatialJoin method getSpatialIndex.

@Nonnull
public SpatialIndex<GeophileRecordImpl> getSpatialIndex(@Nonnull String indexName, @Nonnull ScanComparisons prefixComparisons, @Nonnull BiFunction<IndexEntry, Tuple, GeophileRecordImpl> recordFunction) {
    if (!prefixComparisons.isEquality()) {
        throw new RecordCoreArgumentException("prefix comparisons must only have equality");
    }
    // TODO: Add a FDBRecordStoreBase.getIndexMaintainer String overload to do this.
    final IndexMaintainer indexMaintainer = store.getIndexMaintainer(store.getRecordMetaData().getIndex(indexName));
    final TupleRange prefixRange = prefixComparisons.toTupleRange(store, context);
    // Since this is an equality, will match getHigh(), too.
    final Tuple prefix = prefixRange.getLow();
    final Index<GeophileRecordImpl> index = new GeophileIndexImpl(indexMaintainer, prefix, recordFunction);
    final Space space = ((GeophileIndexMaintainer) indexMaintainer).getSpace();
    try {
        return SpatialIndex.newSpatialIndex(space, index);
    } catch (IOException ex) {
        throw new RecordCoreException("Unexpected IO exception", ex);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new RecordCoreException(ex);
    }
}
Also used : Space(com.geophile.z.Space) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) IndexMaintainer(com.apple.foundationdb.record.provider.foundationdb.IndexMaintainer) TupleRange(com.apple.foundationdb.record.TupleRange) IOException(java.io.IOException) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Tuple(com.apple.foundationdb.tuple.Tuple) Nonnull(javax.annotation.Nonnull)

Example 8 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreStateCacheTest method useWithDifferentDatabase.

@ParameterizedTest(name = "useWithDifferentDatabase (factory = {0})")
@MethodSource("factorySource")
public void useWithDifferentDatabase(FDBRecordStoreStateCacheFactory storeStateCacheFactory) throws Exception {
    FDBRecordStoreStateCacheFactory currentCacheFactory = FDBDatabaseFactory.instance().getStoreStateCacheFactory();
    try {
        String clusterFile = FDBTestBase.createFakeClusterFile("record_store_cache_");
        FDBDatabaseFactory.instance().setStoreStateCacheFactory(readVersionCacheFactory);
        FDBDatabase secondDatabase = FDBDatabaseFactory.instance().getDatabase(clusterFile);
        // Using the cache with a context from the wrong database shouldn't work
        try (FDBRecordContext context = openContext()) {
            openSimpleRecordStore(context);
            RecordCoreArgumentException ex = assertThrows(RecordCoreArgumentException.class, () -> secondDatabase.getStoreStateCache().get(recordStore, FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NO_INFO_AND_NOT_EMPTY));
            assertThat(ex.getMessage(), containsString("record store state cache used with different database"));
        }
        // Setting the database's cache to a record store of the wrong database shouldn't work
        FDBRecordStoreStateCache originalCache = fdb.getStoreStateCache();
        RecordCoreArgumentException ex = assertThrows(RecordCoreArgumentException.class, () -> fdb.setStoreStateCache(secondDatabase.getStoreStateCache()));
        assertThat(ex.getMessage(), containsString("record store state cache used with different database"));
        assertSame(originalCache, fdb.getStoreStateCache());
    } finally {
        FDBDatabaseFactory.instance().setStoreStateCacheFactory(currentCacheFactory);
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Matchers.containsString(org.hamcrest.Matchers.containsString) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class FDBDirectory method readBlock.

/**
 * Reads known data from the directory.
 * @param resourceDescription Description should be non-null, opaque string describing this resource; used for logging
 * @param referenceFuture the reference where the data supposedly lives
 * @param block the block where the data is stored
 * @return Completable future of the data returned
 * @throws RecordCoreException if blockCache fails to get the data from the block
 * @throws RecordCoreArgumentException if a reference with that id hasn't been written yet.
 */
// checks and throws more relevant exception
@SuppressWarnings("PMD.UnusedNullCheckInEquals")
@Nonnull
public CompletableFuture<byte[]> readBlock(@Nonnull String resourceDescription, @Nonnull CompletableFuture<FDBLuceneFileReference> referenceFuture, int block) throws RecordCoreException {
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace(getLogMessage("readBlock", LogMessageKeys.FILE_NAME, resourceDescription, LogMessageKeys.BLOCK_NUMBER, block));
        }
        // Tried to fully pipeline this but the reality is that this is mostly cached after listAll, delete, etc.
        final FDBLuceneFileReference reference = referenceFuture.join();
        if (reference == null) {
            throw new RecordCoreArgumentException(String.format("No reference with name %s was found", resourceDescription));
        }
        Long id = reference.getId();
        long start = System.nanoTime();
        return context.instrument(FDBStoreTimer.Events.LUCENE_READ_BLOCK, blockCache.get(Pair.of(id, block), () -> context.instrument(FDBStoreTimer.Events.LUCENE_FDB_READ_BLOCK, context.ensureActive().get(dataSubspace.pack(Tuple.from(id, block))).thenApplyAsync(data -> LuceneSerializer.decode(data)))), start);
    } catch (ExecutionException e) {
        throw new RecordCoreException(CompletionExceptionLogHelper.asCause(e));
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) LoggerFactory(org.slf4j.LoggerFactory) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Subspace(com.apple.foundationdb.subspace.Subspace) ArrayList(java.util.ArrayList) Tuple(com.apple.foundationdb.tuple.Tuple) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Lock(org.apache.lucene.store.Lock) Pair(org.apache.commons.lang3.tuple.Pair) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Directory(org.apache.lucene.store.Directory) IOContext(org.apache.lucene.store.IOContext) Nonnull(javax.annotation.Nonnull) IndexOutput(org.apache.lucene.store.IndexOutput) Nullable(javax.annotation.Nullable) Verify(com.google.common.base.Verify) Logger(org.slf4j.Logger) KeyValue(com.apple.foundationdb.KeyValue) IndexInput(org.apache.lucene.store.IndexInput) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Collection(java.util.Collection) IndexFileNames(org.apache.lucene.index.IndexFileNames) Set(java.util.Set) IOException(java.io.IOException) ENTRIES_EXTENSION(com.apple.foundationdb.record.lucene.codec.LuceneOptimizedCompoundFormat.ENTRIES_EXTENSION) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CompletionExceptionLogHelper(com.apple.foundationdb.record.logging.CompletionExceptionLogHelper) NoLockFactory(org.apache.lucene.store.NoLockFactory) LockFactory(org.apache.lucene.store.LockFactory) DATA_EXTENSION(com.apple.foundationdb.record.lucene.codec.LuceneOptimizedCompoundFormat.DATA_EXTENSION) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) API(com.apple.foundationdb.annotation.API) LuceneRecordContextProperties(com.apple.foundationdb.record.lucene.LuceneRecordContextProperties) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) SI_EXTENSION(org.apache.lucene.codecs.lucene70.Lucene70SegmentInfoFormat.SI_EXTENSION) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) ExecutionException(java.util.concurrent.ExecutionException) Nonnull(javax.annotation.Nonnull)

Example 10 with RecordCoreArgumentException

use of com.apple.foundationdb.record.RecordCoreArgumentException in project fdb-record-layer by FoundationDB.

the class LuceneIndexMaintainer method insertField.

/**
 * Insert a field into the document and add a suggestion into the suggester if needed.
 * @return whether a suggestion has been added to the suggester
 */
private boolean insertField(LuceneDocumentFromRecord.DocumentField field, final Document document, @Nullable AnalyzingInfixSuggester suggester, @Nullable Tuple groupingKey) {
    String fieldName = field.getFieldName();
    Object value = field.getValue();
    Field luceneField;
    boolean suggestionAdded = false;
    switch(field.getType()) {
        case TEXT:
            luceneField = new TextField(fieldName, (String) value, field.isStored() ? Field.Store.YES : Field.Store.NO);
            suggestionAdded = addTermToSuggesterIfNeeded((String) value, fieldName, suggester, groupingKey);
            break;
        case STRING:
            luceneField = new StringField(fieldName, (String) value, field.isStored() ? Field.Store.YES : Field.Store.NO);
            break;
        case INT:
            luceneField = new IntPoint(fieldName, (Integer) value);
            break;
        case LONG:
            luceneField = new LongPoint(fieldName, (Long) value);
            break;
        case DOUBLE:
            luceneField = new DoublePoint(fieldName, (Double) value);
            break;
        case BOOLEAN:
            luceneField = new StringField(fieldName, ((Boolean) value).toString(), field.isStored() ? Field.Store.YES : Field.Store.NO);
            break;
        default:
            throw new RecordCoreArgumentException("Invalid type for lucene index field", "type", field.getType());
    }
    document.add(luceneField);
    return suggestionAdded;
}
Also used : LongPoint(org.apache.lucene.document.LongPoint) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) StoredField(org.apache.lucene.document.StoredField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) IntPoint(org.apache.lucene.document.IntPoint) StringField(org.apache.lucene.document.StringField) DoublePoint(org.apache.lucene.document.DoublePoint) TextField(org.apache.lucene.document.TextField)

Aggregations

RecordCoreArgumentException (com.apple.foundationdb.record.RecordCoreArgumentException)17 Nonnull (javax.annotation.Nonnull)11 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)4 ComponentWithComparison (com.apple.foundationdb.record.query.expressions.ComponentWithComparison)3 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)3 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)3 Tuple (com.apple.foundationdb.tuple.Tuple)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordCursor (com.apple.foundationdb.record.RecordCursor)2 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)2 Subspace (com.apple.foundationdb.subspace.Subspace)2 KeyValue (com.apple.foundationdb.KeyValue)1 ReadTransaction (com.apple.foundationdb.ReadTransaction)1 Transaction (com.apple.foundationdb.Transaction)1 API (com.apple.foundationdb.annotation.API)1 EndpointType (com.apple.foundationdb.record.EndpointType)1 KeyRange (com.apple.foundationdb.record.KeyRange)1 TupleRange (com.apple.foundationdb.record.TupleRange)1 CompletionExceptionLogHelper (com.apple.foundationdb.record.logging.CompletionExceptionLogHelper)1