Search in sources :

Example 1 with DO_NOT_RE_INCREASE_LIMIT

use of com.apple.foundationdb.record.provider.foundationdb.OnlineIndexer.DO_NOT_RE_INCREASE_LIMIT in project fdb-record-layer by FoundationDB.

the class OnlineIndexerSimpleTest method testConfigLoader.

@Test
public void testConfigLoader() throws Exception {
    final Index index = new Index("newIndex", field("num_value_unique"));
    final FDBRecordStoreTestBase.RecordMetaDataHook hook = metaDataBuilder -> {
        metaDataBuilder.addIndex("MySimpleRecord", index);
    };
    openSimpleMetaData(hook);
    try (FDBRecordContext context = openContext()) {
        for (int i = 0; i < 1000; i++) {
            TestRecords1Proto.MySimpleRecord record = TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(i).setNumValueUnique(i).build();
            recordStore.saveRecord(record);
        }
        recordStore.clearAndMarkIndexWriteOnly(index).join();
        context.commit();
    }
    final FDBStoreTimer timer = new FDBStoreTimer();
    final CompletableFuture<Void> future;
    try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setDatabase(fdb).setMetaData(metaData).setIndex(index).setSubspace(subspace).setConfigLoader(old -> old.toBuilder().setMaxLimit(old.getMaxLimit() - 1).setMaxRetries(3).setRecordsPerSecond(10000).build()).setMaxAttempts(2).setUseSynchronizedSession(false).setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder().setIfReadable(OnlineIndexer.IndexingPolicy.DesiredAction.ERROR).setIfWriteOnly(OnlineIndexer.IndexingPolicy.DesiredAction.CONTINUE).setIfMismatchPrevious(OnlineIndexer.IndexingPolicy.DesiredAction.ERROR).setIfReadable(OnlineIndexer.IndexingPolicy.DesiredAction.ERROR)).build()) {
        int limit = indexBuilder.getLimit();
        future = indexBuilder.buildIndexAsync();
        int pass = 0;
        while (!future.isDone() && timer.getCount(FDBStoreTimer.Events.COMMIT) < 10 && pass++ < 100) {
            Thread.sleep(100);
            assertThat("Should have invoked the configuration loader at least once", indexBuilder.getConfigLoaderInvocationCount(), greaterThan(0));
            assertEquals(indexBuilder.getLimit(), limit - indexBuilder.getConfigLoaderInvocationCount());
            assertEquals(indexBuilder.getConfig().getMaxRetries(), 3);
            assertEquals(indexBuilder.getConfig().getRecordsPerSecond(), 10000);
            assertEquals(indexBuilder.getConfig().getProgressLogIntervalMillis(), DEFAULT_PROGRESS_LOG_INTERVAL);
            assertEquals(indexBuilder.getConfig().getIncreaseLimitAfter(), DO_NOT_RE_INCREASE_LIMIT);
        }
        assertThat("Should have done several transactions in a few seconds", pass, lessThan(100));
    }
}
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) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) Index(com.apple.foundationdb.record.metadata.Index) Test(org.junit.jupiter.api.Test)

Aggregations

FDBError (com.apple.foundationdb.FDBError)1 FDBException (com.apple.foundationdb.FDBException)1 Range (com.apple.foundationdb.Range)1 AsyncIterator (com.apple.foundationdb.async.AsyncIterator)1 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)1 RangeSet (com.apple.foundationdb.async.RangeSet)1 FunctionNames (com.apple.foundationdb.record.FunctionNames)1 IsolationLevel (com.apple.foundationdb.record.IsolationLevel)1 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 RecordCoreRetriableTransactionException (com.apple.foundationdb.record.RecordCoreRetriableTransactionException)1 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)1 TupleRange (com.apple.foundationdb.record.TupleRange)1 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)1 Index (com.apple.foundationdb.record.metadata.Index)1 IndexAggregateFunction (com.apple.foundationdb.record.metadata.IndexAggregateFunction)1 IndexTypes (com.apple.foundationdb.record.metadata.IndexTypes)1 Key (com.apple.foundationdb.record.metadata.Key)1 Expressions.field (com.apple.foundationdb.record.metadata.Key.Expressions.field)1 MetaDataException (com.apple.foundationdb.record.metadata.MetaDataException)1 DEFAULT_PROGRESS_LOG_INTERVAL (com.apple.foundationdb.record.provider.foundationdb.OnlineIndexer.DEFAULT_PROGRESS_LOG_INTERVAL)1