Skip to content

Commit 6fa7af4

Browse files
committed
Add missing logic in untangle engine ctor backport
This commit adds missing logic during backporting the untangle engine constructor PR (#28245). These minor logic helps to handle an old indices which do not have all 6.x commit tags such as max_unsafe_autoid_timestamp or historyUUID or sequence numbers.
1 parent 8fc46e4 commit 6fa7af4

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.Closeable;
3535
import java.io.IOException;
3636
import java.util.Collection;
37+
import java.util.Map;
3738
import java.util.concurrent.atomic.AtomicBoolean;
3839

3940
final 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() {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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) {

server/src/main/java/org/elasticsearch/index/store/Store.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff 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
/**

0 commit comments

Comments
 (0)