diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index 0021139adb9..5f75610e2e8 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -682,6 +682,8 @@ public class TranslogTests extends ESTestCase { // a signal for all threads to stop final AtomicBoolean run = new AtomicBoolean(true); + final Object flushMutex = new Object(); + // any errors on threads final List errors = new CopyOnWriteArrayList<>(); logger.debug("using [{}] readers. [{}] writers. flushing every ~[{}] ops.", readers.length, writers.length, flushEveryOps); @@ -721,7 +723,11 @@ public class TranslogTests extends ESTestCase { translog.ensureSynced(location); } if (id % flushEveryOps == 0) { - translog.commit(translog.currentFileGeneration()); + synchronized (flushMutex) { + // we need not do this concurrently as we need to make sure that the generation + // we're committing - translog.currentFileGeneration() - is still present when we're committing + translog.commit(translog.currentFileGeneration()); + } } if (id % 7 == 0) { synchronized (signalReaderSomeDataWasIndexed) {