Skip to content

Commit d87c9fd

Browse files
authored
Refresh translog stats after translog trimming in NoOpEngine (elastic#43825)
This commit changes NoOpEngine so that it refreshes its translog stats once translog is trimmed. Relates elastic#43156
1 parent 539a120 commit d87c9fd

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

server/src/main/java/org/elasticsearch/index/engine/NoOpEngine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ public void trimUnreferencedTranslogFiles() {
158158
try (Translog translog = new Translog(translogConfig, translogUuid, translogDeletionPolicy,
159159
engineConfig.getGlobalCheckpointSupplier(), engineConfig.getPrimaryTermSupplier(), seqNo -> {})) {
160160
translog.trimUnreferencedReaders();
161+
// refresh the translog stats
162+
this.translogStats = translog.stats();
161163
}
162164
}
163165
}

server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ public class ReadOnlyEngine extends Engine {
7575
BlockTreeTermsReader.FSTLoadMode.AUTO.name());
7676
private final SegmentInfos lastCommittedSegmentInfos;
7777
private final SeqNoStats seqNoStats;
78-
private final TranslogStats translogStats;
7978
private final SearcherManager searcherManager;
8079
private final IndexCommit indexCommit;
8180
private final Lock indexWriterLock;
8281
private final DocsStats docsStats;
8382
private final RamAccountingSearcherFactory searcherFactory;
8483

84+
protected volatile TranslogStats translogStats;
85+
8586
/**
8687
* Creates a new ReadOnlyEngine. This ctor can also be used to open a read-only engine on top of an already opened
8788
* read-write engine. It allows to optionally obtain the writer locks for the shard which would time-out if another

server/src/test/java/org/elasticsearch/index/engine/NoOpEngineTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,15 @@ public void testTrimUnreferencedTranslogFiles() throws Exception {
195195
}
196196

197197
assertThat(Translog.readMinTranslogGeneration(translogPath, translogUuid), equalTo(minFileGeneration));
198+
assertThat(noOpEngine.getTranslogStats().estimatedNumberOfOperations(), equalTo(numDocs));
199+
assertThat(noOpEngine.getTranslogStats().getUncommittedOperations(), equalTo(0));
200+
198201
noOpEngine.trimUnreferencedTranslogFiles();
202+
199203
assertThat(Translog.readMinTranslogGeneration(translogPath, translogUuid), equalTo(lastCommitedTranslogGeneration));
204+
assertThat(noOpEngine.getTranslogStats().estimatedNumberOfOperations(), equalTo(0));
205+
assertThat(noOpEngine.getTranslogStats().getUncommittedOperations(), equalTo(0));
206+
200207
noOpEngine.close();
201208
}
202209

0 commit comments

Comments
 (0)