Skip to content

Commit 22575bd

Browse files
committed
Remove isRecovering method from Engine (#47039)
We already prevent flushing in Engine if it's recovering. Hence, we can remove the protection in IndexShard.
1 parent c4a166f commit 22575bd

File tree

4 files changed

+12
-32
lines changed

4 files changed

+12
-32
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,13 +1874,6 @@ public interface Warmer {
18741874
*/
18751875
public abstract void skipTranslogRecovery();
18761876

1877-
/**
1878-
* Returns <code>true</code> iff this engine is currently recovering from translog.
1879-
*/
1880-
public boolean isRecovering() {
1881-
return false;
1882-
}
1883-
18841877
/**
18851878
* Tries to prune buffered deletes from the version map.
18861879
*/

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ protected void commitIndexWriter(final IndexWriter writer, final Translog transl
24612461
}
24622462
}
24632463

2464-
private void ensureCanFlush() {
2464+
final void ensureCanFlush() {
24652465
// translog recover happens after the engine is fully constructed
24662466
// if we are in this stage we have to prevent flushes from this
24672467
// engine otherwise we might loose documents if the flush succeeds
@@ -2659,11 +2659,6 @@ public Closeable acquireRetentionLock() {
26592659
}
26602660
}
26612661

2662-
@Override
2663-
public boolean isRecovering() {
2664-
return pendingTranslogRecovery.get();
2665-
}
2666-
26672662
/**
26682663
* Gets the commit data from {@link IndexWriter} as a map.
26692664
*/

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,7 @@ public CompletionStats completionStats(String... fields) {
10541054
public Engine.SyncedFlushResult syncFlush(String syncId, Engine.CommitId expectedCommitId) {
10551055
verifyNotClosed();
10561056
logger.trace("trying to sync flush. sync id [{}]. expected commit id [{}]]", syncId, expectedCommitId);
1057-
Engine engine = getEngine();
1058-
if (engine.isRecovering()) {
1059-
throw new IllegalIndexShardStateException(shardId(), state, "syncFlush is only allowed if the engine is not recovery" +
1060-
" from translog");
1061-
}
1062-
return engine.syncFlush(syncId, expectedCommitId);
1057+
return getEngine().syncFlush(syncId, expectedCommitId);
10631058
}
10641059

10651060
/**
@@ -1078,15 +1073,8 @@ public Engine.CommitId flush(FlushRequest request) {
10781073
* since we use Engine#writeIndexingBuffer for this now.
10791074
*/
10801075
verifyNotClosed();
1081-
final Engine engine = getEngine();
1082-
if (engine.isRecovering()) {
1083-
throw new IllegalIndexShardStateException(
1084-
shardId(),
1085-
state,
1086-
"flush is only allowed if the engine is not recovery from translog");
1087-
}
10881076
final long time = System.nanoTime();
1089-
final Engine.CommitId commitId = engine.flush(force, waitIfOngoing);
1077+
final Engine.CommitId commitId = getEngine().flush(force, waitIfOngoing);
10901078
flushMetric.inc(System.nanoTime() - time);
10911079
return commitId;
10921080
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,16 +729,20 @@ public long getProcessedCheckpoint() {
729729
}
730730

731731
public void testFlushIsDisabledDuringTranslogRecovery() throws IOException {
732-
assertFalse(engine.isRecovering());
732+
engine.ensureCanFlush(); // recovered already
733733
ParsedDocument doc = testParsedDocument("1", null, testDocumentWithTextField(), SOURCE, null);
734734
engine.index(indexForDoc(doc));
735735
engine.close();
736736

737737
engine = new InternalEngine(engine.config());
738+
expectThrows(IllegalStateException.class, engine::ensureCanFlush);
738739
expectThrows(IllegalStateException.class, () -> engine.flush(true, true));
739-
assertTrue(engine.isRecovering());
740-
engine.recoverFromTranslog(translogHandler, Long.MAX_VALUE);
741-
assertFalse(engine.isRecovering());
740+
if (randomBoolean()) {
741+
engine.recoverFromTranslog(translogHandler, Long.MAX_VALUE);
742+
} else {
743+
engine.skipTranslogRecovery();
744+
}
745+
engine.ensureCanFlush(); // ready
742746
doc = testParsedDocument("2", null, testDocumentWithTextField(), SOURCE, null);
743747
engine.index(indexForDoc(doc));
744748
engine.flush();
@@ -2825,7 +2829,7 @@ public void testCurrentTranslogIDisCommitted() throws IOException {
28252829
{
28262830
for (int i = 0; i < 2; i++) {
28272831
try (InternalEngine engine = new InternalEngine(config)) {
2828-
assertTrue(engine.isRecovering());
2832+
expectThrows(IllegalStateException.class, engine::ensureCanFlush);
28292833
Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
28302834
if (i == 0) {
28312835
assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));

0 commit comments

Comments
 (0)