Skip to content

Commit

Permalink
Ensure that IndexShard is mutable before force merges (#122275)
Browse files Browse the repository at this point in the history
Closes ES-10787
  • Loading branch information
fcofdez authored Feb 12, 2025
1 parent 2b54de1 commit a0029cd
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRunnable;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.SubscribableListener;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -92,12 +93,16 @@ protected void shardOperation(
ActionListener<TransportBroadcastByNodeAction.EmptyResult> listener
) {
assert (task instanceof CancellableTask) == false; // TODO: add cancellation handling here once the task supports it
threadPool.executor(ThreadPool.Names.FORCE_MERGE).execute(ActionRunnable.supply(listener, () -> {
SubscribableListener.<IndexShard>newForked(l -> {
IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex())
.getShard(shardRouting.shardId().id());
indexShard.forceMerge(request);
return EmptyResult.INSTANCE;
}));
indexShard.ensureMutable(l.map(unused -> indexShard));
}).<EmptyResult>andThen((l, indexShard) -> {
threadPool.executor(ThreadPool.Names.FORCE_MERGE).execute(ActionRunnable.supply(l, () -> {
indexShard.forceMerge(request);
return EmptyResult.INSTANCE;
}));
}).addListener(listener);
}

/**
Expand Down

0 comments on commit a0029cd

Please sign in to comment.