Skip to content

Commit 0890947

Browse files
committed
[Remote Store] Add support to disable flush based on translog reader count (opensearch-project#14027)
Signed-off-by: Shourya Dutta Biswas <114977491+shourya035@users.noreply.github.com>
1 parent 9bc536d commit 0890947

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212
- [Remote Store] Add dynamic cluster settings to set timeout for segments upload to Remote Store ([#13679](https://github.com/opensearch-project/OpenSearch/pull/13679))
1313
- Add getMetadataFields to MapperService ([#13819](https://github.com/opensearch-project/OpenSearch/pull/13819))
1414
- Allow setting query parameters on requests ([#13776](https://github.com/opensearch-project/OpenSearch/issues/13776))
15+
- [Remote Store] Add support to disable flush based on translog reader count ([#14027](https://github.com/opensearch-project/OpenSearch/pull/14027))
1516

1617
### Dependencies
1718
- Bump `com.github.spullara.mustache.java:compiler` from 0.9.10 to 0.9.13 ([#13329](https://github.com/opensearch-project/OpenSearch/pull/13329), [#13559](https://github.com/opensearch-project/OpenSearch/pull/13559))

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreIT.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ public void testFlushOnTooManyRemoteTranslogFiles() throws Exception {
852852

853853
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
854854
updateSettingsRequest.persistentSettings(
855-
Settings.builder().put(RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS.getKey(), "100")
855+
Settings.builder()
856+
.put(RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS.getKey(), "100")
857+
.put(CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING.getKey(), "0ms")
856858
);
857859
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
858860

@@ -883,5 +885,27 @@ public void testFlushOnTooManyRemoteTranslogFiles() throws Exception {
883885
assertEquals(totalFiles, 1L);
884886
}
885887
}, 30, TimeUnit.SECONDS);
888+
889+
// Disabling max translog readers
890+
assertAcked(
891+
internalCluster().client()
892+
.admin()
893+
.cluster()
894+
.prepareUpdateSettings()
895+
.setPersistentSettings(Settings.builder().put(RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS.getKey(), "-1"))
896+
.get()
897+
);
898+
899+
// Indexing 500 more docs
900+
for (int i = 0; i < 500; i++) {
901+
indexBulk(INDEX_NAME, 1);
902+
}
903+
904+
// No flush is triggered since max_translog_readers is set to -1
905+
// Total tlog files would be incremented by 500
906+
try (Stream<Path> files = Files.list(translogLocation)) {
907+
long totalFiles = files.filter(f -> f.getFileName().toString().endsWith(Translog.TRANSLOG_FILE_SUFFIX)).count();
908+
assertEquals(totalFiles, 501L);
909+
}
886910
}
887911
}

server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,10 @@ int availablePermits() {
706706
*/
707707
@Override
708708
protected boolean shouldFlush() {
709-
return readers.size() >= translogTransferManager.getMaxRemoteTranslogReadersSettings();
709+
int maxRemoteTlogReaders = translogTransferManager.getMaxRemoteTranslogReadersSettings();
710+
if (maxRemoteTlogReaders == -1) {
711+
return false;
712+
}
713+
return readers.size() >= maxRemoteTlogReaders;
710714
}
711715
}

server/src/main/java/org/opensearch/indices/RemoteStoreSettings.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
@PublicApi(since = "2.14.0")
2727
public class RemoteStoreSettings {
28+
private static final int MIN_CLUSTER_REMOTE_MAX_TRANSLOG_READERS = 100;
2829

2930
/**
3031
* Used to specify the default translog buffer interval for remote store backed indexes.
@@ -112,7 +113,12 @@ public class RemoteStoreSettings {
112113
public static final Setting<Integer> CLUSTER_REMOTE_MAX_TRANSLOG_READERS = Setting.intSetting(
113114
"cluster.remote_store.translog.max_readers",
114115
1000,
115-
100,
116+
-1,
117+
v -> {
118+
if (v != -1 && v < MIN_CLUSTER_REMOTE_MAX_TRANSLOG_READERS) {
119+
throw new IllegalArgumentException("Cannot set value lower than " + MIN_CLUSTER_REMOTE_MAX_TRANSLOG_READERS);
120+
}
121+
},
116122
Property.Dynamic,
117123
Property.NodeScope
118124
);

server/src/test/java/org/opensearch/indices/RemoteStoreSettingsDynamicUpdateTests.java

+11
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,15 @@ public void testMaxRemoteReferencedTranslogFiles() {
116116
);
117117
assertEquals(500, remoteStoreSettings.getMaxRemoteTranslogReaders());
118118
}
119+
120+
public void testDisableMaxRemoteReferencedTranslogFiles() {
121+
// Test default value
122+
assertEquals(1000, remoteStoreSettings.getMaxRemoteTranslogReaders());
123+
124+
// Test override with valid value
125+
clusterSettings.applySettings(
126+
Settings.builder().put(RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS.getKey(), "-1").build()
127+
);
128+
assertEquals(-1, remoteStoreSettings.getMaxRemoteTranslogReaders());
129+
}
119130
}

0 commit comments

Comments
 (0)