Skip to content

Commit

Permalink
add use compound file setting
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Herman <[email protected]>
  • Loading branch information
sam-herman committed Apr 30, 2024
1 parent 2dc3f74 commit 51fa0eb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
EngineConfig.INDEX_CODEC_SETTING,
EngineConfig.INDEX_CODEC_COMPRESSION_LEVEL_SETTING,
EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS,
EngineConfig.INDEX_USE_COMPOUND_FILE,
IndexMetadata.SETTING_WAIT_FOR_ACTIVE_SHARDS,
IndexSettings.DEFAULT_PIPELINE,
IndexSettings.FINAL_PIPELINE,
Expand Down
13 changes: 13 additions & 0 deletions server/src/main/java/org/opensearch/index/engine/EngineConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
}
}, Property.IndexScope, Property.NodeScope);



/**
* Index setting to change the compression level of zstd and zstd_no_dict lucene codecs.
* Compression Level gives a trade-off between compression ratio and speed. The higher compression level results in higher compression ratio but slower compression and decompression speeds.
Expand Down Expand Up @@ -236,6 +238,13 @@ private static void doValidateCodecSettings(final String codec) {
Property.Dynamic
);

public static final Setting<Boolean> INDEX_USE_COMPOUND_FILE = Setting.boolSetting(
"index.use_compound_file",
true,
Property.IndexScope,
Property.Dynamic
);

private final TranslogConfig translogConfig;

private final TranslogFactory translogFactory;
Expand Down Expand Up @@ -494,6 +503,10 @@ public boolean isReadOnlyReplica() {
return indexSettings.isSegRepEnabledOrRemoteNode() && isReadOnlyReplica;
}

public boolean isUseCompoundFile() {
return indexSettings.getValue(INDEX_USE_COMPOUND_FILE);
}

/**
* Returns the underlying startedPrimarySupplier.
* @return the primary mode supplier.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,7 @@ private IndexWriterConfig getIndexWriterConfig() {
iwc.setSimilarity(engineConfig.getSimilarity());
iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());
iwc.setCodec(engineConfig.getCodec());
iwc.setUseCompoundFile(true); // always use compound on flush - reduces # of file-handles on refresh
iwc.setUseCompoundFile(engineConfig.isUseCompoundFile());
if (config().getIndexSort() != null) {
iwc.setIndexSort(config().getIndexSort());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public void setUp() throws Exception {
defaultIndexSettings = IndexSettingsModule.newIndexSettings("test", defaultIndexMetadata.getSettings());
}

public void testEngineConfig_DefaultValueFoUseCompoundFile() {
EngineConfig config = new EngineConfig.Builder().indexSettings(defaultIndexSettings)
.retentionLeasesSupplier(() -> RetentionLeases.EMPTY)
.build();
assertTrue(config.isUseCompoundFile());
}

public void testEngineConfig_DefaultValueForReadOnlyEngine() {
EngineConfig config = new EngineConfig.Builder().indexSettings(defaultIndexSettings)
.retentionLeasesSupplier(() -> RetentionLeases.EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,61 @@ public void testVerboseSegments() throws Exception {
}
}

public void testSegmentsWithUseCompoundFileFlag_true() throws IOException {
try (Store store = createStore(); Engine engine = createEngine(defaultSettings, store, createTempDir(), new TieredMergePolicy())) {
ParsedDocument doc = testParsedDocument("1", null, testDocument(), B_1, null);
Engine.Index index = indexForDoc(doc);
engine.index(index);
engine.flush();
final List<Segment> segments = engine.segments(false);
assertThat(segments.size(), equalTo(1));
assertTrue(segments.get(0).compound);
boolean cfeCompoundFileFound = false;
boolean cfsCompoundFileFound = false;
for (final String fileName : store.readLastCommittedSegmentsInfo().files(true)) {
if (fileName.endsWith(".cfe")) {
cfeCompoundFileFound = true;
}
if (fileName.endsWith(".cfs")) {
cfsCompoundFileFound = true;
}
}
Assert.assertTrue(cfeCompoundFileFound);
Assert.assertTrue(cfsCompoundFileFound);
}
}

public void testSegmentsWithUseCompoundFileFlag_false() throws IOException {
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(
"test",
Settings.builder()
.put(defaultSettings.getSettings())
.put(EngineConfig.INDEX_USE_COMPOUND_FILE.getKey(), false)
.build()
);
try (Store store = createStore(); Engine engine = createEngine(indexSettings, store, createTempDir(), new TieredMergePolicy())) {
ParsedDocument doc = testParsedDocument("1", null, testDocument(), B_1, null);
Engine.Index index = indexForDoc(doc);
engine.index(index);
engine.flush();
final List<Segment> segments = engine.segments(false);
assertThat(segments.size(), equalTo(1));
assertFalse(segments.get(0).compound);
boolean cfeCompoundFileFound = false;
boolean cfsCompoundFileFound = false;
for (final String fileName : store.readLastCommittedSegmentsInfo().files(true)) {
if (fileName.endsWith(".cfe")) {
cfeCompoundFileFound = true;
}
if (fileName.endsWith(".cfs")) {
cfsCompoundFileFound = true;
}
}
Assert.assertFalse(cfeCompoundFileFound);
Assert.assertFalse(cfsCompoundFileFound);
}
}

public void testSegmentsWithMergeFlag() throws Exception {
try (Store store = createStore(); Engine engine = createEngine(defaultSettings, store, createTempDir(), new TieredMergePolicy())) {
ParsedDocument doc = testParsedDocument("1", null, testDocument(), B_1, null);
Expand Down

0 comments on commit 51fa0eb

Please sign in to comment.