use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerSimpleTest method recordsScanned.
@Test
public void recordsScanned() {
Supplier<RuntimeException> nonRetriableException = () -> new RecordCoreException("Non-retriable", new FDBException("transaction_too_large", 2101));
Supplier<RuntimeException> retriableException = () -> new RecordCoreRetriableTransactionException("Retriable", new FDBException("not_committed", 1020));
Queue<Pair<Long, Supplier<RuntimeException>>> queue = new LinkedList<>();
queue.add(Pair.of(0L, retriableException));
queue.add(Pair.of(0L, nonRetriableException));
queue.add(Pair.of(0L, null));
queue.add(Pair.of(1L, null));
queue.add(Pair.of(2L, null));
queue.add(Pair.of(3L, null));
queue.add(Pair.of(4L, retriableException));
queue.add(Pair.of(4L, retriableException));
queue.add(Pair.of(4L, nonRetriableException));
queue.add(Pair.of(4L, nonRetriableException));
queue.add(Pair.of(4L, null));
Index index = runAsyncSetup();
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(index).setSubspace(subspace).setMdcContext(ImmutableMap.of("mdcKey", "my cool mdc value")).setMaxAttempts(3).setConfigLoader(old -> OnlineIndexer.Config.newBuilder().setMaxLimit(100).setMaxRetries(queue.size() + 3).setRecordsPerSecond(10000).setIncreaseLimitAfter(10).setProgressLogIntervalMillis(30).build()).build()) {
AtomicInteger attempts = new AtomicInteger();
attempts.set(0);
AsyncUtil.whileTrue(() -> indexBuilder.buildCommitRetryAsync((store, recordsScanned) -> {
Pair<Long, Supplier<RuntimeException>> behavior = queue.poll();
if (behavior == null) {
return AsyncUtil.READY_FALSE;
} else {
int currentAttempt = attempts.getAndIncrement();
assertEquals(1, recordsScanned.incrementAndGet());
assertEquals(behavior.getLeft().longValue(), indexBuilder.getTotalRecordsScanned(), "Attempt " + currentAttempt);
if (behavior.getRight() != null) {
throw behavior.getRight().get();
}
return AsyncUtil.READY_TRUE;
}
}, Arrays.asList(LogMessageKeys.CALLING_METHOD, "OnlineIndexerTest.recordsScanned"))).join();
assertNull(queue.poll());
assertEquals(5L, indexBuilder.getTotalRecordsScanned());
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerSimpleTest method illegalConstructorParams.
@Test
public void illegalConstructorParams() {
Index newIndex = new Index("newIndex", field("num_value_2"));
openSimpleMetaData(metaDataBuilder -> metaDataBuilder.addIndex("MySimpleRecord", newIndex));
Index indexPrime = metaData.getIndex("newIndex");
// Absent index
RecordCoreException e = assertThrows(MetaDataException.class, () -> {
Index absentIndex = new Index("absent", field("num_value_2"));
OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(absentIndex).setSubspace(subspace).build();
});
assertEquals("Index absent not contained within specified metadata", e.getMessage());
// Limit
e = assertThrows(RecordCoreException.class, () -> OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexPrime).setSubspace(subspace).setLimit(-1).build());
assertEquals("Non-positive value -1 given for record limit", e.getMessage());
e = assertThrows(RecordCoreException.class, () -> OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexPrime).setSubspace(subspace).setLimit(0).build());
assertEquals("Non-positive value 0 given for record limit", e.getMessage());
// Retries
e = assertThrows(RecordCoreException.class, () -> OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexPrime).setSubspace(subspace).setMaxRetries(-1).build());
assertEquals("Non-positive value -1 given for maximum retries", e.getMessage());
e = assertThrows(RecordCoreException.class, () -> OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexPrime).setSubspace(subspace).setMaxRetries(0).build());
assertEquals("Non-positive value 0 given for maximum retries", e.getMessage());
// Records per second
e = assertThrows(RecordCoreException.class, () -> OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexPrime).setSubspace(subspace).setRecordsPerSecond(-1).build());
assertEquals("Non-positive value -1 given for records per second value", e.getMessage());
e = assertThrows(RecordCoreException.class, () -> OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexPrime).setSubspace(subspace).setRecordsPerSecond(0).build());
assertEquals("Non-positive value 0 given for records per second value", e.getMessage());
// WeakReadSemantics before runner
e = assertThrows(MetaDataException.class, () -> OnlineIndexer.newBuilder().setWeakReadSemantics(new FDBDatabase.WeakReadSemantics(Long.MAX_VALUE, 0L, true)));
assertEquals("weak read semantics can only be set after runner has been set", e.getMessage());
// priority before runner
e = assertThrows(MetaDataException.class, () -> OnlineIndexer.newBuilder().setPriority(FDBTransactionPriority.DEFAULT));
assertEquals("transaction priority can only be set after runner has been set", e.getMessage());
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerMultiTargetTest method testMultiTargetMismatchStateFailure.
@Test
public void testMultiTargetMismatchStateFailure() {
// Throw when one index has a different status
final FDBStoreTimer timer = new FDBStoreTimer();
final long numRecords = 3;
List<Index> indexes = new ArrayList<>();
// Here: Value indexes only
indexes.add(new Index("indexC", field("num_value_unique"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
indexes.add(new Index("indexD", new GroupingKeyExpression(EmptyKeyExpression.EMPTY, 0), IndexTypes.COUNT));
indexes.add(new Index("indexA", field("num_value_2"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
openSimpleMetaData();
populateData(numRecords);
FDBRecordStoreTestBase.RecordMetaDataHook hook = allIndexesHook(indexes);
openSimpleMetaData(hook);
disableAll(indexes);
// built one index
try (OnlineIndexer indexer = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(indexes.get(1)).setSubspace(subspace).build()) {
indexer.buildIndex(false);
}
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setSubspace(subspace).setTargetIndexes(indexes).setTimer(timer).build()) {
RecordCoreException e = assertThrows(RecordCoreException.class, indexBuilder::buildIndex);
assertTrue(e.getMessage().contains("A target index state doesn't match the primary index state"));
}
assertEquals(0, timer.getCount(FDBStoreTimer.Counts.ONLINE_INDEX_BUILDER_RECORDS_SCANNED));
assertEquals(0, timer.getCount(FDBStoreTimer.Counts.ONLINE_INDEX_BUILDER_RECORDS_INDEXED));
// Now finish with REBUILD
timer.reset();
openSimpleMetaData(hook);
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setSubspace(subspace).setTargetIndexes(indexes).setTimer(timer).setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder().setIfWriteOnly(OnlineIndexer.IndexingPolicy.DesiredAction.REBUILD).build()).build()) {
indexBuilder.buildIndex(true);
}
assertEquals(numRecords, timer.getCount(FDBStoreTimer.Counts.ONLINE_INDEX_BUILDER_RECORDS_SCANNED));
assertEquals(numRecords, timer.getCount(FDBStoreTimer.Counts.ONLINE_INDEX_BUILDER_RECORDS_INDEXED));
validateIndexes(indexes);
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class OnlineIndexerMultiTargetTest method testMultiTargetPartlyBuildChangeTargets.
@Test
void testMultiTargetPartlyBuildChangeTargets() {
// Throw when the index list changes
final FDBStoreTimer timer = new FDBStoreTimer();
final int numRecords = 107;
final int chunkSize = 17;
List<Index> indexes = new ArrayList<>();
indexes.add(new Index("indexD", new GroupingKeyExpression(EmptyKeyExpression.EMPTY, 0), IndexTypes.COUNT));
indexes.add(new Index("indexA", field("num_value_2"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
indexes.add(new Index("indexB", field("num_value_3_indexed"), IndexTypes.VALUE));
indexes.add(new Index("indexC", field("num_value_unique"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
openSimpleMetaData();
populateData(numRecords);
FDBRecordStoreTestBase.RecordMetaDataHook hook = allIndexesHook(indexes);
openSimpleMetaData(hook);
disableAll(indexes);
// 1. partly build multi
buildIndexAndCrashHalfway(chunkSize, 2, timer, OnlineIndexer.newBuilder().setTargetIndexes(indexes));
// 2. Change indexes set
indexes.remove(2);
// 3. assert mismatch type stamp
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setSubspace(subspace).setTargetIndexes(indexes).setTimer(timer).setLimit(chunkSize).setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder().setIfMismatchPrevious(OnlineIndexer.IndexingPolicy.DesiredAction.ERROR).build()).build()) {
RecordCoreException e = assertThrows(RecordCoreException.class, indexBuilder::buildIndex);
assertTrue(e.getMessage().contains("This index was partly built by another method"));
}
}
use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.
the class SplitHelperTest method loadWithSplit.
@MethodSource("splitAndSuffixArgs")
@ParameterizedTest(name = "deleteWithSplitAndVersion [splitLongRecords = {0}, omitUnsplitSuffix = {1}]")
public void loadWithSplit(boolean splitLongRecords, boolean omitUnsplitSuffix) throws Exception {
loadSingleRecords(splitLongRecords, omitUnsplitSuffix, (context, key, expectedSizes, expectedContents, version) -> loadWithSplit(context, key, splitLongRecords, omitUnsplitSuffix, expectedSizes, expectedContents, version));
if (splitLongRecords) {
try (FDBRecordContext context = openContext()) {
// Unsplit record followed by some unsplit stuff
// This particular error is caught by the single key unsplitter but not the mulit-key one
writeDummyRecord(context, Tuple.from(1307L), 1, false);
writeDummyRecord(context, Tuple.from(1307L), MEDIUM_COPIES, false);
RecordCoreException err = assertThrows(RecordCoreException.class, () -> loadWithSplit(context, Tuple.from(1307L), true, false, null, null));
assertThat(err.getMessage(), containsString("Unsplit value followed by split"));
commit(context);
}
}
}
Aggregations