4141import org .apache .lucene .store .Directory ;
4242import org .apache .lucene .store .LockObtainFailedException ;
4343import org .apache .lucene .util .BytesRef ;
44- import org .elasticsearch .core .internal .io .IOUtils ;
4544import org .apache .lucene .util .InfoStream ;
4645import org .elasticsearch .ExceptionsHelper ;
47- import org .elasticsearch .Version ;
4846import org .elasticsearch .action .index .IndexRequest ;
4947import org .elasticsearch .common .Nullable ;
5048import org .elasticsearch .common .SuppressForbidden ;
5957import org .elasticsearch .common .metrics .CounterMetric ;
6058import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
6159import org .elasticsearch .common .util .concurrent .ReleasableLock ;
60+ import org .elasticsearch .core .internal .io .IOUtils ;
6261import org .elasticsearch .index .IndexSettings ;
6362import org .elasticsearch .index .VersionType ;
6463import org .elasticsearch .index .mapper .IdFieldMapper ;
7069import org .elasticsearch .index .seqno .SequenceNumbers ;
7170import org .elasticsearch .index .shard .ElasticsearchMergePolicy ;
7271import org .elasticsearch .index .shard .ShardId ;
73- import org .elasticsearch .index .store .Store ;
7472import org .elasticsearch .index .translog .Translog ;
7573import org .elasticsearch .index .translog .TranslogConfig ;
7674import org .elasticsearch .index .translog .TranslogCorruptedException ;
7775import org .elasticsearch .index .translog .TranslogDeletionPolicy ;
7876import org .elasticsearch .threadpool .ThreadPool ;
7977
8078import java .io .IOException ;
81- import java .io .UncheckedIOException ;
82- import java .util .ArrayList ;
8379import java .util .Arrays ;
8480import java .util .Collection ;
8581import java .util .HashMap ;
@@ -183,12 +179,10 @@ public InternalEngine(EngineConfig engineConfig) {
183179 translog = openTranslog (engineConfig , translogDeletionPolicy , engineConfig .getGlobalCheckpointSupplier ());
184180 assert translog .getGeneration () != null ;
185181 this .translog = translog ;
186- final IndexCommit startingCommit = getStartingCommitPoint ();
187- assert startingCommit != null : "Starting commit should be non-null" ;
188- this .localCheckpointTracker = createLocalCheckpointTracker (localCheckpointTrackerSupplier , startingCommit );
189- this .combinedDeletionPolicy = new CombinedDeletionPolicy (logger , translogDeletionPolicy ,
190- translog ::getLastSyncedGlobalCheckpoint , startingCommit );
191- writer = createWriter (startingCommit );
182+ this .localCheckpointTracker = createLocalCheckpointTracker (localCheckpointTrackerSupplier );
183+ this .combinedDeletionPolicy =
184+ new CombinedDeletionPolicy (logger , translogDeletionPolicy , translog ::getLastSyncedGlobalCheckpoint );
185+ writer = createWriter ();
192186 bootstrapAppendOnlyInfoFromWriter (writer );
193187 historyUUID = loadOrGenerateHistoryUUID (writer );
194188 Objects .requireNonNull (historyUUID , "history uuid should not be null" );
@@ -232,10 +226,11 @@ public InternalEngine(EngineConfig engineConfig) {
232226 }
233227
234228 private LocalCheckpointTracker createLocalCheckpointTracker (
235- BiFunction <Long , Long , LocalCheckpointTracker > localCheckpointTrackerSupplier , IndexCommit startingCommit ) throws IOException {
229+ BiFunction <Long , Long , LocalCheckpointTracker > localCheckpointTrackerSupplier ) throws IOException {
236230 final long maxSeqNo ;
237231 final long localCheckpoint ;
238- final SequenceNumbers .CommitInfo seqNoStats = Store .loadSeqNoInfo (startingCommit );
232+ final SequenceNumbers .CommitInfo seqNoStats =
233+ SequenceNumbers .loadSeqNoInfoFromLuceneCommit (store .readLastCommittedSegmentsInfo ().userData .entrySet ());
239234 maxSeqNo = seqNoStats .maxSeqNo ;
240235 localCheckpoint = seqNoStats .localCheckpoint ;
241236 logger .trace ("recovered maximum sequence number [{}] and local checkpoint [{}]" , maxSeqNo , localCheckpoint );
@@ -395,31 +390,6 @@ public void skipTranslogRecovery() {
395390 pendingTranslogRecovery .set (false ); // we are good - now we can commit
396391 }
397392
398- private IndexCommit getStartingCommitPoint () throws IOException {
399- final IndexCommit startingIndexCommit ;
400- final long lastSyncedGlobalCheckpoint = translog .getLastSyncedGlobalCheckpoint ();
401- final long minRetainedTranslogGen = translog .getMinFileGeneration ();
402- final List <IndexCommit > existingCommits = DirectoryReader .listCommits (store .directory ());
403- // We may not have a safe commit if an index was create before v6.2; and if there is a snapshotted commit whose translog
404- // are not retained but max_seqno is at most the global checkpoint, we may mistakenly select it as a starting commit.
405- // To avoid this issue, we only select index commits whose translog are fully retained.
406- if (engineConfig .getIndexSettings ().getIndexVersionCreated ().before (Version .V_6_2_0 )) {
407- final List <IndexCommit > recoverableCommits = new ArrayList <>();
408- for (IndexCommit commit : existingCommits ) {
409- if (minRetainedTranslogGen <= Long .parseLong (commit .getUserData ().get (Translog .TRANSLOG_GENERATION_KEY ))) {
410- recoverableCommits .add (commit );
411- }
412- }
413- assert recoverableCommits .isEmpty () == false : "No commit point with translog found; " +
414- "commits [" + existingCommits + "], minRetainedTranslogGen [" + minRetainedTranslogGen + "]" ;
415- startingIndexCommit = CombinedDeletionPolicy .findSafeCommitPoint (recoverableCommits , lastSyncedGlobalCheckpoint );
416- } else {
417- // TODO: Asserts the starting commit is a safe commit once peer-recovery sets global checkpoint.
418- startingIndexCommit = CombinedDeletionPolicy .findSafeCommitPoint (existingCommits , lastSyncedGlobalCheckpoint );
419- }
420- return startingIndexCommit ;
421- }
422-
423393 private void recoverFromTranslogInternal () throws IOException {
424394 Translog .TranslogGeneration translogGeneration = translog .getGeneration ();
425395 final int opsRecovered ;
@@ -1907,9 +1877,9 @@ private long loadCurrentVersionFromIndex(Term uid) throws IOException {
19071877 }
19081878 }
19091879
1910- private IndexWriter createWriter (IndexCommit startingCommit ) throws IOException {
1880+ private IndexWriter createWriter () throws IOException {
19111881 try {
1912- final IndexWriterConfig iwc = getIndexWriterConfig (startingCommit );
1882+ final IndexWriterConfig iwc = getIndexWriterConfig ();
19131883 return createWriter (store .directory (), iwc );
19141884 } catch (LockObtainFailedException ex ) {
19151885 logger .warn ("could not lock IndexWriter" , ex );
@@ -1922,11 +1892,10 @@ IndexWriter createWriter(Directory directory, IndexWriterConfig iwc) throws IOEx
19221892 return new IndexWriter (directory , iwc );
19231893 }
19241894
1925- private IndexWriterConfig getIndexWriterConfig (IndexCommit startingCommit ) {
1895+ private IndexWriterConfig getIndexWriterConfig () {
19261896 final IndexWriterConfig iwc = new IndexWriterConfig (engineConfig .getAnalyzer ());
19271897 iwc .setCommitOnClose (false ); // we by default don't commit on close
19281898 iwc .setOpenMode (IndexWriterConfig .OpenMode .APPEND );
1929- iwc .setIndexCommit (startingCommit );
19301899 iwc .setIndexDeletionPolicy (combinedDeletionPolicy );
19311900 // with tests.verbose, lucene sets this up: plumb to align with filesystem stream
19321901 boolean verbose = false ;
0 commit comments