Fix the earliest last modified age of translog stats (#64753)
Currently translog's `earliest_last_modified_age` field is always 0 in `_nodes/stats` response.
This commit is contained in:
parent
154c579e9b
commit
0137c1679b
|
@ -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() {
|
||||
|
|
|
@ -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<TranslogStats> 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() {
|
||||
|
|
Loading…
Reference in New Issue