Skip to content

Commit 91925c3

Browse files
committed
TEST: Create following engines in the main thread (#33391)
There are two races in the testUpdateAndReadChangesConcurrently if the following engines are created in the worker threads. We fixed the translog issue in #33352, but there is still another race with createStore. This commit ensures that we create all engines in the main thread. Relates #33352 Closes #33344
1 parent 05a366a commit 91925c3

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919

2020
package org.elasticsearch.index.engine;
2121

22-
import java.nio.file.Path;
2322
import org.elasticsearch.common.settings.Settings;
2423
import org.elasticsearch.core.internal.io.IOUtils;
2524
import org.elasticsearch.index.IndexSettings;
2625
import org.elasticsearch.index.VersionType;
2726
import org.elasticsearch.index.mapper.MapperService;
2827
import org.elasticsearch.index.mapper.ParsedDocument;
29-
import org.elasticsearch.index.store.Store;
3028
import org.elasticsearch.index.translog.SnapshotMatchers;
3129
import org.elasticsearch.index.translog.Translog;
3230
import org.elasticsearch.test.IndexSettingsModule;
@@ -202,7 +200,7 @@ public void testUpdateAndReadChangesConcurrently() throws Exception {
202200
CountDownLatch readyLatch = new CountDownLatch(followers.length + 1);
203201
AtomicBoolean isDone = new AtomicBoolean();
204202
for (int i = 0; i < followers.length; i++) {
205-
followers[i] = new Follower(engine, isDone, readyLatch, createTempDir());
203+
followers[i] = new Follower(engine, isDone, readyLatch);
206204
followers[i].start();
207205
}
208206
boolean onPrimary = randomBoolean();
@@ -228,28 +226,30 @@ public void testUpdateAndReadChangesConcurrently() throws Exception {
228226
operations.add(op);
229227
}
230228
readyLatch.countDown();
229+
readyLatch.await();
231230
concurrentlyApplyOps(operations, engine);
232231
assertThat(engine.getLocalCheckpointTracker().getCheckpoint(), equalTo(operations.size() - 1L));
233232
isDone.set(true);
234233
for (Follower follower : followers) {
235234
follower.join();
235+
IOUtils.close(follower.engine, follower.engine.store);
236236
}
237237
}
238238

239239
class Follower extends Thread {
240240
private final Engine leader;
241+
private final InternalEngine engine;
241242
private final TranslogHandler translogHandler;
242243
private final AtomicBoolean isDone;
243244
private final CountDownLatch readLatch;
244-
private final Path translogPath;
245245

246-
Follower(Engine leader, AtomicBoolean isDone, CountDownLatch readLatch, Path translogPath) {
246+
Follower(Engine leader, AtomicBoolean isDone, CountDownLatch readLatch) throws IOException {
247247
this.leader = leader;
248248
this.isDone = isDone;
249249
this.readLatch = readLatch;
250250
this.translogHandler = new TranslogHandler(xContentRegistry(), IndexSettingsModule.newIndexSettings(shardId.getIndexName(),
251-
engine.engineConfig.getIndexSettings().getSettings()));
252-
this.translogPath = translogPath;
251+
leader.engineConfig.getIndexSettings().getSettings()));
252+
this.engine = createEngine(createStore(), createTempDir());
253253
}
254254

255255
void pullOperations(Engine follower) throws IOException {
@@ -267,16 +267,15 @@ void pullOperations(Engine follower) throws IOException {
267267

268268
@Override
269269
public void run() {
270-
try (Store store = createStore();
271-
InternalEngine follower = createEngine(store, translogPath)) {
270+
try {
272271
readLatch.countDown();
273272
readLatch.await();
274273
while (isDone.get() == false ||
275-
follower.getLocalCheckpointTracker().getCheckpoint() < leader.getLocalCheckpoint()) {
276-
pullOperations(follower);
274+
engine.getLocalCheckpointTracker().getCheckpoint() < leader.getLocalCheckpoint()) {
275+
pullOperations(engine);
277276
}
278-
assertConsistentHistoryBetweenTranslogAndLuceneIndex(follower, mapperService);
279-
assertThat(getDocIds(follower, true), equalTo(getDocIds(leader, true)));
277+
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, mapperService);
278+
assertThat(getDocIds(engine, true), equalTo(getDocIds(leader, true)));
280279
} catch (Exception ex) {
281280
throw new AssertionError(ex);
282281
}

0 commit comments

Comments
 (0)