Search in sources :

Example 71 with RecordCoreException

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());
    }
}
Also used : Arrays(java.util.Arrays) LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Tuple(com.apple.foundationdb.tuple.Tuple) Range(com.apple.foundationdb.Range) Pair(org.apache.commons.lang3.tuple.Pair) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) FDBError(com.apple.foundationdb.FDBError) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadContext(org.apache.logging.log4j.ThreadContext) DO_NOT_RE_INCREASE_LIMIT(com.apple.foundationdb.record.provider.foundationdb.OnlineIndexer.DO_NOT_RE_INCREASE_LIMIT) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) DEFAULT_PROGRESS_LOG_INTERVAL(com.apple.foundationdb.record.provider.foundationdb.OnlineIndexer.DEFAULT_PROGRESS_LOG_INTERVAL) TupleRange(com.apple.foundationdb.record.TupleRange) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Queue(java.util.Queue) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FunctionNames(com.apple.foundationdb.record.FunctionNames) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IndexAggregateFunction(com.apple.foundationdb.record.metadata.IndexAggregateFunction) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AsyncIterator(com.apple.foundationdb.async.AsyncIterator) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) RangeSet(com.apple.foundationdb.async.RangeSet) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Key(com.apple.foundationdb.record.metadata.Key) RecordCoreRetriableTransactionException(com.apple.foundationdb.record.RecordCoreRetriableTransactionException) Matchers.lessThan(org.hamcrest.Matchers.lessThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) Expressions.field(com.apple.foundationdb.record.metadata.Key.Expressions.field) Matchers.oneOf(org.hamcrest.Matchers.oneOf) IsolationLevel(com.apple.foundationdb.record.IsolationLevel) LongStream(java.util.stream.LongStream) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) ExecutionException(java.util.concurrent.ExecutionException) Index(com.apple.foundationdb.record.metadata.Index) FDBException(com.apple.foundationdb.FDBException) Collections(java.util.Collections) FDBException(com.apple.foundationdb.FDBException) Index(com.apple.foundationdb.record.metadata.Index) LinkedList(java.util.LinkedList) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecordCoreRetriableTransactionException(com.apple.foundationdb.record.RecordCoreRetriableTransactionException) Supplier(java.util.function.Supplier) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Example 72 with RecordCoreException

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());
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Index(com.apple.foundationdb.record.metadata.Index) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Test(org.junit.jupiter.api.Test)

Example 73 with RecordCoreException

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);
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) ArrayList(java.util.ArrayList) Index(com.apple.foundationdb.record.metadata.Index) Test(org.junit.jupiter.api.Test)

Example 74 with RecordCoreException

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"));
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) GroupingKeyExpression(com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression) ArrayList(java.util.ArrayList) Index(com.apple.foundationdb.record.metadata.Index) Test(org.junit.jupiter.api.Test)

Example 75 with RecordCoreException

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);
        }
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RecordCoreException (com.apple.foundationdb.record.RecordCoreException)121 Nonnull (javax.annotation.Nonnull)58 Test (org.junit.jupiter.api.Test)42 Index (com.apple.foundationdb.record.metadata.Index)37 List (java.util.List)35 Nullable (javax.annotation.Nullable)31 Tuple (com.apple.foundationdb.tuple.Tuple)29 ArrayList (java.util.ArrayList)27 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)26 CompletableFuture (java.util.concurrent.CompletableFuture)25 Collectors (java.util.stream.Collectors)24 Collections (java.util.Collections)22 GroupingKeyExpression (com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression)19 Set (java.util.Set)19 Function (java.util.function.Function)19 IndexEntry (com.apple.foundationdb.record.IndexEntry)17 TupleRange (com.apple.foundationdb.record.TupleRange)17 IndexTypes (com.apple.foundationdb.record.metadata.IndexTypes)17 RecordCursor (com.apple.foundationdb.record.RecordCursor)16 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)15