41
41
import org .apache .lucene .store .Directory ;
42
42
import org .apache .lucene .store .LockObtainFailedException ;
43
43
import org .apache .lucene .util .BytesRef ;
44
- import org .elasticsearch .core .internal .io .IOUtils ;
45
44
import org .apache .lucene .util .InfoStream ;
46
45
import org .elasticsearch .ExceptionsHelper ;
47
- import org .elasticsearch .Version ;
48
46
import org .elasticsearch .action .index .IndexRequest ;
49
47
import org .elasticsearch .common .Nullable ;
50
48
import org .elasticsearch .common .SuppressForbidden ;
59
57
import org .elasticsearch .common .metrics .CounterMetric ;
60
58
import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
61
59
import org .elasticsearch .common .util .concurrent .ReleasableLock ;
60
+ import org .elasticsearch .core .internal .io .IOUtils ;
62
61
import org .elasticsearch .index .IndexSettings ;
63
62
import org .elasticsearch .index .VersionType ;
64
63
import org .elasticsearch .index .mapper .IdFieldMapper ;
70
69
import org .elasticsearch .index .seqno .SequenceNumbers ;
71
70
import org .elasticsearch .index .shard .ElasticsearchMergePolicy ;
72
71
import org .elasticsearch .index .shard .ShardId ;
73
- import org .elasticsearch .index .store .Store ;
74
72
import org .elasticsearch .index .translog .Translog ;
75
73
import org .elasticsearch .index .translog .TranslogConfig ;
76
74
import org .elasticsearch .index .translog .TranslogCorruptedException ;
77
75
import org .elasticsearch .index .translog .TranslogDeletionPolicy ;
78
76
import org .elasticsearch .threadpool .ThreadPool ;
79
77
80
78
import java .io .IOException ;
81
- import java .io .UncheckedIOException ;
82
- import java .util .ArrayList ;
83
79
import java .util .Arrays ;
84
80
import java .util .Collection ;
85
81
import java .util .HashMap ;
@@ -183,12 +179,10 @@ public InternalEngine(EngineConfig engineConfig) {
183
179
translog = openTranslog (engineConfig , translogDeletionPolicy , engineConfig .getGlobalCheckpointSupplier ());
184
180
assert translog .getGeneration () != null ;
185
181
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 ();
192
186
bootstrapAppendOnlyInfoFromWriter (writer );
193
187
historyUUID = loadOrGenerateHistoryUUID (writer );
194
188
Objects .requireNonNull (historyUUID , "history uuid should not be null" );
@@ -232,10 +226,11 @@ public InternalEngine(EngineConfig engineConfig) {
232
226
}
233
227
234
228
private LocalCheckpointTracker createLocalCheckpointTracker (
235
- BiFunction <Long , Long , LocalCheckpointTracker > localCheckpointTrackerSupplier , IndexCommit startingCommit ) throws IOException {
229
+ BiFunction <Long , Long , LocalCheckpointTracker > localCheckpointTrackerSupplier ) throws IOException {
236
230
final long maxSeqNo ;
237
231
final long localCheckpoint ;
238
- final SequenceNumbers .CommitInfo seqNoStats = Store .loadSeqNoInfo (startingCommit );
232
+ final SequenceNumbers .CommitInfo seqNoStats =
233
+ SequenceNumbers .loadSeqNoInfoFromLuceneCommit (store .readLastCommittedSegmentsInfo ().userData .entrySet ());
239
234
maxSeqNo = seqNoStats .maxSeqNo ;
240
235
localCheckpoint = seqNoStats .localCheckpoint ;
241
236
logger .trace ("recovered maximum sequence number [{}] and local checkpoint [{}]" , maxSeqNo , localCheckpoint );
@@ -395,31 +390,6 @@ public void skipTranslogRecovery() {
395
390
pendingTranslogRecovery .set (false ); // we are good - now we can commit
396
391
}
397
392
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
-
423
393
private void recoverFromTranslogInternal () throws IOException {
424
394
Translog .TranslogGeneration translogGeneration = translog .getGeneration ();
425
395
final int opsRecovered ;
@@ -1907,9 +1877,9 @@ private long loadCurrentVersionFromIndex(Term uid) throws IOException {
1907
1877
}
1908
1878
}
1909
1879
1910
- private IndexWriter createWriter (IndexCommit startingCommit ) throws IOException {
1880
+ private IndexWriter createWriter () throws IOException {
1911
1881
try {
1912
- final IndexWriterConfig iwc = getIndexWriterConfig (startingCommit );
1882
+ final IndexWriterConfig iwc = getIndexWriterConfig ();
1913
1883
return createWriter (store .directory (), iwc );
1914
1884
} catch (LockObtainFailedException ex ) {
1915
1885
logger .warn ("could not lock IndexWriter" , ex );
@@ -1922,11 +1892,10 @@ IndexWriter createWriter(Directory directory, IndexWriterConfig iwc) throws IOEx
1922
1892
return new IndexWriter (directory , iwc );
1923
1893
}
1924
1894
1925
- private IndexWriterConfig getIndexWriterConfig (IndexCommit startingCommit ) {
1895
+ private IndexWriterConfig getIndexWriterConfig () {
1926
1896
final IndexWriterConfig iwc = new IndexWriterConfig (engineConfig .getAnalyzer ());
1927
1897
iwc .setCommitOnClose (false ); // we by default don't commit on close
1928
1898
iwc .setOpenMode (IndexWriterConfig .OpenMode .APPEND );
1929
- iwc .setIndexCommit (startingCommit );
1930
1899
iwc .setIndexDeletionPolicy (combinedDeletionPolicy );
1931
1900
// with tests.verbose, lucene sets this up: plumb to align with filesystem stream
1932
1901
boolean verbose = false ;
0 commit comments