Skip to content

Commit

Permalink
FEATURE-13448: add use compound file setting (opensearch-project#13478)
Browse files Browse the repository at this point in the history
* add use compound file setting

Signed-off-by: Samuel Herman <[email protected]>

* review feedback

Signed-off-by: Samuel Herman <[email protected]>

---------

Signed-off-by: Samuel Herman <[email protected]>
  • Loading branch information
samuel-oci authored May 3, 2024
1 parent 89c6c27 commit 14cd0e3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased 2.x]
### Added
- Add useCompoundFile index setting ([#13478](https://github.com/opensearch-project/OpenSearch/pull/13478))
- Constant Keyword Field ([#12285](https://github.com/opensearch-project/OpenSearch/pull/12285))
- Convert ingest processor supports ip type ([#12818](https://github.com/opensearch-project/OpenSearch/pull/12818))
- Add a counter to node stat api to track shard going from idle to non-idle ([#12768](https://github.com/opensearch-project/OpenSearch/pull/12768))
Expand Down
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
10 changes: 10 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 @@ -236,6 +236,12 @@ 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
);

private final TranslogConfig translogConfig;

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

public boolean useCompoundFile() {
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.useCompoundFile());
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.useCompoundFile());
}

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,58 @@ 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, hasSize(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, hasSize(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 14cd0e3

Please sign in to comment.