|
18 | 18 | import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest;
|
19 | 19 | import org.opensearch.action.index.IndexResponse;
|
20 | 20 | import org.opensearch.action.search.SearchPhaseExecutionException;
|
| 21 | +import org.opensearch.client.Requests; |
21 | 22 | import org.opensearch.cluster.health.ClusterHealthStatus;
|
22 | 23 | import org.opensearch.cluster.metadata.IndexMetadata;
|
23 | 24 | import org.opensearch.cluster.routing.RecoverySource;
|
@@ -202,7 +203,7 @@ public void testRemoteTranslogCleanup() throws Exception {
|
202 | 203 |
|
203 | 204 | public void testStaleCommitDeletionWithInvokeFlush() throws Exception {
|
204 | 205 | String dataNode = internalCluster().startNode();
|
205 |
| - createIndex(INDEX_NAME, remoteStoreIndexSettings(1, 10000l, -1)); |
| 206 | + createIndex(INDEX_NAME, remoteStoreIndexSettings(1, 10000L, -1)); |
206 | 207 | int numberOfIterations = randomIntBetween(5, 15);
|
207 | 208 | indexData(numberOfIterations, true, INDEX_NAME);
|
208 | 209 | String segmentsPathFixedPrefix = RemoteStoreSettings.CLUSTER_REMOTE_STORE_SEGMENTS_PATH_PREFIX.get(getNodeSettings());
|
@@ -1011,4 +1012,70 @@ public void testAsyncTranslogDurabilityRestrictionsThroughIdxTemplates() throws
|
1011 | 1012 | .get()
|
1012 | 1013 | );
|
1013 | 1014 | }
|
| 1015 | + |
| 1016 | + public void testCloseIndexWithNoOpSyncAndFlushForSyncTranslog() throws InterruptedException { |
| 1017 | + internalCluster().startNodes(3); |
| 1018 | + client().admin() |
| 1019 | + .cluster() |
| 1020 | + .prepareUpdateSettings() |
| 1021 | + .setTransientSettings(Settings.builder().put(CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING.getKey(), "5s")) |
| 1022 | + .get(); |
| 1023 | + Settings.Builder settings = Settings.builder() |
| 1024 | + .put(remoteStoreIndexSettings(0, 10000L, -1)) |
| 1025 | + .put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "1s"); |
| 1026 | + createIndex(INDEX_NAME, settings.build()); |
| 1027 | + CountDownLatch latch = new CountDownLatch(1); |
| 1028 | + new Thread(() -> { |
| 1029 | + if (randomBoolean()) { |
| 1030 | + for (int i = 0; i < randomIntBetween(1, 5); i++) { |
| 1031 | + indexSingleDoc(INDEX_NAME); |
| 1032 | + } |
| 1033 | + flushAndRefresh(INDEX_NAME); |
| 1034 | + } |
| 1035 | + // Index single doc to start the asyn io processor to run which will lead to 10s wait time before the next sync. |
| 1036 | + indexSingleDoc(INDEX_NAME); |
| 1037 | + // Reduce the latch for the main thread to flush after some sleep. |
| 1038 | + latch.countDown(); |
| 1039 | + // Index another doc and in this case the flush would have happened before the sync. |
| 1040 | + indexSingleDoc(INDEX_NAME); |
| 1041 | + }).start(); |
| 1042 | + // Wait for atleast one doc to be ingested. |
| 1043 | + latch.await(); |
| 1044 | + // Sleep for some time for the next doc to be present in lucene buffer. If flush happens first before the doc #2 |
| 1045 | + // gets indexed, then it goes into the happy case where the close index happens succefully. |
| 1046 | + Thread.sleep(1000); |
| 1047 | + // Flush so that the subsequent sync or flushes are no-op. |
| 1048 | + flush(INDEX_NAME); |
| 1049 | + // Closing the index involves translog.sync and shard.flush which are now no-op. |
| 1050 | + client().admin().indices().close(Requests.closeIndexRequest(INDEX_NAME)).actionGet(); |
| 1051 | + Thread.sleep(10000); |
| 1052 | + ensureGreen(INDEX_NAME); |
| 1053 | + } |
| 1054 | + |
| 1055 | + public void testCloseIndexWithNoOpSyncAndFlushForAsyncTranslog() throws InterruptedException { |
| 1056 | + internalCluster().startNodes(3); |
| 1057 | + Settings.Builder settings = Settings.builder() |
| 1058 | + .put(remoteStoreIndexSettings(0, 10000L, -1)) |
| 1059 | + .put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "1s") |
| 1060 | + .put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Durability.ASYNC) |
| 1061 | + .put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "10s"); |
| 1062 | + createIndex(INDEX_NAME, settings.build()); |
| 1063 | + CountDownLatch latch = new CountDownLatch(1); |
| 1064 | + new Thread(() -> { |
| 1065 | + // Index some docs to start the asyn io processor to run which will lead to 10s wait time before the next sync. |
| 1066 | + indexSingleDoc(INDEX_NAME); |
| 1067 | + indexSingleDoc(INDEX_NAME); |
| 1068 | + indexSingleDoc(INDEX_NAME); |
| 1069 | + // Reduce the latch for the main thread to flush after some sleep. |
| 1070 | + latch.countDown(); |
| 1071 | + }).start(); |
| 1072 | + // Wait for atleast one doc to be ingested. |
| 1073 | + latch.await(); |
| 1074 | + // Flush so that the subsequent sync or flushes are no-op. |
| 1075 | + flush(INDEX_NAME); |
| 1076 | + // Closing the index involves translog.sync and shard.flush which are now no-op. |
| 1077 | + client().admin().indices().close(Requests.closeIndexRequest(INDEX_NAME)).actionGet(); |
| 1078 | + Thread.sleep(10000); |
| 1079 | + ensureGreen(INDEX_NAME); |
| 1080 | + } |
1014 | 1081 | }
|
0 commit comments