Skip to content

Commit 667df97

Browse files
authored
Merge branch 'main' into cperrors
Signed-off-by: Karen X <karenxyr@gmail.com>
2 parents 786c030 + d9cada6 commit 667df97

File tree

52 files changed

+1393
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1393
-186
lines changed

.github/workflows/gradle-check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122

123123
- name: Create Comment Success
124124
if: ${{ github.event_name == 'pull_request_target' && success() && env.result == 'SUCCESS' }}
125-
uses: peter-evans/create-or-update-comment@v4
125+
uses: peter-evans/create-or-update-comment@v5
126126
with:
127127
issue-number: ${{ env.pr_number }}
128128
body: |
@@ -145,7 +145,7 @@ jobs:
145145
146146
- name: Create Comment Flaky
147147
if: ${{ github.event_name == 'pull_request_target' && success() && env.result != 'SUCCESS' }}
148-
uses: peter-evans/create-or-update-comment@v4
148+
uses: peter-evans/create-or-update-comment@v5
149149
with:
150150
issue-number: ${{ env.pr_number }}
151151
body: |
@@ -155,7 +155,7 @@ jobs:
155155
156156
- name: Create Comment Failure
157157
if: ${{ github.event_name == 'pull_request_target' && failure() }}
158-
uses: peter-evans/create-or-update-comment@v4
158+
uses: peter-evans/create-or-update-comment@v5
159159
with:
160160
issue-number: ${{ env.pr_number }}
161161
body: |

.github/workflows/poc-checklist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
issues: write
1212
steps:
1313
- name: Add comment
14-
uses: peter-evans/create-or-update-comment@v4
14+
uses: peter-evans/create-or-update-comment@v5
1515
with:
1616
issue-number: ${{ github.event.issue.number }}
1717
body: |

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
## [Unreleased 3.x]
77
### Added
88
- Use Lucene `pack` method for `half_float` and `usigned_long` when using `ApproximatePointRangeQuery`.
9+
- Add a mapper for context aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
910
- Return full error for GRPC error response ([#19568](https://github.com/opensearch-project/OpenSearch/pull/19568))
1011

1112
### Changed
13+
- Faster `terms` query creation for `keyword` field with index and docValues enabled ([#19350](https://github.com/opensearch-project/OpenSearch/pull/19350))
1214
- Refactor to move prepareIndex and prepareDelete methods to Engine class ([#19551](https://github.com/opensearch-project/OpenSearch/pull/19551))
1315

1416
### Fixed
15-
- [WLM] add a check to stop workload group deletion having rules ([#19502](https://github.com/opensearch-project/OpenSearch/pull/19502))
17+
- Fix flaky test FieldDataLoadingIT.testIndicesFieldDataCacheSizeSetting ([#19571](https://github.com/opensearch-project/OpenSearch/pull/19571))
1618

1719
### Dependencies
20+
- Bump `peter-evans/create-or-update-comment` from 4 to 5 ([#19536](https://github.com/opensearch-project/OpenSearch/pull/19536))
21+
- Bump `com.azure:azure-core-http-netty` from 1.15.12 to 1.16.1 ([#19533](https://github.com/opensearch-project/OpenSearch/pull/19533))
1822
- Bump `org.apache.zookeeper:zookeeper` from 3.9.3 to 3.9.4 ([#19535](https://github.com/opensearch-project/OpenSearch/pull/19535))
1923

2024
### Deprecated

modules/lang-painless/src/main/java/org/opensearch/painless/PainlessModulePlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.opensearch.repositories.RepositoriesService;
6060
import org.opensearch.rest.RestController;
6161
import org.opensearch.rest.RestHandler;
62+
import org.opensearch.script.ContextAwareGroupingScript;
6263
import org.opensearch.script.DerivedFieldScript;
6364
import org.opensearch.script.IngestScript;
6465
import org.opensearch.script.ScoreScript;
@@ -120,6 +121,9 @@ public final class PainlessModulePlugin extends Plugin implements ScriptPlugin,
120121
derived.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.derived.txt"));
121122
map.put(DerivedFieldScript.CONTEXT, derived);
122123

124+
// Only basic painless support for ContextAwareGrouping script
125+
map.put(ContextAwareGroupingScript.CONTEXT, new ArrayList<>(Allowlist.BASE_ALLOWLISTS));
126+
123127
allowlists = map;
124128
}
125129

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
9+
package org.opensearch.painless;
10+
11+
import org.opensearch.common.settings.Settings;
12+
import org.opensearch.painless.spi.Allowlist;
13+
import org.opensearch.script.ContextAwareGroupingScript;
14+
import org.opensearch.script.ScriptContext;
15+
16+
import java.util.ArrayList;
17+
import java.util.Collections;
18+
import java.util.List;
19+
import java.util.Map;
20+
21+
public class ContextAwareGroupingScriptTests extends ScriptTestCase {
22+
23+
private static PainlessScriptEngine SCRIPT_ENGINE;
24+
25+
@Override
26+
public void setUp() throws Exception {
27+
super.setUp();
28+
29+
Map<ScriptContext<?>, List<Allowlist>> contexts = newDefaultContexts();
30+
List<Allowlist> allowlists = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
31+
contexts.put(ContextAwareGroupingScript.CONTEXT, allowlists);
32+
33+
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
34+
}
35+
36+
@Override
37+
public void tearDown() throws Exception {
38+
super.tearDown();
39+
SCRIPT_ENGINE = null;
40+
}
41+
42+
@Override
43+
protected PainlessScriptEngine getEngine() {
44+
return SCRIPT_ENGINE;
45+
}
46+
47+
public void testContextAwareGroupingScript() {
48+
String stringConcat = "ctx.value + \"-context-aware\"";
49+
ContextAwareGroupingScript script = compile(stringConcat);
50+
51+
assertEquals("value-context-aware", script.execute(Map.of("value", "value")));
52+
53+
String integerAddition = "String.valueOf(ctx.value / 100)";
54+
ContextAwareGroupingScript integerAdditionScript = compile(integerAddition);
55+
assertEquals("2", integerAdditionScript.execute(Map.of("value", 200)));
56+
}
57+
58+
private ContextAwareGroupingScript compile(String expression) {
59+
ContextAwareGroupingScript.Factory factory = getEngine().compile(
60+
expression,
61+
expression,
62+
ContextAwareGroupingScript.CONTEXT,
63+
Collections.emptyMap()
64+
);
65+
return factory.newInstance();
66+
}
67+
}

modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/71_context_api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- do:
33
scripts_painless_context: {}
44
- match: { contexts.0: aggregation_selector}
5-
- match: { contexts.24: update}
5+
- match: { contexts.25: update}
66
---
77

88
"Action to get all API values for score context":

modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteRequestBuilders.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.hc.core5.http.ContentType;
3636
import org.apache.hc.core5.http.io.entity.StringEntity;
3737
import org.opensearch.OpenSearchException;
38-
import org.opensearch.Version;
3938
import org.opensearch.action.search.SearchRequest;
4039
import org.opensearch.client.Request;
4140
import org.opensearch.common.logging.DeprecationLogger;
@@ -74,7 +73,7 @@ final class RemoteRequestBuilders {
7473

7574
private RemoteRequestBuilders() {}
7675

77-
static Request initialSearch(SearchRequest searchRequest, BytesReference query, Version remoteVersion) {
76+
static Request initialSearch(SearchRequest searchRequest, BytesReference query, RemoteVersion remoteVersion) {
7877
// It is nasty to build paths with StringBuilder but we'll be careful....
7978
StringBuilder path = new StringBuilder("/");
8079
addIndices(path, searchRequest.indices());
@@ -84,7 +83,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
8483
if (searchRequest.scroll() != null) {
8584
TimeValue keepAlive = searchRequest.scroll().keepAlive();
8685
// V_5_0_0
87-
if (remoteVersion.before(Version.fromId(5000099))) {
86+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_5_0_0)) {
8887
/* Versions of Elasticsearch before 5.0 couldn't parse nanos or micros
8988
* so we toss out that resolution, rounding up because more scroll
9089
* timeout seems safer than less. */
@@ -103,7 +102,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
103102
if (searchRequest.source().sorts() != null) {
104103
boolean useScan = false;
105104
// Detect if we should use search_type=scan rather than a sort
106-
if (remoteVersion.before(Version.fromId(2010099))) {
105+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_2_1_0)) {
107106
for (SortBuilder<?> sort : searchRequest.source().sorts()) {
108107
if (sort instanceof FieldSortBuilder) {
109108
FieldSortBuilder f = (FieldSortBuilder) sort;
@@ -124,10 +123,10 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
124123
request.addParameter("sort", sorts.toString());
125124
}
126125
}
127-
if (remoteVersion.before(Version.fromId(2000099))) {
126+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_2_0_0)) {
128127
// Versions before 2.0.0 need prompting to return interesting fields. Note that timestamp isn't available at all....
129128
searchRequest.source().storedField("_parent").storedField("_routing").storedField("_ttl");
130-
if (remoteVersion.before(Version.fromId(1000099))) {
129+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_1_0_0)) {
131130
// Versions before 1.0.0 don't support `"_source": true` so we have to ask for the _source in a funny way.
132131
if (false == searchRequest.source().storedFields().fieldNames().contains("_source")) {
133132
searchRequest.source().storedField("_source");
@@ -140,11 +139,11 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
140139
fields.append(',').append(searchRequest.source().storedFields().fieldNames().get(i));
141140
}
142141
// V_5_0_0
143-
String storedFieldsParamName = remoteVersion.before(Version.fromId(5000099)) ? "fields" : "stored_fields";
142+
String storedFieldsParamName = remoteVersion.before(RemoteVersion.ELASTICSEARCH_5_0_0) ? "fields" : "stored_fields";
144143
request.addParameter(storedFieldsParamName, fields.toString());
145144
}
146145

147-
if (remoteVersion.onOrAfter(Version.fromId(6030099))) {
146+
if (remoteVersion.onOrAfter(RemoteVersion.ELASTICSEARCH_6_3_0)) {
148147
// allow_partial_results introduced in 6.3, running remote reindex against earlier versions still silently discards RED shards.
149148
request.addParameter("allow_partial_search_results", "false");
150149
}
@@ -173,7 +172,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
173172
if (searchRequest.source().fetchSource() != null) {
174173
entity.field("_source", searchRequest.source().fetchSource());
175174
} else {
176-
if (remoteVersion.onOrAfter(Version.fromId(1000099))) {
175+
if (remoteVersion.onOrAfter(RemoteVersion.ELASTICSEARCH_1_0_0)) {
177176
// Versions before 1.0 don't support `"_source": true` so we have to ask for the source as a stored field.
178177
entity.field("_source", true);
179178
}
@@ -225,19 +224,18 @@ private static String sortToUri(SortBuilder<?> sort) {
225224
throw new IllegalArgumentException("Unsupported sort [" + sort + "]");
226225
}
227226

228-
static Request scroll(String scroll, TimeValue keepAlive, Version remoteVersion) {
227+
static Request scroll(String scroll, TimeValue keepAlive, RemoteVersion remoteVersion) {
229228
Request request = new Request("POST", "/_search/scroll");
230229

231-
// V_5_0_0
232-
if (remoteVersion.before(Version.fromId(5000099))) {
230+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_5_0_0)) {
233231
/* Versions of Elasticsearch before 5.0 couldn't parse nanos or micros
234232
* so we toss out that resolution, rounding up so we shouldn't end up
235233
* with 0s. */
236234
keepAlive = timeValueMillis((long) Math.ceil(keepAlive.millisFrac()));
237235
}
238236
request.addParameter("scroll", keepAlive.getStringRep());
239237

240-
if (remoteVersion.before(Version.fromId(2000099))) {
238+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_2_0_0)) {
241239
// Versions before 2.0.0 extract the plain scroll_id from the body
242240
request.setEntity(new StringEntity(scroll, ContentType.TEXT_PLAIN));
243241
return request;
@@ -252,10 +250,10 @@ static Request scroll(String scroll, TimeValue keepAlive, Version remoteVersion)
252250
return request;
253251
}
254252

255-
static Request clearScroll(String scroll, Version remoteVersion) {
253+
static Request clearScroll(String scroll, RemoteVersion remoteVersion) {
256254
Request request = new Request("DELETE", "/_search/scroll");
257255

258-
if (remoteVersion.before(Version.fromId(2000099))) {
256+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_2_0_0)) {
259257
// Versions before 2.0.0 extract the plain scroll_id from the body
260258
request.setEntity(new StringEntity(scroll, ContentType.TEXT_PLAIN));
261259
return request;

modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteResponseParsers.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
package org.opensearch.index.reindex.remote;
3434

3535
import org.apache.lucene.search.TotalHits;
36-
import org.opensearch.LegacyESVersion;
37-
import org.opensearch.Version;
3836
import org.opensearch.common.collect.Tuple;
3937
import org.opensearch.core.ParseField;
4038
import org.opensearch.core.common.ParsingException;
@@ -294,20 +292,21 @@ public void setCausedBy(Throwable causedBy) {
294292
}
295293

296294
/**
297-
* Parses the main action to return just the {@linkplain Version} that it returns. We throw everything else out.
295+
* Parses the main action to return just the {@linkplain RemoteVersion} that it returns. We throw everything else out.
298296
*/
299-
public static final ConstructingObjectParser<Version, MediaType> MAIN_ACTION_PARSER = new ConstructingObjectParser<>(
297+
public static final ConstructingObjectParser<RemoteVersion, MediaType> MAIN_ACTION_PARSER = new ConstructingObjectParser<>(
300298
"/",
301299
true,
302-
a -> (Version) a[0]
300+
a -> (RemoteVersion) a[0]
303301
);
304302
static {
305-
ConstructingObjectParser<Version, MediaType> versionParser = new ConstructingObjectParser<>(
303+
ConstructingObjectParser<RemoteVersion, MediaType> versionParser = new ConstructingObjectParser<>(
306304
"version",
307305
true,
308-
a -> a[0] == null
309-
? LegacyESVersion.fromString(((String) a[1]).replace("-SNAPSHOT", "").replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", ""))
310-
: Version.fromString(((String) a[1]).replace("-SNAPSHOT", "").replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", ""))
306+
a -> RemoteVersion.fromString(
307+
((String) a[1]).replace("-SNAPSHOT", "").replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", ""),
308+
a[0] != null
309+
)
311310
);
312311
versionParser.declareStringOrNull(optionalConstructorArg(), new ParseField("distribution"));
313312
versionParser.declareString(constructorArg(), new ParseField("number"));

modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteScrollableHitSource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.logging.log4j.util.Supplier;
4343
import org.opensearch.OpenSearchException;
4444
import org.opensearch.OpenSearchStatusException;
45-
import org.opensearch.Version;
4645
import org.opensearch.action.bulk.BackoffPolicy;
4746
import org.opensearch.action.search.SearchRequest;
4847
import org.opensearch.client.Request;
@@ -81,7 +80,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
8180
private final RestClient client;
8281
private final BytesReference query;
8382
private final SearchRequest searchRequest;
84-
Version remoteVersion;
83+
RemoteVersion remoteVersion;
8584

8685
public RemoteScrollableHitSource(
8786
Logger logger,
@@ -116,7 +115,7 @@ protected void doStart(RejectAwareActionListener<Response> searchListener) {
116115
}, searchListener::onFailure, searchListener::onFailure));
117116
}
118117

119-
void lookupRemoteVersion(RejectAwareActionListener<Version> listener) {
118+
void lookupRemoteVersion(RejectAwareActionListener<RemoteVersion> listener) {
120119
logger.trace("Checking version for remote domain");
121120
// We're skipping retries for the first call to remote cluster so that we fail fast & respond back immediately
122121
// instead of retrying for longer duration.
@@ -159,7 +158,8 @@ public void onFailure(Exception e) {
159158
private void logFailure(Exception e) {
160159
if (e instanceof ResponseException) {
161160
ResponseException re = (ResponseException) e;
162-
if (remoteVersion.before(Version.fromId(2000099)) && re.getResponse().getStatusLine().getStatusCode() == 404) {
161+
if (remoteVersion.before(RemoteVersion.ELASTICSEARCH_2_0_0)
162+
&& re.getResponse().getStatusLine().getStatusCode() == 404) {
163163
logger.debug(
164164
(Supplier<?>) () -> new ParameterizedMessage(
165165
"Failed to clear scroll [{}] from pre-2.0 OpenSearch. This is normal if the request terminated "

0 commit comments

Comments
 (0)