Skip to content

Commit

Permalink
[test] Print out recovery translog state (#108858)
Browse files Browse the repository at this point in the history
The test in #108037 failed only once in 3 months, it never reproduces on my machine.
Let's print the state of translog before verifying, so we have more debug information
about it if the failure ever happens again.

See #108037

* Update server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java

Co-authored-by: David Turner <david.turner@elastic.co>

---------

Co-authored-by: David Turner <david.turner@elastic.co>
  • Loading branch information
arteam and DaveCTurner committed May 22, 2024
1 parent 3911061 commit 1148861
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ private void assertNoOpRecoveries(String indexName) {
for (RecoveryState recovery : indicesAdmin().prepareRecoveries(indexName).get().shardRecoveryStates().get(indexName)) {
if (recovery.getPrimary() == false) {
assertThat(recovery.getIndex().fileDetails(), empty());
assertThat(recovery.getTranslog().totalLocal(), equalTo(recovery.getTranslog().totalOperations()));
var translog = recovery.getTranslog();
logger.info("Verifying recovery translog state: {} for index: {}", translog, indexName);
assertThat(translog.totalLocal(), equalTo(translog.totalOperations()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,17 @@ public synchronized XContentBuilder toXContent(XContentBuilder builder, Params p
builder.humanReadableField(Fields.TOTAL_TIME_IN_MILLIS, Fields.TOTAL_TIME, new TimeValue(time()));
return builder;
}

@Override
public synchronized String toString() {
return Strings.format(
"Translog{recovered=%d, total=%d, totalOnStart=%d, totalLocal=%d}",
recovered,
total,
totalOnStart,
totalLocal
);
}
}

public static class FileDetail implements ToXContentObject, Writeable {
Expand Down

0 comments on commit 1148861

Please sign in to comment.