diff --git a/server/src/main/java/org/elasticsearch/index/translog/TranslogStats.java b/server/src/main/java/org/elasticsearch/index/translog/TranslogStats.java index 3089e443568..37c671a6c22 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/TranslogStats.java +++ b/server/src/main/java/org/elasticsearch/index/translog/TranslogStats.java @@ -88,8 +88,12 @@ public class TranslogStats implements Writeable, ToXContentFragment { this.translogSizeInBytes += translogStats.translogSizeInBytes; this.uncommittedOperations += translogStats.uncommittedOperations; this.uncommittedSizeInBytes += translogStats.uncommittedSizeInBytes; - this.earliestLastModifiedAge = - Math.min(this.earliestLastModifiedAge, translogStats.earliestLastModifiedAge); + if (this.earliestLastModifiedAge == 0) { + this.earliestLastModifiedAge = translogStats.earliestLastModifiedAge; + } else { + this.earliestLastModifiedAge = + Math.min(this.earliestLastModifiedAge, translogStats.earliestLastModifiedAge); + } } public long getTranslogSizeInBytes() { diff --git a/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index 0606faba2ef..27b34d154c8 100644 --- a/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -529,14 +529,18 @@ public class TranslogTests extends ESTestCase { public void testTotalTests() { final TranslogStats total = - new TranslogStats(0, 0, 0, 0, 1); + new TranslogStats(); final int n = randomIntBetween(0, 16); final List statsList = new ArrayList<>(n); + long earliestLastModifiedAge = Long.MAX_VALUE; for (int i = 0; i < n; i++) { final TranslogStats stats = new TranslogStats(randomIntBetween(1, 4096), randomIntBetween(1, 1 << 20), randomIntBetween(1, 1 << 20), randomIntBetween(1, 4096), randomIntBetween(1, 1 << 20)); statsList.add(stats); total.add(stats); + if (earliestLastModifiedAge > stats.getEarliestLastModifiedAge()) { + earliestLastModifiedAge = stats.getEarliestLastModifiedAge(); + } } assertThat( @@ -553,7 +557,7 @@ public class TranslogTests extends ESTestCase { equalTo(statsList.stream().mapToLong(TranslogStats::getUncommittedSizeInBytes).sum())); assertThat( total.getEarliestLastModifiedAge(), - equalTo(1L)); + equalTo(earliestLastModifiedAge)); } public void testNegativeNumberOfOperations() {