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