Skip to content

Commit

Permalink
Fix the earliest last modified age of translog stats (#64753)
Browse files Browse the repository at this point in the history
Currently translog's `earliest_last_modified_age` field is always 0 in `_nodes/stats` response.
  • Loading branch information
howardhuanghua authored and dnhatn committed Nov 30, 2020
1 parent 2eee124 commit a4e3c68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ public void add(TranslogStats translogStats) {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,18 @@ public void testUncommittedOperations() throws Exception {

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(
Expand All @@ -567,7 +571,7 @@ public void testTotalTests() {
equalTo(statsList.stream().mapToLong(TranslogStats::getUncommittedSizeInBytes).sum()));
assertThat(
total.getEarliestLastModifiedAge(),
equalTo(1L));
equalTo(earliestLastModifiedAge));
}

public void testNegativeNumberOfOperations() {
Expand Down

0 comments on commit a4e3c68

Please sign in to comment.