|
30 | 30 | import org.opensearch.index.IndexSettings;
|
31 | 31 | import org.opensearch.index.shard.IndexShard;
|
32 | 32 | import org.opensearch.index.shard.IndexShardClosedException;
|
| 33 | +import org.opensearch.index.translog.Translog; |
33 | 34 | import org.opensearch.index.translog.Translog.Durability;
|
34 | 35 | import org.opensearch.indices.IndicesService;
|
35 | 36 | import org.opensearch.indices.RemoteStoreSettings;
|
|
63 | 64 | import static org.opensearch.index.remote.RemoteStoreEnums.DataCategory.TRANSLOG;
|
64 | 65 | import static org.opensearch.index.remote.RemoteStoreEnums.DataType.DATA;
|
65 | 66 | import static org.opensearch.index.remote.RemoteStoreEnums.DataType.METADATA;
|
| 67 | +import static org.opensearch.index.shard.IndexShardTestCase.getTranslog; |
66 | 68 | import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING;
|
67 | 69 | import static org.opensearch.test.OpenSearchTestCase.getShardLevelBlobPath;
|
68 | 70 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
@@ -859,4 +861,45 @@ public void testLocalOnlyTranslogCleanupOnNodeRestart() throws Exception {
|
859 | 861 | refresh(INDEX_NAME);
|
860 | 862 | assertHitCount(client(dataNode).prepareSearch(INDEX_NAME).setSize(0).get(), searchableDocs + 15);
|
861 | 863 | }
|
| 864 | + |
| 865 | + public void testFlushOnTooManyRemoteTranslogFiles() throws Exception { |
| 866 | + internalCluster().startClusterManagerOnlyNode(); |
| 867 | + String datanode = internalCluster().startDataOnlyNodes(1).get(0); |
| 868 | + createIndex(INDEX_NAME, remoteStoreIndexSettings(0, 10000L, -1)); |
| 869 | + ensureGreen(INDEX_NAME); |
| 870 | + |
| 871 | + ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); |
| 872 | + updateSettingsRequest.persistentSettings( |
| 873 | + Settings.builder().put(RemoteStoreSettings.CLUSTER_REMOTE_MAX_TRANSLOG_READERS.getKey(), "100") |
| 874 | + ); |
| 875 | + assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); |
| 876 | + |
| 877 | + IndexShard indexShard = getIndexShard(datanode, INDEX_NAME); |
| 878 | + Path translogLocation = getTranslog(indexShard).location(); |
| 879 | + assertFalse(indexShard.shouldPeriodicallyFlush()); |
| 880 | + |
| 881 | + try (Stream<Path> files = Files.list(translogLocation)) { |
| 882 | + long totalFiles = files.filter(f -> f.getFileName().toString().endsWith(Translog.TRANSLOG_FILE_SUFFIX)).count(); |
| 883 | + assertEquals(totalFiles, 1L); |
| 884 | + } |
| 885 | + |
| 886 | + // indexing 100 documents (100 bulk requests), no flush will be triggered yet |
| 887 | + for (int i = 0; i < 100; i++) { |
| 888 | + indexBulk(INDEX_NAME, 1); |
| 889 | + } |
| 890 | + |
| 891 | + try (Stream<Path> files = Files.list(translogLocation)) { |
| 892 | + long totalFiles = files.filter(f -> f.getFileName().toString().endsWith(Translog.TRANSLOG_FILE_SUFFIX)).count(); |
| 893 | + assertEquals(totalFiles, 101L); |
| 894 | + } |
| 895 | + // Will flush and trim the translog readers |
| 896 | + indexBulk(INDEX_NAME, 1); |
| 897 | + |
| 898 | + assertBusy(() -> { |
| 899 | + try (Stream<Path> files = Files.list(translogLocation)) { |
| 900 | + long totalFiles = files.filter(f -> f.getFileName().toString().endsWith(Translog.TRANSLOG_FILE_SUFFIX)).count(); |
| 901 | + assertEquals(totalFiles, 1L); |
| 902 | + } |
| 903 | + }, 30, TimeUnit.SECONDS); |
| 904 | + } |
862 | 905 | }
|
0 commit comments