Skip to content

Commit bc8dcd6

Browse files
TESTS: Fix Race Condition in Temp Path Creation (#33352) (#33370)
* TESTS: Fix Race Condition in Temp Path Creation * Calling `createTempDir` concurrently here in the `Follower`s causes collisions at times which lead to `createEngine` throwing because of unexpected files in the newly created temp dir * Fixed by creating all temp dirs in the main test thread * closes #33344
1 parent ae55a93 commit bc8dcd6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

server/src/test/java/org/elasticsearch/index/engine/LuceneChangesSnapshotTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.index.engine;
2121

22+
import java.nio.file.Path;
2223
import org.elasticsearch.common.settings.Settings;
2324
import org.elasticsearch.core.internal.io.IOUtils;
2425
import org.elasticsearch.index.IndexSettings;
@@ -191,13 +192,12 @@ public void testDedupByPrimaryTerm() throws Exception {
191192
}
192193
}
193194

194-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33344")
195195
public void testUpdateAndReadChangesConcurrently() throws Exception {
196196
Follower[] followers = new Follower[between(1, 3)];
197197
CountDownLatch readyLatch = new CountDownLatch(followers.length + 1);
198198
AtomicBoolean isDone = new AtomicBoolean();
199199
for (int i = 0; i < followers.length; i++) {
200-
followers[i] = new Follower(engine, isDone, readyLatch);
200+
followers[i] = new Follower(engine, isDone, readyLatch, createTempDir());
201201
followers[i].start();
202202
}
203203
boolean onPrimary = randomBoolean();
@@ -236,13 +236,15 @@ class Follower extends Thread {
236236
private final TranslogHandler translogHandler;
237237
private final AtomicBoolean isDone;
238238
private final CountDownLatch readLatch;
239+
private final Path translogPath;
239240

240-
Follower(Engine leader, AtomicBoolean isDone, CountDownLatch readLatch) {
241+
Follower(Engine leader, AtomicBoolean isDone, CountDownLatch readLatch, Path translogPath) {
241242
this.leader = leader;
242243
this.isDone = isDone;
243244
this.readLatch = readLatch;
244245
this.translogHandler = new TranslogHandler(xContentRegistry(), IndexSettingsModule.newIndexSettings(shardId.getIndexName(),
245246
engine.engineConfig.getIndexSettings().getSettings()));
247+
this.translogPath = translogPath;
246248
}
247249

248250
void pullOperations(Engine follower) throws IOException {
@@ -261,7 +263,7 @@ void pullOperations(Engine follower) throws IOException {
261263
@Override
262264
public void run() {
263265
try (Store store = createStore();
264-
InternalEngine follower = createEngine(store, createTempDir())) {
266+
InternalEngine follower = createEngine(store, translogPath)) {
265267
readLatch.countDown();
266268
readLatch.await();
267269
while (isDone.get() == false ||

0 commit comments

Comments
 (0)