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

Fix bulk ingest NPE with empty pipeline #15033

Merged
merged 5 commits into from
Aug 6, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed
- Fix constraint bug which allows more primary shards than average primary shards per index ([#14908](https://github.com/opensearch-project/OpenSearch/pull/14908))
- Fix bulk ingest NPE with empty pipeline ([#15033](https://github.com/opensearch-project/OpenSearch/pull/15033))
- Fix missing value of FieldSort for unsigned_long ([#14963](https://github.com/opensearch-project/OpenSearch/pull/14963))

### Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@
Consumer<List<IngestDocumentWrapper>> handler
) {
if (pipeline.getProcessors().isEmpty()) {
handler.accept(null);
handler.accept(toIngestDocumentWrappers(slots, indexRequests));

Check warning on line 1000 in server/src/main/java/org/opensearch/ingest/IngestService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/ingest/IngestService.java#L1000

Added line #L1000 was not covered by tests
chishui marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down Expand Up @@ -1271,6 +1271,14 @@
return new IngestDocumentWrapper(slot, toIngestDocument(indexRequest), null);
}

private static List<IngestDocumentWrapper> toIngestDocumentWrappers(List<Integer> slots, List<IndexRequest> indexRequests) {
mch2 marked this conversation as resolved.
Show resolved Hide resolved
List<IngestDocumentWrapper> ingestDocumentWrappers = new ArrayList<>();

Check warning on line 1275 in server/src/main/java/org/opensearch/ingest/IngestService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/ingest/IngestService.java#L1275

Added line #L1275 was not covered by tests
for (int i = 0; i < slots.size(); ++i) {
ingestDocumentWrappers.add(toIngestDocumentWrapper(slots.get(i), indexRequests.get(i)));

Check warning on line 1277 in server/src/main/java/org/opensearch/ingest/IngestService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/ingest/IngestService.java#L1277

Added line #L1277 was not covered by tests
}
return ingestDocumentWrappers;

Check warning on line 1279 in server/src/main/java/org/opensearch/ingest/IngestService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/ingest/IngestService.java#L1279

Added line #L1279 was not covered by tests
mch2 marked this conversation as resolved.
Show resolved Hide resolved
}

private static Map<Integer, IndexRequest> createSlotIndexRequestMap(List<Integer> slots, List<IndexRequest> indexRequests) {
Map<Integer, IndexRequest> slotIndexRequestMap = new HashMap<>();
for (int i = 0; i < slots.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,43 @@ public void testExecuteBulkRequestInBatchWithDefaultBatchSize() {
verify(mockCompoundProcessor, never()).execute(any(), any());
}

public void testExecuteEmptyPipelineInBatch() throws Exception {
IngestService ingestService = createWithProcessors(emptyMap());
PutPipelineRequest putRequest = new PutPipelineRequest(
"_id",
new BytesArray("{\"processors\": [], \"description\": \"_description\"}"),
MediaTypeRegistry.JSON
);
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build(); // Start empty
ClusterState previousClusterState = clusterState;
clusterState = IngestService.innerPut(putRequest, clusterState);
ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState));
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest1 = new IndexRequest("_index").id("_id1").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
bulkRequest.add(indexRequest1);
IndexRequest indexRequest2 = new IndexRequest("_index").id("_id2").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
bulkRequest.add(indexRequest2);
IndexRequest indexRequest3 = new IndexRequest("_index").id("_id3").source(emptyMap()).setPipeline("_none").setFinalPipeline("_id");
bulkRequest.add(indexRequest3);
IndexRequest indexRequest4 = new IndexRequest("_index").id("_id4").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
bulkRequest.add(indexRequest4);
@SuppressWarnings("unchecked")
final BiConsumer<Integer, Exception> failureHandler = mock(BiConsumer.class);
@SuppressWarnings("unchecked")
final BiConsumer<Thread, Exception> completionHandler = mock(BiConsumer.class);
chishui marked this conversation as resolved.
Show resolved Hide resolved
ingestService.executeBulkRequest(
4,
bulkRequest.requests(),
failureHandler,
completionHandler,
indexReq -> {},
Names.WRITE,
mockBulkRequest
);
verify(failureHandler, never()).accept(any(), any());
verify(completionHandler, times(1)).accept(Thread.currentThread(), null);
}

public void testPrepareBatches_same_index_pipeline() {
IngestService.IndexRequestWrapper wrapper1 = createIndexRequestWrapper("index1", Collections.singletonList("p1"));
IngestService.IndexRequestWrapper wrapper2 = createIndexRequestWrapper("index1", Collections.singletonList("p1"));
Expand Down
Loading