Skip to content

Commit b47b401

Browse files
authored
Fix bulk ingest NPE with empty pipeline (opensearch-project#15033)
Signed-off-by: Liyun Xiu <xiliyun@amazon.com>
1 parent f980924 commit b47b401

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3636

3737
### Fixed
3838
- Fix constraint bug which allows more primary shards than average primary shards per index ([#14908](https://github.com/opensearch-project/OpenSearch/pull/14908))
39+
- Fix NPE when bulk ingest with empty pipeline ([#15033](https://github.com/opensearch-project/OpenSearch/pull/15033))
3940
- Fix missing value of FieldSort for unsigned_long ([#14963](https://github.com/opensearch-project/OpenSearch/pull/14963))
4041
- Fix delete index template failed when the index template matches a data stream but is unused ([#15080](https://github.com/opensearch-project/OpenSearch/pull/15080))
4142

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ private void innerBatchExecute(
997997
Consumer<List<IngestDocumentWrapper>> handler
998998
) {
999999
if (pipeline.getProcessors().isEmpty()) {
1000-
handler.accept(null);
1000+
handler.accept(toIngestDocumentWrappers(slots, indexRequests));
10011001
return;
10021002
}
10031003

@@ -1271,6 +1271,14 @@ private static IngestDocumentWrapper toIngestDocumentWrapper(int slot, IndexRequ
12711271
return new IngestDocumentWrapper(slot, toIngestDocument(indexRequest), null);
12721272
}
12731273

1274+
private static List<IngestDocumentWrapper> toIngestDocumentWrappers(List<Integer> slots, List<IndexRequest> indexRequests) {
1275+
List<IngestDocumentWrapper> ingestDocumentWrappers = new ArrayList<>();
1276+
for (int i = 0; i < slots.size(); ++i) {
1277+
ingestDocumentWrappers.add(toIngestDocumentWrapper(slots.get(i), indexRequests.get(i)));
1278+
}
1279+
return ingestDocumentWrappers;
1280+
}
1281+
12741282
private static Map<Integer, IndexRequest> createSlotIndexRequestMap(List<Integer> slots, List<IndexRequest> indexRequests) {
12751283
Map<Integer, IndexRequest> slotIndexRequestMap = new HashMap<>();
12761284
for (int i = 0; i < slots.size(); ++i) {

server/src/test/java/org/opensearch/ingest/IngestServiceTests.java

+36
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,42 @@ public void testExecuteBulkRequestInBatchWithDefaultBatchSize() {
19951995
verify(mockCompoundProcessor, never()).execute(any(), any());
19961996
}
19971997

1998+
public void testExecuteEmptyPipelineInBatch() throws Exception {
1999+
IngestService ingestService = createWithProcessors(emptyMap());
2000+
PutPipelineRequest putRequest = new PutPipelineRequest(
2001+
"_id",
2002+
new BytesArray("{\"processors\": [], \"description\": \"_description\"}"),
2003+
MediaTypeRegistry.JSON
2004+
);
2005+
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build(); // Start empty
2006+
ClusterState previousClusterState = clusterState;
2007+
clusterState = IngestService.innerPut(putRequest, clusterState);
2008+
ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState));
2009+
BulkRequest bulkRequest = new BulkRequest();
2010+
IndexRequest indexRequest1 = new IndexRequest("_index").id("_id1").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
2011+
bulkRequest.add(indexRequest1);
2012+
IndexRequest indexRequest2 = new IndexRequest("_index").id("_id2").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
2013+
bulkRequest.add(indexRequest2);
2014+
IndexRequest indexRequest3 = new IndexRequest("_index").id("_id3").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
2015+
bulkRequest.add(indexRequest3);
2016+
IndexRequest indexRequest4 = new IndexRequest("_index").id("_id4").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none");
2017+
bulkRequest.add(indexRequest4);
2018+
bulkRequest.batchSize(4);
2019+
final Map<Integer, Exception> failureHandler = new HashMap<>();
2020+
final Map<Thread, Exception> completionHandler = new HashMap<>();
2021+
ingestService.executeBulkRequest(
2022+
4,
2023+
bulkRequest.requests(),
2024+
failureHandler::put,
2025+
completionHandler::put,
2026+
indexReq -> {},
2027+
Names.WRITE,
2028+
bulkRequest
2029+
);
2030+
assertTrue(failureHandler.isEmpty());
2031+
assertEquals(Set.of(Thread.currentThread()), completionHandler.keySet());
2032+
}
2033+
19982034
public void testPrepareBatches_same_index_pipeline() {
19992035
IngestService.IndexRequestWrapper wrapper1 = createIndexRequestWrapper("index1", Collections.singletonList("p1"));
20002036
IngestService.IndexRequestWrapper wrapper2 = createIndexRequestWrapper("index1", Collections.singletonList("p1"));

0 commit comments

Comments
 (0)