Skip to content

Commit f416688

Browse files
authored
Fix double-pausing shard snapshot (#109148)
Closes #109143
1 parent 92f8935 commit f416688

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

docs/changelog/109148.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 109148
2+
summary: Fix double-pausing shard snapshot
3+
area: Snapshot/Restore
4+
type: bug
5+
issues:
6+
- 109143

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,15 @@ private <T> void executeShardSnapshotUpdate(
33543354
updatedState = updateSnapshotState.updatedState;
33553355
}
33563356

3357+
if (updatedState.state() == ShardState.PAUSED_FOR_NODE_REMOVAL) {
3358+
// leave subsequent entries for this shard alone until this one is unpaused
3359+
iterator.remove();
3360+
} else {
3361+
// All other shard updates leave the shard in a complete state, which means we should leave this update in the list so
3362+
// it can fall through to later entries and start any waiting shard snapshots:
3363+
assert updatedState.isActive() == false : updatedState;
3364+
}
3365+
33573366
logger.trace("[{}] Updating shard [{}] with status [{}]", updateSnapshotState.snapshot, updatedShard, updatedState.state());
33583367
changedCount++;
33593368
newStates.get().put(updatedShard, updatedState);

server/src/test/java/org/elasticsearch/snapshots/SnapshotsServiceTests.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,70 @@ public void testCompletedCloneStartsNextClone() throws Exception {
401401
assertIsNoop(updatedClusterState, completeShardClone);
402402
}
403403

404+
public void testPauseForNodeRemovalWithQueuedShards() throws Exception {
405+
final var repoName = "test-repo";
406+
final var snapshot1 = snapshot(repoName, "snap-1");
407+
final var snapshot2 = snapshot(repoName, "snap-2");
408+
final var indexName = "index-1";
409+
final var shardId = new ShardId(index(indexName), 0);
410+
final var repositoryShardId = new RepositoryShardId(indexId(indexName), 0);
411+
final var nodeId = uuid();
412+
413+
final var runningEntry = snapshotEntry(
414+
snapshot1,
415+
Collections.singletonMap(indexName, repositoryShardId.index()),
416+
Map.of(shardId, initShardStatus(nodeId))
417+
);
418+
419+
final var queuedEntry = snapshotEntry(
420+
snapshot2,
421+
Collections.singletonMap(indexName, repositoryShardId.index()),
422+
Map.of(shardId, SnapshotsInProgress.ShardSnapshotStatus.UNASSIGNED_QUEUED)
423+
);
424+
425+
final var initialState = stateWithSnapshots(
426+
ClusterState.builder(ClusterState.EMPTY_STATE)
427+
.nodes(DiscoveryNodes.builder().add(DiscoveryNodeUtils.create(nodeId)).localNodeId(nodeId).masterNodeId(nodeId).build())
428+
.routingTable(
429+
RoutingTable.builder()
430+
.add(
431+
IndexRoutingTable.builder(shardId.getIndex())
432+
.addShard(TestShardRouting.newShardRouting(shardId, nodeId, true, ShardRoutingState.STARTED))
433+
)
434+
.build()
435+
)
436+
.build(),
437+
repoName,
438+
runningEntry,
439+
queuedEntry
440+
);
441+
442+
final var updatedState = applyUpdates(
443+
initialState,
444+
new SnapshotsService.ShardSnapshotUpdate(
445+
snapshot1,
446+
shardId,
447+
null,
448+
new SnapshotsInProgress.ShardSnapshotStatus(
449+
nodeId,
450+
SnapshotsInProgress.ShardState.PAUSED_FOR_NODE_REMOVAL,
451+
runningEntry.shards().get(shardId).generation()
452+
),
453+
ActionTestUtils.assertNoFailureListener(t -> {})
454+
)
455+
);
456+
457+
assertEquals(
458+
SnapshotsInProgress.ShardState.PAUSED_FOR_NODE_REMOVAL,
459+
SnapshotsInProgress.get(updatedState).snapshot(snapshot1).shards().get(shardId).state()
460+
);
461+
462+
assertEquals(
463+
SnapshotsInProgress.ShardState.QUEUED,
464+
SnapshotsInProgress.get(updatedState).snapshot(snapshot2).shards().get(shardId).state()
465+
);
466+
}
467+
404468
public void testSnapshottingIndicesExcludesClones() {
405469
final String repoName = "test-repo";
406470
final String indexName = "index";

0 commit comments

Comments
 (0)