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);
}
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);
}
}
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);
}
}
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));
}
}
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;
}
Aggregations