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

Do not refresh all indices in TransportBulkAction #93417

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions docs/changelog/93417.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 93417
summary: Do not refresh all indices in `TransportBulkAction`
area: CRUD
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.IndexRouting;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.core.Releasable;
Expand Down Expand Up @@ -197,15 +198,19 @@ protected void doExecute(Task task, BulkRequest bulkRequest, ActionListener<Bulk
// TODO: Replace with a less hacky approach.
ActionListener<BulkResponse> listener = outerListener;
if (DiscoveryNode.isStateless(clusterService.getSettings()) && bulkRequest.getRefreshPolicy() != WriteRequest.RefreshPolicy.NONE) {
listener = outerListener.delegateFailure((l, r) -> client.admin().indices().prepareRefresh().execute(l.map(ignored -> {
listener = outerListener.delegateFailure((l, r) -> {
final Set<String> indices = new HashSet<>();
for (BulkItemResponse response : r.getItems()) {
if (response.isFailed() == false) {
indices.add(response.getIndex());
}
DocWriteResponse docWriteResponse = response.getResponse();
if (docWriteResponse != null) {
docWriteResponse.setForcedRefresh(true);
}
}
return r;
})));
client.admin().indices().prepareRefresh().setIndices(indices.toArray(Strings.EMPTY_ARRAY)).execute(l.map(ignored -> r));
});
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.NONE);
}
/*
Expand Down