File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed
server/src/main/java/org/elasticsearch/index Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 3434import java .io .Closeable ;
3535import java .io .IOException ;
3636import java .util .Collection ;
37+ import java .util .Map ;
3738import java .util .concurrent .atomic .AtomicBoolean ;
3839
3940final class LocalShardSnapshot implements Closeable {
@@ -66,7 +67,8 @@ long maxSeqNo() {
6667 }
6768
6869 long maxUnsafeAutoIdTimestamp () {
69- return Long .parseLong (shard .getEngine ().commitStats ().getUserData ().get (InternalEngine .MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID ));
70+ final Map <String , String > commitUserData = shard .getEngine ().commitStats ().getUserData ();
71+ return Long .parseLong (commitUserData .getOrDefault (InternalEngine .MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID , "-1" ));
7072 }
7173
7274 Directory getSnapshotDirectory () {
Original file line number Diff line number Diff line change @@ -396,10 +396,12 @@ private void internalRecoverFromStore(IndexShard indexShard) throws IndexShardRe
396396 final String translogUUID = Translog .createEmptyTranslog (indexShard .shardPath ().resolveTranslog (), maxSeqNo , shardId );
397397 store .associateIndexWithNewTranslog (translogUUID );
398398 } else if (indexShouldExists ) {
399- // since we recover from local, just fill the files and size
400399 if (indexShard .indexSettings ().getIndexVersionCreated ().before (Version .V_6_0_0_rc1 )) {
401- store .ensureIndexHasHistoryUUIDAndSeqNo ();
400+ if (store .ensureIndexHasHistoryUUIDAndSeqNo ()) {
401+ si = store .readLastCommittedSegmentsInfo (); // new commit is flushed - refresh SegmentInfo.
402+ }
402403 }
404+ // since we recover from local, just fill the files and size
403405 try {
404406 final RecoveryState .Index index = recoveryState .getIndex ();
405407 if (si != null ) {
Original file line number Diff line number Diff line change @@ -1517,13 +1517,14 @@ public void associateIndexWithNewTranslog(final String translogUUID) throws IOEx
15171517 }
15181518 }
15191519
1520-
15211520 /**
1522- * A 5.x index does not have either historyUUDID or sequence number markers as both markers are introduced in 6.0+.
1521+ * A 5.x index does not have either historyUUDID or sequence number markers as these markers are introduced in 6.0+.
15231522 * This method should be called only in local store recovery or file-based recovery to ensure an index has proper
15241523 * historyUUID and sequence number markers before opening an engine.
1524+ *
1525+ * @return <code>true</code> if a new commit is flushed, otherwise return false
15251526 */
1526- public void ensureIndexHasHistoryUUIDAndSeqNo () throws IOException {
1527+ public boolean ensureIndexHasHistoryUUIDAndSeqNo () throws IOException {
15271528 metadataLock .writeLock ().lock ();
15281529 try (IndexWriter writer = newIndexWriter (IndexWriterConfig .OpenMode .APPEND , directory , null )) {
15291530 final Map <String , String > userData = getUserData (writer );
@@ -1539,10 +1540,12 @@ public void ensureIndexHasHistoryUUIDAndSeqNo() throws IOException {
15391540 }
15401541 if (maps .isEmpty () == false ) {
15411542 updateCommitData (writer , maps );
1543+ return true ;
15421544 }
15431545 } finally {
15441546 metadataLock .writeLock ().unlock ();
15451547 }
1548+ return false ;
15461549 }
15471550
15481551 /**
You can’t perform that action at this time.
0 commit comments