use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class GeophileSpatialJoin method recordCursor.
@Nonnull
public RecordCursor<IndexEntry> recordCursor(@Nonnull SpatialObject spatialObject, @Nonnull SpatialIndex<GeophileRecordImpl> spatialIndex) {
// TODO: This is a synchronous implementation using Iterators. A proper RecordCursor implementation needs
// Geophile async extensions. Also need to pass down executeProperties.
final Iterator<GeophileRecordImpl> iterator;
try {
iterator = spatialJoin.iterator(spatialObject, spatialIndex);
} catch (IOException ex) {
throw new RecordCoreException("Unexpected IO exception", ex);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RecordCoreException(ex);
}
final RecordCursor<GeophileRecordImpl> recordCursor = RecordCursor.fromIterator(store.getExecutor(), iterator);
return recordCursor.map(GeophileRecordImpl::getIndexEntry);
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class GeophileSpatialObjectQueryPlan method executeEntries.
@Nonnull
@Override
public <M extends Message> RecordCursor<IndexEntry> executeEntries(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
if (continuation != null) {
throw new RecordCoreException("continuations are not yet supported");
}
final SpatialObject spatialObject = getSpatialObject(context);
if (spatialObject == null) {
return RecordCursor.empty();
}
final SpatialJoin spatialJoin = SpatialJoin.newSpatialJoin(SpatialJoin.Duplicates.INCLUDE, getFilter(context));
final GeophileSpatialJoin geophileSpatialJoin = new GeophileSpatialJoin(spatialJoin, store.getUntypedRecordStore(), context);
final SpatialIndex<GeophileRecordImpl> spatialIndex = geophileSpatialJoin.getSpatialIndex(indexName, prefixComparisons, getRecordFunction());
return geophileSpatialJoin.recordCursor(spatialObject, spatialIndex);
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreOpeningTest method storeExistenceChecksWithNoRecords.
@Test
public void storeExistenceChecksWithNoRecords() throws Exception {
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
FDBRecordStore.Builder storeBuilder;
try (FDBRecordContext context = openContext()) {
storeBuilder = storeBuilder(context, metaData);
FDBRecordStore store = storeBuilder.create();
// delete the header
store.ensureContextActive().clear(getStoreInfoKey(store));
commit(context);
}
// Should be able to recover from a completely empty record store
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context);
FDBRecordStore store = storeBuilder.createOrOpen();
// put a range subspace in for an index so that a future store opening can see it
store.ensureContextActive().clear(getStoreInfoKey(store));
Index foundIndex = metaData.getAllIndexes().stream().findAny().orElseGet(() -> fail("no indexes defined in meta-data"));
new RangeSet(store.indexRangeSubspace(foundIndex)).insertRange(context.ensureActive(), null, null).get();
// re-delete the header
store.ensureContextActive().clear(getStoreInfoKey(store));
commit(context);
}
// should be recoverable using ERROR_IF_NO_INFO_AND_HAS_RECORDS_OR_INDEXES
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context);
assertThrows(RecordStoreNoInfoAndNotEmptyException.class, storeBuilder::createOrOpen);
commit(context);
}
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context);
// do not perform checkVersion yet
FDBRecordStore store = storeBuilder.build();
assertNull(context.ensureActive().get(getStoreInfoKey(store)).get());
assertTrue(store.checkVersion(null, FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NO_INFO_AND_HAS_RECORDS_OR_INDEXES).get());
commit(context);
}
// Delete everything except a value in the index build space
try (FDBRecordContext context = openContext()) {
FDBRecordStore store = storeBuilder.setContext(context).open();
final Subspace subspace = OnlineIndexer.indexBuildScannedRecordsSubspace(store, metaData.getIndex("MySimpleRecord$str_value_indexed"));
// set a key in the INDEX_BUILD_SPACE
context.ensureActive().set(subspace.getKey(), FDBRecordStore.encodeRecordCount(1215));
context.ensureActive().clear(store.getSubspace().getKey(), subspace.getKey());
commit(context);
}
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context);
assertThrows(RecordStoreNoInfoAndNotEmptyException.class, storeBuilder::createOrOpen);
}
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context).createOrOpen(FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NO_INFO_AND_HAS_RECORDS_OR_INDEXES);
commit(context);
}
// Insert a record, then delete the store header
try (FDBRecordContext context = openContext()) {
// open as the previous open with the relaxed existence check should have fixed the store header
FDBRecordStore store = storeBuilder.setContext(context).open();
store.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1066L).build());
store.ensureContextActive().clear(getStoreInfoKey(store));
commit(context);
}
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context);
assertThrows(RecordStoreNoInfoAndNotEmptyException.class, storeBuilder::createOrOpen);
assertThrows(RecordStoreNoInfoAndNotEmptyException.class, () -> storeBuilder.createOrOpen(FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NO_INFO_AND_HAS_RECORDS_OR_INDEXES));
commit(context);
}
// Delete the record store, then insert a key at an unknown keyspace
try (FDBRecordContext context = openContext()) {
FDBRecordStore.deleteStore(context, path);
Subspace subspace = path.toSubspace(context);
context.ensureActive().set(subspace.pack("unknown_keyspace"), Tuple.from("doesn't matter").pack());
commit(context);
}
try (FDBRecordContext context = openContext()) {
storeBuilder.setContext(context);
assertThrows(RecordStoreNoInfoAndNotEmptyException.class, storeBuilder::createOrOpen);
RecordCoreException err = assertThrows(RecordCoreException.class, () -> storeBuilder.createOrOpen(FDBRecordStoreBase.StoreExistenceCheck.ERROR_IF_NO_INFO_AND_HAS_RECORDS_OR_INDEXES));
assertEquals("Unrecognized keyspace: unknown_keyspace", err.getMessage());
commit(context);
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerSimpleTest method lessenLimits.
@Test
public void lessenLimits() {
Index index = runAsyncSetup();
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(index).setSubspace(subspace).setLimit(100).setMaxRetries(30).setRecordsPerSecond(10000).setMdcContext(ImmutableMap.of("mdcKey", "my cool mdc value")).setMaxAttempts(3).build()) {
AtomicInteger attempts = new AtomicInteger();
AtomicInteger limit = new AtomicInteger(100);
// Non-retriable error that is in lessen work codes.
attempts.set(0);
indexBuilder.buildCommitRetryAsync((store, recordsScanned) -> {
assertEquals(attempts.getAndIncrement(), indexBuilder.getLimit(), limit.getAndUpdate(x -> Math.max(x, (3 * x) / 4)));
throw new RecordCoreException("Non-retriable", new FDBException("transaction_too_large", 2101));
}, null).handle((val, e) -> {
assertNotNull(e);
assertThat(e, instanceOf(RecordCoreException.class));
assertEquals("Non-retriable", e.getMessage());
return null;
}).join();
assertEquals(31, attempts.get());
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerIndexFromIndexTest method buildIndexAndCrashHalfway.
private void buildIndexAndCrashHalfway(Index tgtIndex, int chunkSize, int count, FDBStoreTimer timer, @Nullable OnlineIndexer.IndexingPolicy policy) {
final AtomicLong counter = new AtomicLong(0);
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).addTargetIndex(tgtIndex).setSubspace(subspace).setIndexingPolicy(policy).setLimit(chunkSize).setTimer(timer).setConfigLoader(old -> {
if (counter.incrementAndGet() > count) {
throw new RecordCoreException("Intentionally crash during test");
}
return old;
}).build()) {
assertThrows(RecordCoreException.class, indexBuilder::buildIndex);
// The index should be partially built
}
// by-records performs an extra range while building endpoints
final int expected = policy == null ? count + 1 : count;
assertEquals(expected, timer.getCount(FDBStoreTimer.Counts.ONLINE_INDEX_BUILDER_RANGES_BY_COUNT));
}
Aggregations