diff --git a/server/src/main/java/org/elasticsearch/index/engine/NoOpEngine.java b/server/src/main/java/org/elasticsearch/index/engine/NoOpEngine.java index 007a13351df..2244dd57037 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/NoOpEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/NoOpEngine.java @@ -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(); } } } diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index d28cd9610b1..57df9f29590 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -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 diff --git a/server/src/test/java/org/elasticsearch/index/engine/NoOpEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/NoOpEngineTests.java index f45eab0e057..bd934f683fb 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/NoOpEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/NoOpEngineTests.java @@ -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(); }