Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.RestoreInProgress;
import org.elasticsearch.cluster.metadata.IndexMetadata;
Expand Down Expand Up @@ -655,39 +656,42 @@ public void testCcrRepositoryFailsToFetchSnapshotShardSizes() throws Exception {
try {
final SnapshotsInfoService snapshotsInfoService = getFollowerCluster().getCurrentMasterNodeInstance(SnapshotsInfoService.class);

final ClusterService clusterService = getFollowerCluster().getCurrentMasterNodeInstance(ClusterService.class);
final PlainActionFuture<Void> waitForAllShardSnapshotSizesFailures = new PlainActionFuture<>();
final ClusterStateListener listener = event -> {
if (RestoreInProgress.get(event.state()).isEmpty() == false && event.state().routingTable().hasIndex(followerIndex)) {
try {
final IndexRoutingTable indexRoutingTable = event.state().routingTable().index(followerIndex);
// this assertBusy completes because the listener is added after the InternalSnapshotsInfoService
// and ClusterService preserves the order of listeners.
assertBusy(() -> {
List<Long> sizes = indexRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED)
.stream()
.filter(shard -> shard.unassignedInfo().lastAllocationStatus() == AllocationStatus.FETCHING_SHARD_DATA)
.sorted(Comparator.comparingInt(ShardRouting::getId))
.map(shard -> snapshotsInfoService.snapshotShardSizes().getShardSize(shard))
.filter(Objects::nonNull)
.filter(size -> ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE == size)
.collect(Collectors.toList());
assertThat(sizes, hasSize(numberOfShards));
});
waitForAllShardSnapshotSizesFailures.onResponse(null);
} catch (Exception e) {
throw new AssertionError("Failed to retrieve all snapshot shard sizes", e);
final ClusterStateListener listener = new ClusterStateListener() {
@Override
public void clusterChanged(ClusterChangedEvent event) {
if (RestoreInProgress.get(event.state()).isEmpty() == false && event.state().routingTable().hasIndex(followerIndex)) {
try {
final IndexRoutingTable indexRoutingTable = event.state().routingTable().index(followerIndex);
// this assertBusy completes because the listener is added after the InternalSnapshotsInfoService
// and ClusterService preserves the order of listeners.
assertBusy(() -> {
List<Long> sizes = indexRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED)
.stream()
.filter(shard -> shard.unassignedInfo().lastAllocationStatus() == AllocationStatus.FETCHING_SHARD_DATA)
.sorted(Comparator.comparingInt(ShardRouting::getId))
.map(shard -> snapshotsInfoService.snapshotShardSizes().getShardSize(shard))
.filter(Objects::nonNull)
.filter(size -> ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE == size)
.collect(Collectors.toList());
assertThat(sizes, hasSize(numberOfShards));
});
clusterService.removeListener(this);
Copy link
Member Author

@ywangd ywangd Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only this line is the real change. The others are due to using anonymous class (so that it can be referenced as this) instead of lambda.

waitForAllShardSnapshotSizesFailures.onResponse(null);
} catch (Exception e) {
throw new AssertionError("Failed to retrieve all snapshot shard sizes", e);
}
}
}
};

final ClusterService clusterService = getFollowerCluster().getCurrentMasterNodeInstance(ClusterService.class);
clusterService.addListener(listener);

logger.debug("--> creating follower index [{}]", followerIndex);
followerClient().execute(PutFollowAction.INSTANCE, putFollow(leaderIndex, followerIndex, ActiveShardCount.NONE));

waitForAllShardSnapshotSizesFailures.get(30L, TimeUnit.SECONDS);
clusterService.removeListener(listener);

assertThat(simulatedFailures.get(), equalTo(numberOfShards));

Expand Down