Skip to content

Commit 29091e8

Browse files
authored
Refactor the new snapshot code in Engine (#95364)
Relates ES-5058 Revert "Ability to add extra user data for lucene commits (#95073)" This reverts commit 192b4aa. Relates ES-5849
1 parent 4da8055 commit 29091e8

File tree

2 files changed

+6
-38
lines changed

2 files changed

+6
-38
lines changed

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private void recoverFromTranslogInternal(TranslogRecoveryRunner translogRecovery
538538
final int opsRecovered;
539539
final long localCheckpoint = getProcessedLocalCheckpoint();
540540
if (localCheckpoint < recoverUpToSeqNo) {
541-
try (Translog.Snapshot snapshot = translog.newSnapshot(localCheckpoint + 1, recoverUpToSeqNo)) {
541+
try (Translog.Snapshot snapshot = newTranslogSnapshot(localCheckpoint + 1, recoverUpToSeqNo)) {
542542
opsRecovered = translogRecoveryRunner.run(this, snapshot);
543543
} catch (Exception e) {
544544
throw new EngineException(shardId, "failed to recover from translog", e);
@@ -561,6 +561,10 @@ private void recoverFromTranslogInternal(TranslogRecoveryRunner translogRecovery
561561
translog.trimUnreferencedReaders();
562562
}
563563

564+
protected Translog.Snapshot newTranslogSnapshot(long fromSeqNo, long toSeqNo) throws IOException {
565+
return translog.newSnapshot(fromSeqNo, toSeqNo);
566+
}
567+
564568
private Translog openTranslog(
565569
EngineConfig engineConfig,
566570
TranslogDeletionPolicy translogDeletionPolicy,
@@ -2666,20 +2670,6 @@ protected void doRun() throws Exception {
26662670
}
26672671
}
26682672

2669-
/**
2670-
* Defines extra user data to be stored in a commit file.
2671-
*
2672-
* Note that:
2673-
* <ul>
2674-
* <li>Any conflicting keys used internally by the engine or the store will prevail.</li>
2675-
* <li>The extra user data will not be present in an empty commit.</li>
2676-
* <li>This function is temporary and may be removed in the future.</li>
2677-
* </ul>
2678-
*/
2679-
protected Map<String, String> getCommitExtraUserData() {
2680-
return Map.of();
2681-
}
2682-
26832673
/**
26842674
* Commits the specified index writer.
26852675
*
@@ -2700,9 +2690,7 @@ protected void commitIndexWriter(final IndexWriter writer, final Translog transl
27002690
* {@link IndexWriter#commit()} call flushes all documents, we defer computation of the maximum sequence number to the time
27012691
* of invocation of the commit data iterator (which occurs after all documents have been flushed to Lucene).
27022692
*/
2703-
final Map<String, String> extraCommitUserData = getCommitExtraUserData();
2704-
final Map<String, String> commitData = Maps.newMapWithExpectedSize(8 + extraCommitUserData.size());
2705-
commitData.putAll(extraCommitUserData);
2693+
final Map<String, String> commitData = Maps.newMapWithExpectedSize(8);
27062694
commitData.put(Translog.TRANSLOG_UUID_KEY, translog.getTranslogUUID());
27072695
commitData.put(SequenceNumbers.LOCAL_CHECKPOINT_KEY, Long.toString(localCheckpoint));
27082696
commitData.put(SequenceNumbers.MAX_SEQ_NO, Long.toString(localCheckpointTracker.getMaxSeqNo()));

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@
196196
import static org.hamcrest.Matchers.equalTo;
197197
import static org.hamcrest.Matchers.greaterThan;
198198
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
199-
import static org.hamcrest.Matchers.hasEntry;
200199
import static org.hamcrest.Matchers.hasItem;
201200
import static org.hamcrest.Matchers.hasKey;
202201
import static org.hamcrest.Matchers.hasSize;
@@ -7402,25 +7401,6 @@ public void testCurrentVersionIsCommitted() throws IOException {
74027401
}
74037402
}
74047403

7405-
public void testExtraUserDataIsCommitted() throws IOException {
7406-
engine.close();
7407-
engine = new InternalEngine(engine.config()) {
7408-
@Override
7409-
protected Map<String, String> getCommitExtraUserData() {
7410-
return Map.of("userkey", "userdata", ES_VERSION, Version.V_EMPTY.toString());
7411-
}
7412-
};
7413-
engine.skipTranslogRecovery();
7414-
7415-
ParsedDocument doc = testParsedDocument("1", null, testDocumentWithTextField(), SOURCE, null);
7416-
engine.index(indexForDoc(doc));
7417-
engine.flush();
7418-
7419-
Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
7420-
assertThat(userData, hasEntry("userkey", "userdata"));
7421-
assertThat(userData, hasEntry(ES_VERSION, Version.CURRENT.toString()));
7422-
}
7423-
74247404
public void testTrimUnsafeCommitHasESVersionInUserData() throws IOException {
74257405
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
74267406
final int maxSeqNo = 40;

0 commit comments

Comments
 (0)