Skip to content

Commit 14cd0e3

Browse files
authored
FEATURE-13448: add use compound file setting (opensearch-project#13478)
* 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]>
1 parent 89c6c27 commit 14cd0e3

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55

66
## [Unreleased 2.x]
77
### Added
8+
- Add useCompoundFile index setting ([#13478](https://github.com/opensearch-project/OpenSearch/pull/13478))
89
- Constant Keyword Field ([#12285](https://github.com/opensearch-project/OpenSearch/pull/12285))
910
- Convert ingest processor supports ip type ([#12818](https://github.com/opensearch-project/OpenSearch/pull/12818))
1011
- 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))

server/src/main/java/org/opensearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
198198
EngineConfig.INDEX_CODEC_SETTING,
199199
EngineConfig.INDEX_CODEC_COMPRESSION_LEVEL_SETTING,
200200
EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS,
201+
EngineConfig.INDEX_USE_COMPOUND_FILE,
201202
IndexMetadata.SETTING_WAIT_FOR_ACTIVE_SHARDS,
202203
IndexSettings.DEFAULT_PIPELINE,
203204
IndexSettings.FINAL_PIPELINE,

server/src/main/java/org/opensearch/index/engine/EngineConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ private static void doValidateCodecSettings(final String codec) {
236236
Property.Dynamic
237237
);
238238

239+
public static final Setting<Boolean> INDEX_USE_COMPOUND_FILE = Setting.boolSetting(
240+
"index.use_compound_file",
241+
true,
242+
Property.IndexScope
243+
);
244+
239245
private final TranslogConfig translogConfig;
240246

241247
private final TranslogFactory translogFactory;
@@ -494,6 +500,10 @@ public boolean isReadOnlyReplica() {
494500
return indexSettings.isSegRepEnabledOrRemoteNode() && isReadOnlyReplica;
495501
}
496502

503+
public boolean useCompoundFile() {
504+
return indexSettings.getValue(INDEX_USE_COMPOUND_FILE);
505+
}
506+
497507
/**
498508
* Returns the underlying startedPrimarySupplier.
499509
* @return the primary mode supplier.

server/src/main/java/org/opensearch/index/engine/InternalEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ private IndexWriterConfig getIndexWriterConfig() {
23412341
iwc.setSimilarity(engineConfig.getSimilarity());
23422342
iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());
23432343
iwc.setCodec(engineConfig.getCodec());
2344-
iwc.setUseCompoundFile(true); // always use compound on flush - reduces # of file-handles on refresh
2344+
iwc.setUseCompoundFile(engineConfig.useCompoundFile());
23452345
if (config().getIndexSort() != null) {
23462346
iwc.setIndexSort(config().getIndexSort());
23472347
}

server/src/test/java/org/opensearch/index/engine/EngineConfigTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public void setUp() throws Exception {
3232
defaultIndexSettings = IndexSettingsModule.newIndexSettings("test", defaultIndexMetadata.getSettings());
3333
}
3434

35+
public void testEngineConfig_DefaultValueFoUseCompoundFile() {
36+
EngineConfig config = new EngineConfig.Builder().indexSettings(defaultIndexSettings)
37+
.retentionLeasesSupplier(() -> RetentionLeases.EMPTY)
38+
.build();
39+
assertTrue(config.useCompoundFile());
40+
}
41+
3542
public void testEngineConfig_DefaultValueForReadOnlyEngine() {
3643
EngineConfig config = new EngineConfig.Builder().indexSettings(defaultIndexSettings)
3744
.retentionLeasesSupplier(() -> RetentionLeases.EMPTY)

server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,58 @@ public void testVerboseSegments() throws Exception {
342342
}
343343
}
344344

345+
public void testSegmentsWithUseCompoundFileFlag_true() throws IOException {
346+
try (Store store = createStore(); Engine engine = createEngine(defaultSettings, store, createTempDir(), new TieredMergePolicy())) {
347+
ParsedDocument doc = testParsedDocument("1", null, testDocument(), B_1, null);
348+
Engine.Index index = indexForDoc(doc);
349+
engine.index(index);
350+
engine.flush();
351+
final List<Segment> segments = engine.segments(false);
352+
assertThat(segments, hasSize(1));
353+
assertTrue(segments.get(0).compound);
354+
boolean cfeCompoundFileFound = false;
355+
boolean cfsCompoundFileFound = false;
356+
for (final String fileName : store.readLastCommittedSegmentsInfo().files(true)) {
357+
if (fileName.endsWith(".cfe")) {
358+
cfeCompoundFileFound = true;
359+
}
360+
if (fileName.endsWith(".cfs")) {
361+
cfsCompoundFileFound = true;
362+
}
363+
}
364+
Assert.assertTrue(cfeCompoundFileFound);
365+
Assert.assertTrue(cfsCompoundFileFound);
366+
}
367+
}
368+
369+
public void testSegmentsWithUseCompoundFileFlag_false() throws IOException {
370+
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(
371+
"test",
372+
Settings.builder().put(defaultSettings.getSettings()).put(EngineConfig.INDEX_USE_COMPOUND_FILE.getKey(), false).build()
373+
);
374+
try (Store store = createStore(); Engine engine = createEngine(indexSettings, store, createTempDir(), new TieredMergePolicy())) {
375+
ParsedDocument doc = testParsedDocument("1", null, testDocument(), B_1, null);
376+
Engine.Index index = indexForDoc(doc);
377+
engine.index(index);
378+
engine.flush();
379+
final List<Segment> segments = engine.segments(false);
380+
assertThat(segments, hasSize(1));
381+
assertFalse(segments.get(0).compound);
382+
boolean cfeCompoundFileFound = false;
383+
boolean cfsCompoundFileFound = false;
384+
for (final String fileName : store.readLastCommittedSegmentsInfo().files(true)) {
385+
if (fileName.endsWith(".cfe")) {
386+
cfeCompoundFileFound = true;
387+
}
388+
if (fileName.endsWith(".cfs")) {
389+
cfsCompoundFileFound = true;
390+
}
391+
}
392+
Assert.assertFalse(cfeCompoundFileFound);
393+
Assert.assertFalse(cfsCompoundFileFound);
394+
}
395+
}
396+
345397
public void testSegmentsWithMergeFlag() throws Exception {
346398
try (Store store = createStore(); Engine engine = createEngine(defaultSettings, store, createTempDir(), new TieredMergePolicy())) {
347399
ParsedDocument doc = testParsedDocument("1", null, testDocument(), B_1, null);

0 commit comments

Comments
 (0)