Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that IndexShard is mutable before force merges #122275

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all 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 @@ -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 -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: seems to be neater to initialize indexShard and use SubscribableListener<Void> for indexShard.ensureMutable?

IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(shardRouting.shardId().id());
SubscribableListener.<Void>newForked(l -> indexShard.ensureMutable(l))
    .<EmptyResult>andThen(l -> threadPool.executor(ThreadPool.Names.FORCE_MERGE).execute(ActionRunnable.supply(l, () -> {
        indexShard.forceMerge(request);
        return EmptyResult.INSTANCE;
    })))
    .addListener(listener);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to do the error handling when the index doesn't exist in the node anymore, that's why I included it in the listener.

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