Skip to content

Commit 3720d9c

Browse files
authored
[GRPC] Upgrade to protobufs 0.24.0 and fix compilation errors (#20059)
1 parent c4b12cf commit 3720d9c

34 files changed

+584
-88
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6464
- Refactor the IndexPressutreStats, DeviceStats and TransportStats class to use the Builder pattern instead of constructors ([#19991](https://github.com/opensearch-project/OpenSearch/pull/19991))
6565
- Refactor the Cache.CacheStats class to use the Builder pattern instead of constructors ([#20015](https://github.com/opensearch-project/OpenSearch/pull/20015))
6666
- Refactor the HttpStats, ScriptStats, AdaptiveSelectionStats and OsStats class to use the Builder pattern instead of constructors ([#20014](https://github.com/opensearch-project/OpenSearch/pull/20014))
67+
- Bump opensearch-protobufs dependency to 0.24.0 and update transport-grpc module compatibility ([#20059](https://github.com/opensearch-project/OpenSearch/pull/20059))
68+
6769

6870
### Fixed
6971
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kotlin = "1.7.10"
2222
antlr4 = "4.13.1"
2323
guava = "33.2.1-jre"
2424
gson = "2.13.2"
25-
opensearchprotobufs = "0.23.0"
25+
opensearchprotobufs = "0.24.0"
2626
protobuf = "3.25.8"
2727
jakarta_annotation = "1.3.5"
2828
google_http_client = "1.44.1"

modules/transport-grpc/licenses/protobufs-0.23.0.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4330dd089f853e345aa137708490aec841ffadc0

modules/transport-grpc/spi/licenses/protobufs-0.23.0.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4330dd089f853e345aa137708490aec841ffadc0

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/FetchSourceContextProtoUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
4545
// Set up source context if source parameters are provided
4646
if (request.hasXSource()) {
4747
switch (request.getXSource().getSourceConfigParamCase()) {
48-
case BOOL:
49-
fetchSource = request.getXSource().getBool();
48+
case FETCH:
49+
fetchSource = request.getXSource().getFetch();
5050
break;
51-
case STRING_ARRAY:
52-
sourceIncludes = request.getXSource().getStringArray().getStringArrayList().toArray(new String[0]);
51+
case FIELDS:
52+
sourceIncludes = request.getXSource().getFields().getStringArrayList().toArray(new String[0]);
5353
break;
5454
default:
5555
throw new UnsupportedOperationException("Invalid sourceConfig provided.");
@@ -84,10 +84,10 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
8484
if (request.hasXSource()) {
8585
SourceConfigParam source = request.getXSource();
8686

87-
if (source.hasBool()) {
88-
fetchSource = source.getBool();
87+
if (source.hasFetch()) {
88+
fetchSource = source.getFetch();
8989
} else {
90-
sourceIncludes = source.getStringArray().getStringArrayList().toArray(new String[0]);
90+
sourceIncludes = source.getFields().getStringArrayList().toArray(new String[0]);
9191
}
9292
}
9393

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/ScriptProtoUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static Script parseInlineScript(InlineScript inlineScript, String default
7676

7777
ScriptType type = ScriptType.INLINE;
7878

79-
String lang = parseScriptLanguage(inlineScript.getLang(), defaultLang);
79+
String lang = inlineScript.hasLang() ? parseScriptLanguage(inlineScript.getLang(), defaultLang) : defaultLang;
8080
String idOrCode = inlineScript.getSource();
8181

8282
Map<String, String> options = inlineScript.getOptionsMap();

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/document/bulk/ActiveShardCountProtoUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ private ActiveShardCountProtoUtils() {
3838
public static ActiveShardCount parseProto(WaitForActiveShards waitForActiveShards) {
3939

4040
switch (waitForActiveShards.getWaitForActiveShardsCase()) {
41-
case WAIT_FOR_ACTIVE_SHARD_OPTIONS:
42-
switch (waitForActiveShards.getWaitForActiveShardOptions()) {
41+
case OPTION:
42+
switch (waitForActiveShards.getOption()) {
4343
case WAIT_FOR_ACTIVE_SHARD_OPTIONS_ALL:
4444
return ActiveShardCount.ALL;
4545
case WAIT_FOR_ACTIVE_SHARD_OPTIONS_NULL:
4646
case WAIT_FOR_ACTIVE_SHARD_OPTIONS_UNSPECIFIED:
4747
default:
4848
return ActiveShardCount.DEFAULT;
4949
}
50-
case INT32:
51-
return ActiveShardCount.from(waitForActiveShards.getInt32());
50+
case COUNT:
51+
return ActiveShardCount.from(waitForActiveShards.getCount());
5252
case WAITFORACTIVESHARDS_NOT_SET:
5353
default:
5454
return ActiveShardCount.DEFAULT;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
package org.opensearch.transport.grpc.proto.request.search;
9+
10+
import org.opensearch.index.mapper.DerivedField;
11+
import org.opensearch.transport.grpc.proto.request.common.ObjectMapProtoUtils;
12+
import org.opensearch.transport.grpc.proto.request.common.ScriptProtoUtils;
13+
14+
/**
15+
* Utility class for converting DerivedField Protocol Buffers to OpenSearch DerivedField objects.
16+
* This class handles the conversion of Protocol Buffer representations to their
17+
* corresponding OpenSearch derived field objects, matching the REST side pattern.
18+
*
19+
* @see org.opensearch.index.mapper.DerivedFieldMapper.Builder#build(org.opensearch.index.mapper.Mapper.BuilderContext)
20+
* @see org.opensearch.index.mapper.DefaultDerivedFieldResolver#initDerivedFieldTypes(java.util.Map, java.util.List)
21+
*/
22+
public class DerivedFieldProtoUtils {
23+
24+
private DerivedFieldProtoUtils() {
25+
// Utility class, no instances
26+
}
27+
28+
/**
29+
* Converts a Protocol Buffer DerivedField to its corresponding OpenSearch DerivedField.
30+
* Uses the same pattern as REST side: always use simple constructor, then conditionally
31+
* set optional fields based on presence (matches DerivedFieldMapper.Builder.build() pattern).
32+
*
33+
*
34+
* <p>This matches the REST side's {@code Parameter.isConfigured()} pattern in
35+
* {@link org.opensearch.index.mapper.DerivedFieldMapper.Builder#build}, where optional
36+
* fields are only set if they were present in the request.</p>
37+
*
38+
* @param name The name of the derived field
39+
* @param derivedFieldProto The Protocol Buffer DerivedField to convert
40+
* @return The corresponding OpenSearch DerivedField with optional fields set
41+
* @see org.opensearch.index.mapper.DerivedFieldMapper.Builder#build(org.opensearch.index.mapper.Mapper.BuilderContext)
42+
* @see org.opensearch.index.mapper.ParametrizedFieldMapper.Parameter#isConfigured()
43+
*/
44+
public static DerivedField fromProto(String name, org.opensearch.protobufs.DerivedField derivedFieldProto) {
45+
// Always use simple constructor first (matches REST side pattern in DerivedFieldMapper.Builder.build())
46+
DerivedField derivedField = new DerivedField(
47+
name,
48+
derivedFieldProto.getType(),
49+
ScriptProtoUtils.parseFromProtoRequest(derivedFieldProto.getScript())
50+
);
51+
52+
// Conditionally set optional fields based on presence (matches REST side's isConfigured() pattern)
53+
if (derivedFieldProto.hasProperties()) {
54+
derivedField.setProperties(ObjectMapProtoUtils.fromProto(derivedFieldProto.getProperties()));
55+
}
56+
if (derivedFieldProto.hasPrefilterField()) {
57+
derivedField.setPrefilterField(derivedFieldProto.getPrefilterField());
58+
}
59+
if (derivedFieldProto.hasFormat()) {
60+
derivedField.setFormat(derivedFieldProto.getFormat());
61+
}
62+
if (derivedFieldProto.hasIgnoreMalformed()) {
63+
derivedField.setIgnoreMalformed(derivedFieldProto.getIgnoreMalformed());
64+
}
65+
66+
return derivedField;
67+
}
68+
}

0 commit comments

Comments
 (0)