|
23 | 23 | import com.apple.foundationdb.record.IndexBuildProto;
|
24 | 24 | import com.apple.foundationdb.record.RecordCoreException;
|
25 | 25 | import com.apple.foundationdb.record.TestRecords1Proto;
|
| 26 | +import com.apple.foundationdb.record.logging.KeyValueLogMessage; |
| 27 | +import com.apple.foundationdb.record.logging.LogMessageKeys; |
26 | 28 | import com.apple.foundationdb.record.metadata.Index;
|
27 | 29 | import com.apple.foundationdb.record.metadata.IndexOptions;
|
28 | 30 | import com.apple.foundationdb.record.metadata.IndexTypes;
|
|
35 | 37 | import org.junit.jupiter.api.Test;
|
36 | 38 | import org.junit.jupiter.params.ParameterizedTest;
|
37 | 39 | import org.junit.jupiter.params.provider.ValueSource;
|
| 40 | +import org.slf4j.Logger; |
| 41 | +import org.slf4j.LoggerFactory; |
38 | 42 |
|
39 | 43 | import javax.annotation.Nonnull;
|
40 | 44 | import java.util.ArrayList;
|
|
46 | 50 | import java.util.concurrent.atomic.AtomicBoolean;
|
47 | 51 | import java.util.concurrent.atomic.AtomicLong;
|
48 | 52 | import java.util.stream.Collectors;
|
| 53 | +import java.util.stream.IntStream; |
49 | 54 | import java.util.stream.LongStream;
|
50 | 55 |
|
51 | 56 | import static com.apple.foundationdb.record.metadata.Key.Expressions.field;
|
|
58 | 63 | */
|
59 | 64 | @Tag(Tags.Slow)
|
60 | 65 | class OnlineIndexerMultiTargetTest extends OnlineIndexerTest {
|
| 66 | + private static final Logger LOGGER = LoggerFactory.getLogger(OnlineIndexerMultiTargetTest.class); |
61 | 67 |
|
62 | 68 | private void populateOtherData(final long numRecords) {
|
63 | 69 | List<TestRecords1Proto.MyOtherRecord> records = LongStream.range(0, numRecords).mapToObj(val ->
|
@@ -882,14 +888,6 @@ void testMultiTargetIndexingBlockerExpiration() {
|
882 | 888 | scrubAndValidate(indexes);
|
883 | 889 | }
|
884 | 890 |
|
885 |
| - void snooze(int millis) { |
886 |
| - try { |
887 |
| - Thread.sleep(millis); |
888 |
| - } catch (InterruptedException e) { |
889 |
| - throw new RuntimeException(e); |
890 |
| - } |
891 |
| - } |
892 |
| - |
893 | 891 | @Test
|
894 | 892 | void testForbidConversionOfActiveMultiTarget() throws InterruptedException {
|
895 | 893 | // Do not let a conversion of few indexes of an active multi-target session
|
@@ -1018,4 +1016,47 @@ void testForbidConversionOfActiveMultiTargetToMutual() throws InterruptedExcepti
|
1018 | 1016 | // happy indexes assertion
|
1019 | 1017 | assertReadable(indexes);
|
1020 | 1018 | }
|
| 1019 | + |
| 1020 | + @ParameterizedTest |
| 1021 | + @BooleanSource |
| 1022 | + void testMultiTargetIgnoringSyncLock(boolean reverseScan) { |
| 1023 | + // Simply build the index |
| 1024 | + |
| 1025 | + final long numRecords = 180; |
| 1026 | + |
| 1027 | + List<Index> indexes = new ArrayList<>(); |
| 1028 | + indexes.add(new Index("indexA", field("num_value_2"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS)); |
| 1029 | + indexes.add(new Index("indexB", field("num_value_3_indexed"), IndexTypes.VALUE)); |
| 1030 | + indexes.add(new Index("indexC", field("num_value_unique"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS)); |
| 1031 | + indexes.add(new Index("indexD", new GroupingKeyExpression(EmptyKeyExpression.EMPTY, 0), IndexTypes.COUNT)); |
| 1032 | + |
| 1033 | + populateData(numRecords); |
| 1034 | + |
| 1035 | + FDBRecordStoreTestBase.RecordMetaDataHook hook = allIndexesHook(indexes); |
| 1036 | + openSimpleMetaData(hook); |
| 1037 | + disableAll(indexes); |
| 1038 | + |
| 1039 | + IntStream.rangeClosed(0, 4).parallel().forEach(id -> { |
| 1040 | + snooze(100 - id); |
| 1041 | + try { |
| 1042 | + try (OnlineIndexer indexBuilder = newIndexerBuilder(indexes) |
| 1043 | + .setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder() |
| 1044 | + .setReverseScanOrder(reverseScan)) |
| 1045 | + .setLimit(5) |
| 1046 | + .setUseSynchronizedSession(id == 0) |
| 1047 | + .setMaxRetries(100) // enough to avoid giving up |
| 1048 | + .build()) { |
| 1049 | + indexBuilder.buildIndex(true); |
| 1050 | + } |
| 1051 | + } catch (IndexingBase.UnexpectedReadableException ex) { |
| 1052 | + LOGGER.info(KeyValueLogMessage.of("Ignoring lock, got exception", |
| 1053 | + LogMessageKeys.SESSION_ID, id, |
| 1054 | + LogMessageKeys.ERROR, ex.getMessage())); |
| 1055 | + } |
| 1056 | + }); |
| 1057 | + |
| 1058 | + assertReadable(indexes); |
| 1059 | + scrubAndValidate(indexes); |
| 1060 | + } |
| 1061 | + |
1021 | 1062 | }
|
0 commit comments