From 2b33dee783e2a39b063fa906db0d028fbb9162aa Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 13 Oct 2023 14:59:51 +0100 Subject: [PATCH] Compute shardStateId before addAbortListener (#100809) (#100831) It is not valid to call `SnapshotIndexCommit#indexCommit()` if the snapshot is aborted, so we must compute `shardStateId` before adding the abort listener. Closes #99477 --- .../org/elasticsearch/snapshots/SnapshotShardsService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java index bdd7fbd999a7b..5765b0fc4b99a 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java @@ -383,6 +383,7 @@ private void snapshot( SnapshotIndexCommit snapshotIndexCommit = null; try { snapshotIndexCommit = new SnapshotIndexCommit(indexShard.acquireIndexCommitForSnapshot()); + final var shardStateId = getShardStateId(indexShard, snapshotIndexCommit.indexCommit()); // not aborted so indexCommit() ok snapshotStatus.addAbortListener(makeAbortListener(indexShard.shardId(), snapshot, snapshotIndexCommit)); snapshotStatus.ensureNotAborted(); repository.snapshotShard( @@ -392,7 +393,7 @@ private void snapshot( snapshot.getSnapshotId(), indexId, snapshotIndexCommit, - getShardStateId(indexShard, snapshotIndexCommit.indexCommit()), + shardStateId, snapshotStatus, version, entryStartTime,