Skip to content

Commit 0b81d55

Browse files
authored
Merge branch 'main' into correct-seed-data-in-reload-test
2 parents 34c6a77 + 790810e commit 0b81d55

File tree

18 files changed

+89
-55
lines changed

18 files changed

+89
-55
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,10 @@ static Tuple<Long, Long> numberOfMultiparts(final long totalSize, final long par
783783
}
784784
}
785785

786-
private class CompareAndExchangeOperation {
786+
/**
787+
* An implementation of {@link BlobContainer#compareAndExchangeRegister} based on strongly-consistent multipart upload APIs.
788+
*/
789+
private class MultipartUploadCompareAndExchangeOperation {
787790

788791
private final OperationPurpose purpose;
789792
private final S3Client client;
@@ -792,7 +795,13 @@ private class CompareAndExchangeOperation {
792795
private final String blobKey;
793796
private final ThreadPool threadPool;
794797

795-
CompareAndExchangeOperation(OperationPurpose purpose, S3Client client, String bucket, String key, ThreadPool threadPool) {
798+
MultipartUploadCompareAndExchangeOperation(
799+
OperationPurpose purpose,
800+
S3Client client,
801+
String bucket,
802+
String key,
803+
ThreadPool threadPool
804+
) {
796805
this.purpose = purpose;
797806
this.client = client;
798807
this.bucket = bucket;
@@ -802,6 +811,23 @@ private class CompareAndExchangeOperation {
802811
}
803812

804813
void run(BytesReference expected, BytesReference updated, ActionListener<OptionalBytesReference> listener) throws Exception {
814+
innerRun(expected, updated, listener.delegateResponse((delegate, e) -> {
815+
logger.trace(() -> Strings.format("[%s]: compareAndExchangeRegister failed", rawKey), e);
816+
if (e instanceof AwsServiceException awsServiceException
817+
&& (awsServiceException.statusCode() == 404
818+
|| awsServiceException.statusCode() == 200
819+
&& "NoSuchUpload".equals(awsServiceException.awsErrorDetails().errorCode()))) {
820+
// An uncaught 404 means that our multipart upload was aborted by a concurrent operation before we could complete it.
821+
// Also (rarely) S3 can start processing the request during a concurrent abort and this can result in a 200 OK with an
822+
// <Error><Code>NoSuchUpload</Code>... in the response. Either way, this means that our write encountered contention:
823+
delegate.onResponse(OptionalBytesReference.MISSING);
824+
} else {
825+
delegate.onFailure(e);
826+
}
827+
}));
828+
}
829+
830+
void innerRun(BytesReference expected, BytesReference updated, ActionListener<OptionalBytesReference> listener) throws Exception {
805831
BlobContainerUtils.ensureValidRegisterContent(updated);
806832

807833
if (hasPreexistingUploads()) {
@@ -1094,25 +1120,15 @@ public void compareAndExchangeRegister(
10941120
ActionListener<OptionalBytesReference> listener
10951121
) {
10961122
final var clientReference = blobStore.clientReference();
1097-
ActionListener.run(ActionListener.releaseAfter(listener.delegateResponse((delegate, e) -> {
1098-
logger.trace(() -> Strings.format("[%s]: compareAndExchangeRegister failed", key), e);
1099-
if (e instanceof AwsServiceException awsServiceException
1100-
&& (awsServiceException.statusCode() == 404
1101-
|| awsServiceException.statusCode() == 200
1102-
&& "NoSuchUpload".equals(awsServiceException.awsErrorDetails().errorCode()))) {
1103-
// An uncaught 404 means that our multipart upload was aborted by a concurrent operation before we could complete it.
1104-
// Also (rarely) S3 can start processing the request during a concurrent abort and this can result in a 200 OK with an
1105-
// <Error><Code>NoSuchUpload</Code>... in the response. Either way, this means that our write encountered contention:
1106-
delegate.onResponse(OptionalBytesReference.MISSING);
1107-
} else {
1108-
delegate.onFailure(e);
1109-
}
1110-
}), clientReference),
1111-
l -> new CompareAndExchangeOperation(purpose, clientReference.client(), blobStore.bucket(), key, blobStore.getThreadPool()).run(
1112-
expected,
1113-
updated,
1114-
l
1115-
)
1123+
ActionListener.run(
1124+
ActionListener.releaseBefore(clientReference, listener),
1125+
l -> new MultipartUploadCompareAndExchangeOperation(
1126+
purpose,
1127+
clientReference.client(),
1128+
blobStore.bucket(),
1129+
key,
1130+
blobStore.getThreadPool()
1131+
).run(expected, updated, l)
11161132
);
11171133
}
11181134

muted-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ tests:
420420
- class: org.elasticsearch.smoketest.MlWithSecurityIT
421421
method: test {yaml=ml/start_data_frame_analytics/Test start classification analysis when the dependent variable cardinality is too low}
422422
issue: https://github.com/elastic/elasticsearch/issues/138409
423+
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
424+
method: test {p0=esql/60_usage/Basic ESQL usage output (telemetry) non-snapshot version}
425+
issue: https://github.com/elastic/elasticsearch/issues/138426
426+
- class: org.elasticsearch.xpack.ml.integration.RevertModelSnapshotIT
427+
method: testRevertModelSnapshot
428+
issue: https://github.com/elastic/elasticsearch/issues/132733
423429

424430
# Examples:
425431
#

qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/FeatureUpgradeApiIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class FeatureUpgradeApiIT extends AbstractSystemIndicesIT {
2929

3030
@After
3131
public void resetFeatures() throws Exception {
32-
client().performRequest(new Request("POST", "/_features/_reset"));
32+
performPostFeaturesReset(client());
3333
}
3434

3535
public void testCreatingSystemIndex() throws Exception {

qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/NetNewSystemIndicesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ public void testSearch() throws Exception {
9494

9595
@After
9696
public void resetFeatures() throws Exception {
97-
client().performRequest(new Request("POST", "/_features/_reset"));
97+
performPostFeaturesReset(client());
9898
}
9999
}

qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/SystemAliasIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SystemAliasIT extends AbstractSystemIndicesIT {
2626

2727
@After
2828
public void resetFeatures() throws Exception {
29-
client().performRequest(new Request("POST", "/_features/_reset"));
29+
performPostFeaturesReset(client());
3030
}
3131

3232
public void testCreatingSystemIndexWithAlias() throws Exception {

server/src/test/java/org/elasticsearch/action/admin/cluster/stats/MappingStatsTests.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
9999

100100
private static final String SCRIPT_1 = scriptAsJSON("doc['field'] + doc.field + params._source.field");
101101
private static final String SCRIPT_2 = scriptAsJSON("doc['field']");
102-
private static final String SCRIPT_3 = scriptAsJSON("params._source.field + params._source.field \n + params._source.field");
102+
private static final String SCRIPT_3 = scriptAsJSON("params._source.field + params._source.field + params._source.field");
103103
private static final String SCRIPT_4 = scriptAsJSON("params._source.field");
104104

105105
public void testToXContent() {
@@ -114,8 +114,8 @@ public void testToXContent() {
114114
"mappings" : {
115115
"total_field_count" : 12,
116116
"total_deduplicated_field_count" : 6,
117-
"total_deduplicated_mapping_size" : "260b",
118-
"total_deduplicated_mapping_size_in_bytes" : 260,
117+
"total_deduplicated_mapping_size" : "255b",
118+
"total_deduplicated_mapping_size_in_bytes" : 255,
119119
"field_types" : [
120120
{
121121
"name" : "dense_vector",
@@ -159,10 +159,10 @@ public void testToXContent() {
159159
"lang" : [
160160
"painless"
161161
],
162-
"lines_max" : 2,
163-
"lines_total" : 6,
164-
"chars_max" : 68,
165-
"chars_total" : 176,
162+
"lines_max" : 1,
163+
"lines_total" : 4,
164+
"chars_max" : 66,
165+
"chars_total" : 172,
166166
"source_max" : 3,
167167
"source_total" : 8,
168168
"doc_max" : 0,
@@ -203,10 +203,10 @@ public void testToXContent() {
203203
"lang" : [
204204
"painless"
205205
],
206-
"lines_max" : 2,
207-
"lines_total" : 6,
208-
"chars_max" : 68,
209-
"chars_total" : 176,
206+
"lines_max" : 1,
207+
"lines_total" : 4,
208+
"chars_max" : 66,
209+
"chars_total" : 172,
210210
"source_max" : 3,
211211
"source_total" : 8,
212212
"doc_max" : 0,
@@ -246,8 +246,8 @@ public void testToXContentWithSomeSharedMappings() {
246246
"mappings" : {
247247
"total_field_count" : 18,
248248
"total_deduplicated_field_count" : 12,
249-
"total_deduplicated_mapping_size" : "519b",
250-
"total_deduplicated_mapping_size_in_bytes" : 519,
249+
"total_deduplicated_mapping_size" : "513b",
250+
"total_deduplicated_mapping_size_in_bytes" : 513,
251251
"field_types" : [
252252
{
253253
"name" : "dense_vector",
@@ -291,10 +291,10 @@ public void testToXContentWithSomeSharedMappings() {
291291
"lang" : [
292292
"painless"
293293
],
294-
"lines_max" : 2,
295-
"lines_total" : 9,
296-
"chars_max" : 68,
297-
"chars_total" : 264,
294+
"lines_max" : 1,
295+
"lines_total" : 6,
296+
"chars_max" : 66,
297+
"chars_total" : 258,
298298
"source_max" : 3,
299299
"source_total" : 12,
300300
"doc_max" : 0,
@@ -335,10 +335,10 @@ public void testToXContentWithSomeSharedMappings() {
335335
"lang" : [
336336
"painless"
337337
],
338-
"lines_max" : 2,
339-
"lines_total" : 9,
340-
"chars_max" : 68,
341-
"chars_total" : 264,
338+
"lines_max" : 1,
339+
"lines_total" : 6,
340+
"chars_max" : 66,
341+
"chars_total" : 258,
342342
"source_max" : 3,
343343
"source_total" : 12,
344344
"doc_max" : 0,

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,15 @@ protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
923923
return false;
924924
}
925925

926+
/**
927+
* Invoke {@code POST /_features/_reset?error_trace} with the given {@link RestClient}.
928+
*/
929+
public static void performPostFeaturesReset(RestClient restClient) throws IOException {
930+
final var request = new Request(HttpPost.METHOD_NAME, "/_features/_reset");
931+
request.addParameter("error_trace", "true");
932+
assertOK(restClient.performRequest(request));
933+
}
934+
926935
private void wipeCluster() throws Exception {
927936
waitForClusterUpdates();
928937

@@ -949,8 +958,7 @@ private void wipeCluster() throws Exception {
949958
wipeSnapshots();
950959

951960
if (resetFeatureStates()) {
952-
final Request postRequest = new Request("POST", "/_features/_reset");
953-
cleanupClient().performRequest(postRequest);
961+
performPostFeaturesReset(cleanupClient());
954962
}
955963

956964
// wipe data streams before indices so that the backing indices for data streams are handled properly

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.List;
1818
import java.util.Map;
1919

20+
import static org.elasticsearch.test.rest.ESRestTestCase.performPostFeaturesReset;
2021
import static org.hamcrest.MatcherAssert.assertThat;
2122
import static org.hamcrest.Matchers.hasSize;
2223

@@ -33,7 +34,7 @@ public MlRestTestStateCleaner(Logger logger, RestClient adminClient) {
3334
public void resetFeatures() throws IOException {
3435
deletePipelinesWithInferenceProcessors();
3536
// This resets all features, not just ML, but they should have been getting reset between tests anyway so it shouldn't matter
36-
adminClient.performRequest(new Request("POST", "/_features/_reset"));
37+
performPostFeaturesReset(adminClient);
3738
}
3839

3940
@SuppressWarnings("unchecked")

x-pack/plugin/deprecation/qa/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/MlDeprecationIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ protected String getTestRestCluster() {
5959

6060
@After
6161
public void resetFeatures() throws IOException {
62-
Response response = adminClient().performRequest(new Request("POST", "/_features/_reset"));
63-
assertOK(response);
62+
performPostFeaturesReset(adminClient());
6463
}
6564

6665
@Override

x-pack/plugin/ml/qa/disabled/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlPluginDisabledIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public void testActionsFail() throws Exception {
7575
}
7676

7777
public void testMlFeatureReset() throws IOException {
78-
Request request = new Request("POST", "/_features/_reset");
79-
assertOK(client().performRequest(request));
78+
performPostFeaturesReset(client());
8079
}
8180

8281
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)