Skip to content

Commit a0029cd

Browse files
authored
Ensure that IndexShard is mutable before force merges (#122275)
Closes ES-10787
1 parent 2b54de1 commit a0029cd

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.ActionListener;
1313
import org.elasticsearch.action.ActionRunnable;
1414
import org.elasticsearch.action.support.ActionFilters;
15+
import org.elasticsearch.action.support.SubscribableListener;
1516
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
1617
import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction;
1718
import org.elasticsearch.cluster.ClusterState;
@@ -92,12 +93,16 @@ protected void shardOperation(
9293
ActionListener<TransportBroadcastByNodeAction.EmptyResult> listener
9394
) {
9495
assert (task instanceof CancellableTask) == false; // TODO: add cancellation handling here once the task supports it
95-
threadPool.executor(ThreadPool.Names.FORCE_MERGE).execute(ActionRunnable.supply(listener, () -> {
96+
SubscribableListener.<IndexShard>newForked(l -> {
9697
IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex())
9798
.getShard(shardRouting.shardId().id());
98-
indexShard.forceMerge(request);
99-
return EmptyResult.INSTANCE;
100-
}));
99+
indexShard.ensureMutable(l.map(unused -> indexShard));
100+
}).<EmptyResult>andThen((l, indexShard) -> {
101+
threadPool.executor(ThreadPool.Names.FORCE_MERGE).execute(ActionRunnable.supply(l, () -> {
102+
indexShard.forceMerge(request);
103+
return EmptyResult.INSTANCE;
104+
}));
105+
}).addListener(listener);
101106
}
102107

103108
/**

0 commit comments

Comments
 (0)