Skip to content

Commit 859f7c3

Browse files
authored
BulkRequest: Make sure that indices Set is properly initialized when being deserialized from TransportRequest stream (#20132)
* BulkRequest: Make sure that indices Set is properly initialized when being deserialized from TransportRequest stream Signed-off-by: Nils Bandener <[email protected]> * fix Signed-off-by: Nils Bandener <[email protected]> * simplified BytesStreamOutput construction Signed-off-by: Nils Bandener <[email protected]> --------- Signed-off-by: Nils Bandener <[email protected]>
1 parent 0197084 commit 859f7c3

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
9393
- Fix node bootstrap error when enable stream transport and remote cluster state ([#19948](https://github.com/opensearch-project/OpenSearch/pull/19948))
9494
- Fix deletion failure/error of unused index template; case when an index template matches a data stream but has a lower priority. ([#20102](https://github.com/opensearch-project/OpenSearch/pull/20102))
9595
- Fix toBuilder method in EngineConfig to include mergedSegmentTransferTracker([20105](https://github.com/opensearch-project/OpenSearch/pull/20105))
96+
- Fixed handling of property index in BulkRequest during deserialization ([#20132](https://github.com/opensearch-project/OpenSearch/pull/20132))
9697

9798
### Dependencies
9899
- Bump Apache Lucene from 10.3.1 to 10.3.2 ([#20026](https://github.com/opensearch-project/OpenSearch/pull/20026))

server/src/main/java/org/opensearch/action/bulk/BulkRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public BulkRequest(StreamInput in) throws IOException {
111111
if (in.getVersion().onOrAfter(Version.V_2_14_0) && in.getVersion().before(Version.V_3_0_0)) {
112112
in.readInt(); // formerly batch_size
113113
}
114+
requests.stream().map(DocWriteRequest::index).forEach(indices::add);
114115
}
115116

116117
public BulkRequest(@Nullable String globalIndex) {

server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.opensearch.cluster.node.DiscoveryNode;
5454
import org.opensearch.cluster.node.DiscoveryNodeRole;
5555
import org.opensearch.cluster.service.ClusterService;
56+
import org.opensearch.common.io.stream.BytesStreamOutput;
5657
import org.opensearch.common.settings.Settings;
5758
import org.opensearch.common.unit.TimeValue;
5859
import org.opensearch.core.action.ActionListener;
@@ -77,6 +78,7 @@
7778
import java.util.Collections;
7879
import java.util.List;
7980
import java.util.Map;
81+
import java.util.Set;
8082
import java.util.SortedMap;
8183
import java.util.TreeMap;
8284
import java.util.concurrent.TimeUnit;
@@ -379,6 +381,15 @@ public void testRejectionAfterCreateIndexIsPropagated() throws Exception {
379381
}
380382
}
381383

384+
public void testSerializationDeserialization() throws Exception {
385+
BulkRequest bulkRequest = new BulkRequest().add(new IndexRequest("index").id("id").source(Collections.emptyMap()));
386+
BytesStreamOutput out = new BytesStreamOutput();
387+
out.setVersion(Version.V_3_4_0);
388+
bulkRequest.writeTo(out);
389+
BulkRequest deserializedRequest = new BulkRequest(out.bytes().streamInput());
390+
assertEquals(Set.of("index"), deserializedRequest.getIndices());
391+
}
392+
382393
private BulkRequest buildBulkRequest(List<String> indices) {
383394
BulkRequest request = new BulkRequest();
384395
for (String index : indices) {

0 commit comments

Comments
 (0)