Refresh translog stats after translog trimming in NoOpEngine (#43825)

This commit changes NoOpEngine so that it refreshes its translog 
stats once translog is trimmed.

Relates #43156
This commit is contained in:
Tanguy Leroux 2019-07-03 08:39:04 +02:00
parent 461aa39daf
commit 365dfe88ca
3 changed files with 11 additions and 1 deletions

View File

@ -158,6 +158,8 @@ public final class NoOpEngine extends ReadOnlyEngine {
try (Translog translog = new Translog(translogConfig, translogUuid, translogDeletionPolicy,
engineConfig.getGlobalCheckpointSupplier(), engineConfig.getPrimaryTermSupplier(), seqNo -> {})) {
translog.trimUnreferencedReaders();
// refresh the translog stats
this.translogStats = translog.stats();
}
}
}

View File

@ -75,13 +75,14 @@ public class ReadOnlyEngine extends Engine {
BlockTreeTermsReader.FSTLoadMode.AUTO.name());
private final SegmentInfos lastCommittedSegmentInfos;
private final SeqNoStats seqNoStats;
private final TranslogStats translogStats;
private final SearcherManager searcherManager;
private final IndexCommit indexCommit;
private final Lock indexWriterLock;
private final DocsStats docsStats;
private final RamAccountingSearcherFactory searcherFactory;
protected volatile TranslogStats translogStats;
/**
* Creates a new ReadOnlyEngine. This ctor can also be used to open a read-only engine on top of an already opened
* read-write engine. It allows to optionally obtain the writer locks for the shard which would time-out if another

View File

@ -195,8 +195,15 @@ public class NoOpEngineTests extends EngineTestCase {
}
assertThat(Translog.readMinTranslogGeneration(translogPath, translogUuid), equalTo(minFileGeneration));
assertThat(noOpEngine.getTranslogStats().estimatedNumberOfOperations(), equalTo(numDocs));
assertThat(noOpEngine.getTranslogStats().getUncommittedOperations(), equalTo(0));
noOpEngine.trimUnreferencedTranslogFiles();
assertThat(Translog.readMinTranslogGeneration(translogPath, translogUuid), equalTo(lastCommitedTranslogGeneration));
assertThat(noOpEngine.getTranslogStats().estimatedNumberOfOperations(), equalTo(0));
assertThat(noOpEngine.getTranslogStats().getUncommittedOperations(), equalTo(0));
noOpEngine.close();
}