Skip to content

Commit a1d5a87

Browse files
committed
[Remote Store] Emit correct global checkpoint during translog upload
Signed-off-by: Ashish Singh <[email protected]>
1 parent 3a1b6d1 commit a1d5a87

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest;
1919
import org.opensearch.action.index.IndexResponse;
2020
import org.opensearch.action.search.SearchPhaseExecutionException;
21+
import org.opensearch.client.Requests;
2122
import org.opensearch.cluster.health.ClusterHealthStatus;
2223
import org.opensearch.cluster.metadata.IndexMetadata;
2324
import org.opensearch.cluster.routing.RecoverySource;
@@ -202,7 +203,7 @@ public void testRemoteTranslogCleanup() throws Exception {
202203

203204
public void testStaleCommitDeletionWithInvokeFlush() throws Exception {
204205
String dataNode = internalCluster().startNode();
205-
createIndex(INDEX_NAME, remoteStoreIndexSettings(1, 10000l, -1));
206+
createIndex(INDEX_NAME, remoteStoreIndexSettings(1, 10000L, -1));
206207
int numberOfIterations = randomIntBetween(5, 15);
207208
indexData(numberOfIterations, true, INDEX_NAME);
208209
String segmentsPathFixedPrefix = RemoteStoreSettings.CLUSTER_REMOTE_STORE_SEGMENTS_PATH_PREFIX.get(getNodeSettings());
@@ -1011,4 +1012,73 @@ public void testAsyncTranslogDurabilityRestrictionsThroughIdxTemplates() throws
10111012
.get()
10121013
);
10131014
}
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+
// Sleep for some time for the next doc to be present in lucene buffer. If flush happens first before the doc #2
1075+
// gets indexed, then it goes into the happy case where the close index happens succefully.
1076+
Thread.sleep(1000);
1077+
// Flush so that the subsequent sync or flushes are no-op.
1078+
flush(INDEX_NAME);
1079+
// Closing the index involves translog.sync and shard.flush which are now no-op.
1080+
client().admin().indices().close(Requests.closeIndexRequest(INDEX_NAME)).actionGet();
1081+
Thread.sleep(10000);
1082+
ensureGreen(INDEX_NAME);
1083+
}
10141084
}

0 commit comments

Comments
 (0)