Skip to content

Commit 92ebe52

Browse files
committed
Randomize compression and encryption in LuceneIndexMaintenanceTest
1 parent 6d948b8 commit 92ebe52

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/properties/RecordLayerPropertyStorage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ private Builder(ImmutableMap<RecordLayerPropertyKey<?>, RecordLayerPropertyValue
9696
this.propertyMap = new HashMap<>(properties);
9797
}
9898

99+
public <T> boolean hasProp(@Nonnull RecordLayerPropertyKey<T> propKey) {
100+
return propertyMap.containsKey(propKey);
101+
}
102+
99103
public <T> Builder addProp(@Nonnull RecordLayerPropertyValue<T> propValue) {
100104
if (this.propertyMap.putIfAbsent(propValue.getKey(), propValue) != null) {
101105
throw new RecordCoreException("Duplicate property name is added")

fdb-record-layer-lucene/src/test/java/com/apple/foundationdb/record/lucene/LuceneIndexMaintenanceTest.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.apple.foundationdb.record.lucene.directory.FDBDirectoryLockFactory;
3636
import com.apple.foundationdb.record.lucene.directory.FDBDirectoryWrapper;
3737
import com.apple.foundationdb.record.metadata.Index;
38+
import com.apple.foundationdb.record.provider.common.RollingTestKeyManager;
3839
import com.apple.foundationdb.record.provider.common.StoreTimer;
3940
import com.apple.foundationdb.record.provider.foundationdb.FDBExceptions;
4041
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
@@ -70,6 +71,7 @@
7071
import javax.annotation.Nonnull;
7172
import javax.annotation.Nullable;
7273
import java.io.IOException;
74+
import java.security.GeneralSecurityException;
7375
import java.time.Duration;
7476
import java.util.ArrayDeque;
7577
import java.util.HashMap;
@@ -250,11 +252,13 @@ void savingInReverseDoesNotRequireRepartitioning(boolean isGrouped,
250252

251253
static Stream<Arguments> manyDocumentsArgumentsSlow() {
252254
return Stream.concat(
253-
Stream.of(Arguments.of(true, true, true, 80, 2, 200, 234809),
255+
Stream.of(Arguments.of(true, true, true, true, false, 80, 2, 200, 234809),
254256
// I don't know why, but this took over an hour, I'm hoping my laptop slept, but I don't see it
255-
Arguments.of(false, true, false, 50, 8, 212, 3125111852333110588L)),
257+
Arguments.of(false, true, false, true, false, 50, 8, 212, 3125111852333110588L)),
256258
RandomizedTestUtils.randomArguments(random ->
257259
Arguments.of(random.nextBoolean(),
260+
random.nextBoolean(),
261+
random.nextBoolean(),
258262
random.nextBoolean(),
259263
random.nextBoolean(),
260264
// We want to have a high partitionHighWatermark so that the underlying lucene indexes
@@ -271,27 +275,31 @@ static Stream<Arguments> manyDocumentsArgumentsSlow() {
271275
void manyDocumentSlow(boolean isGrouped,
272276
boolean isSynthetic,
273277
boolean primaryKeySegmentIndexEnabled,
278+
boolean compressed,
279+
boolean encrypted,
274280
int partitionHighWatermark,
275281
int repartitionCount,
276282
int loopCount,
277-
long seed) throws IOException {
278-
manyDocument(isGrouped, isSynthetic, primaryKeySegmentIndexEnabled, partitionHighWatermark,
283+
long seed) throws IOException, GeneralSecurityException {
284+
manyDocuments(isGrouped, isSynthetic, primaryKeySegmentIndexEnabled, compressed, encrypted, partitionHighWatermark,
279285
repartitionCount, loopCount, 10, seed);
280286
}
281287

282288

283289
static Stream<Arguments> manyDocumentsArguments() {
284290
return Stream.concat(
285291
Stream.concat(
286-
Stream.of(Arguments.of(true, true, true, 20, 4, 50, 3, -644766138635622644L)),
292+
Stream.of(Arguments.of(true, true, true, true, false, 20, 4, 50, 3, -644766138635622644L)),
287293
TestConfigurationUtils.onlyNightly(
288294
Stream.of(
289-
Arguments.of(true, false, false, 21, 3, 55, 3, 9237590782644L),
290-
Arguments.of(false, true, true, 18, 3, 46, 3, -1089113174774589435L),
291-
Arguments.of(false, false, false, 24, 6, 59, 3, 6223372946177329440L),
292-
Arguments.of(true, false, false, 27, 9, 48, 3, 2451719304283565963L)))),
295+
Arguments.of(true, false, false, true, false, 21, 3, 55, 3, 9237590782644L),
296+
Arguments.of(false, true, true, true, false, 18, 3, 46, 3, -1089113174774589435L),
297+
Arguments.of(false, false, false, true, false, 24, 6, 59, 3, 6223372946177329440L),
298+
Arguments.of(true, false, false, true, false, 27, 9, 48, 3, 2451719304283565963L)))),
293299
RandomizedTestUtils.randomArguments(random ->
294300
Arguments.of(random.nextBoolean(),
301+
random.nextBoolean(),
302+
random.nextBoolean(),
295303
random.nextBoolean(),
296304
random.nextBoolean(),
297305
// We want to have a high partitionHighWatermark so that the underlying lucene indexes
@@ -305,14 +313,16 @@ static Stream<Arguments> manyDocumentsArguments() {
305313

306314
@ParameterizedTest
307315
@MethodSource("manyDocumentsArguments")
308-
void manyDocument(boolean isGrouped,
309-
boolean isSynthetic,
310-
boolean primaryKeySegmentIndexEnabled,
311-
int partitionHighWatermark,
312-
int repartitionCount,
313-
int loopCount,
314-
int maxTransactionsPerLoop,
315-
long seed) throws IOException {
316+
void manyDocuments(boolean isGrouped,
317+
boolean isSynthetic,
318+
boolean primaryKeySegmentIndexEnabled,
319+
boolean compressed,
320+
boolean encrypted,
321+
int partitionHighWatermark,
322+
int repartitionCount,
323+
int loopCount,
324+
int maxTransactionsPerLoop,
325+
long seed) throws IOException, GeneralSecurityException {
316326
final LuceneIndexTestDataModel dataModel = new LuceneIndexTestDataModel.Builder(seed, this::getStoreBuilder, pathManager)
317327
.setIsGrouped(isGrouped)
318328
.setIsSynthetic(isSynthetic)
@@ -326,11 +336,16 @@ void manyDocument(boolean isGrouped,
326336
"seed", seed,
327337
"loopCount", loopCount));
328338

329-
final RecordLayerPropertyStorage contextProps = RecordLayerPropertyStorage.newBuilder()
339+
final RecordLayerPropertyStorage.Builder contextPropsBuilder = RecordLayerPropertyStorage.newBuilder()
330340
.addProp(LuceneRecordContextProperties.LUCENE_REPARTITION_DOCUMENT_COUNT, repartitionCount)
331341
.addProp(LuceneRecordContextProperties.LUCENE_MAX_DOCUMENTS_TO_MOVE_DURING_REPARTITIONING, dataModel.nextInt(1000) + repartitionCount)
332342
.addProp(LuceneRecordContextProperties.LUCENE_MERGE_SEGMENTS_PER_TIER, (double)dataModel.nextInt(10) + 2) // it must be at least 2.0
333-
.build();
343+
.addProp(LuceneRecordContextProperties.LUCENE_INDEX_COMPRESSION_ENABLED, compressed)
344+
.addProp(LuceneRecordContextProperties.LUCENE_INDEX_ENCRYPTION_ENABLED, encrypted);
345+
if (encrypted) {
346+
contextPropsBuilder.addProp(LuceneRecordContextProperties.LUCENE_INDEX_KEY_MANAGER, new RollingTestKeyManager(seed));
347+
}
348+
final RecordLayerPropertyStorage contextProps = contextPropsBuilder.build();
334349
for (int i = 0; i < loopCount; i++) {
335350
LOGGER.info(KeyValueLogMessage.of("ManyDocument loop",
336351
"iteration", i,
@@ -1279,6 +1294,9 @@ private void explicitMergeIndex(Index index,
12791294
}
12801295

12811296
protected RecordLayerPropertyStorage.Builder addDefaultProps(final RecordLayerPropertyStorage.Builder props) {
1297+
if (props.hasProp(LuceneRecordContextProperties.LUCENE_INDEX_COMPRESSION_ENABLED)) {
1298+
return props;
1299+
}
12821300
return super.addDefaultProps(props).addProp(LuceneRecordContextProperties.LUCENE_INDEX_COMPRESSION_ENABLED, true);
12831301
}
12841302
}

0 commit comments

Comments
 (0)