Skip to content

Commit 67a486e

Browse files
committed
Apply feedback (2)
1 parent d6ce8a1 commit 67a486e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.lucene.search.SearcherManager;
3131
import org.apache.lucene.store.Directory;
3232
import org.apache.lucene.store.Lock;
33+
import org.elasticsearch.Assertions;
3334
import org.elasticsearch.Version;
3435
import org.elasticsearch.common.lucene.Lucene;
3536
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
@@ -111,7 +112,7 @@ public ReadOnlyEngine(EngineConfig config, SeqNoStats seqNoStats, TranslogStats
111112
if (globalCheckpoint != SequenceNumbers.UNASSIGNED_SEQ_NO
112113
&& engineConfig.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_7_0)) {
113114
if (seqNoStats.getMaxSeqNo() != globalCheckpoint) {
114-
assert false : "max seq. no. [" + seqNoStats.getMaxSeqNo() + "] does not match [" + globalCheckpoint + "]";
115+
assertMaxSeqNoEqualsToGlobalCheckpoint(seqNoStats.getMaxSeqNo(), globalCheckpoint);
115116
throw new IllegalStateException("Maximum sequence number [" + seqNoStats.getMaxSeqNo()
116117
+ "] from last commit does not match global checkpoint [" + globalCheckpoint + "]");
117118
}
@@ -135,6 +136,12 @@ public ReadOnlyEngine(EngineConfig config, SeqNoStats seqNoStats, TranslogStats
135136
}
136137
}
137138

139+
protected void assertMaxSeqNoEqualsToGlobalCheckpoint(final long maxSeqNo, final long globalCheckpoint) {
140+
if (Assertions.ENABLED) {
141+
assert false : "max seq. no. [" + maxSeqNo + "] does not match [" + globalCheckpoint + "]";
142+
}
143+
}
144+
138145
protected final DirectoryReader wrapReader(DirectoryReader reader,
139146
Function<DirectoryReader, DirectoryReader> readerWrapperFunction) throws IOException {
140147
reader = ElasticsearchDirectoryReader.wrap(reader, engineConfig.getShardId());

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ public void testEnsureMaxSeqNoIsEqualToGlobalCheckpoint() throws IOException {
159159
engine.flushAndClose();
160160

161161
IllegalStateException exception = expectThrows(IllegalStateException.class,
162-
() -> new ReadOnlyEngine(engine.engineConfig, null, null, true, Function.identity()));
162+
() -> new ReadOnlyEngine(engine.engineConfig, null, null, true, Function.identity()) {
163+
@Override
164+
protected void assertMaxSeqNoEqualsToGlobalCheckpoint(final long maxSeqNo, final long globalCheckpoint) {
165+
// we don't want the assertion to trip in this test
166+
}
167+
});
163168
assertThat(exception.getMessage(), equalTo("Maximum sequence number [" + maxSeqNo
164169
+ "] from last commit does not match global checkpoint [" + globalCheckpoint.get() + "]"));
165170
} finally {

0 commit comments

Comments
 (0)