Skip to content

Commit 32cadde

Browse files
authored
Merge branch 'main' into eut2
2 parents 927f9bf + 8a662a6 commit 32cadde

File tree

61 files changed

+2055
-426
lines changed

Some content is hidden

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

61 files changed

+2055
-426
lines changed

server/src/main/java/org/elasticsearch/common/text/Text.java renamed to libs/x-content/src/main/java/org/elasticsearch/xcontent/Text.java

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@
66
* your election, the "Elastic License 2.0", the "GNU Affero General Public
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
9-
package org.elasticsearch.common.text;
10-
11-
import org.apache.lucene.util.BytesRef;
12-
import org.elasticsearch.common.bytes.BytesArray;
13-
import org.elasticsearch.common.bytes.BytesReference;
14-
import org.elasticsearch.xcontent.ToXContentFragment;
15-
import org.elasticsearch.xcontent.XContentBuilder;
9+
package org.elasticsearch.xcontent;
1610

1711
import java.io.IOException;
12+
import java.nio.ByteBuffer;
1813
import java.nio.charset.StandardCharsets;
1914

2015
/**
21-
* Both {@link String} and {@link BytesReference} representation of the text. Starts with one of those, and if
16+
* Both {@link String} and {@link ByteBuffer} representation of the text. Starts with one of those, and if
2217
* the other is requests, caches the other one in a local reference so no additional conversion will be needed.
2318
*/
24-
public final class Text implements Comparable<Text>, ToXContentFragment {
19+
public final class Text implements XContentString, Comparable<Text>, ToXContentFragment {
2520

2621
public static final Text[] EMPTY_ARRAY = new Text[0];
2722

@@ -36,31 +31,43 @@ public static Text[] convertFromStringArray(String[] strings) {
3631
return texts;
3732
}
3833

39-
private BytesReference bytes;
34+
private ByteBuffer bytes;
4035
private String text;
4136
private int hash;
37+
private int stringLength = -1;
38+
39+
/**
40+
* Construct a Text from a UTF-8 encoded ByteBuffer. Since no string length is specified, {@link #stringLength()}
41+
* will perform a string conversion to measure the string length.
42+
*/
43+
public Text(ByteBuffer bytes) {
44+
this.bytes = bytes;
45+
}
4246

43-
public Text(BytesReference bytes) {
47+
/**
48+
* Construct a Text from a UTF-8 encoded ByteBuffer and an explicit string length. Used to avoid string conversion
49+
* in {@link #stringLength()}.
50+
*/
51+
public Text(ByteBuffer bytes, int stringLength) {
4452
this.bytes = bytes;
53+
this.stringLength = stringLength;
4554
}
4655

4756
public Text(String text) {
4857
this.text = text;
4958
}
5059

5160
/**
52-
* Whether a {@link BytesReference} view of the data is already materialized.
61+
* Whether a {@link ByteBuffer} view of the data is already materialized.
5362
*/
5463
public boolean hasBytes() {
5564
return bytes != null;
5665
}
5766

58-
/**
59-
* Returns a {@link BytesReference} view of the data.
60-
*/
61-
public BytesReference bytes() {
67+
@Override
68+
public ByteBuffer bytes() {
6269
if (bytes == null) {
63-
bytes = new BytesArray(text.getBytes(StandardCharsets.UTF_8));
70+
bytes = StandardCharsets.UTF_8.encode(text);
6471
}
6572
return bytes;
6673
}
@@ -72,11 +79,20 @@ public boolean hasString() {
7279
return text != null;
7380
}
7481

75-
/**
76-
* Returns a {@link String} view of the data.
77-
*/
82+
@Override
7883
public String string() {
79-
return text == null ? bytes.utf8ToString() : text;
84+
if (text == null) {
85+
text = StandardCharsets.UTF_8.decode(bytes).toString();
86+
}
87+
return text;
88+
}
89+
90+
@Override
91+
public int stringLength() {
92+
if (stringLength < 0) {
93+
stringLength = string().length();
94+
}
95+
return stringLength;
8096
}
8197

8298
@Override
@@ -115,8 +131,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
115131
} else {
116132
// TODO: TextBytesOptimization we can use a buffer here to convert it? maybe add a
117133
// request to jackson to support InputStream as well?
118-
BytesRef br = this.bytes().toBytesRef();
119-
return builder.utf8Value(br.bytes, br.offset, br.length);
134+
assert bytes.hasArray();
135+
return builder.utf8Value(bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining());
120136
}
121137
}
122138
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.xcontent;
11+
12+
import java.nio.ByteBuffer;
13+
14+
public interface XContentString {
15+
/**
16+
* Returns a {@link String} view of the data.
17+
*/
18+
String string();
19+
20+
/**
21+
* Returns a UTF8-encoded {@link ByteBuffer} view of the data.
22+
*/
23+
ByteBuffer bytes();
24+
25+
/**
26+
* Returns the number of characters in the represented string.
27+
*/
28+
int stringLength();
29+
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ tests:
432432
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
433433
method: test {p0=search/350_point_in_time/point-in-time with index filter}
434434
issue: https://github.com/elastic/elasticsearch/issues/127741
435-
- class: org.elasticsearch.xpack.remotecluster.RemoteClusterSecurityFcActionAuthorizationIT
436-
method: testIndicesPrivilegesAreEnforcedForCcrRestoreSessionActions
437-
issue: https://github.com/elastic/elasticsearch/issues/127782
438435
- class: org.elasticsearch.compute.aggregation.FilteredGroupingAggregatorFunctionTests
439436
method: testSimpleCircuitBreaking
440437
issue: https://github.com/elastic/elasticsearch/issues/127833

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ static TransportVersion def(int id) {
7676
* READ THE COMMENT BELOW THIS BLOCK OF DECLARATIONS BEFORE ADDING NEW TRANSPORT VERSIONS
7777
* Detached transport versions added below here.
7878
*/
79-
public static final TransportVersion V_8_9_X = def(8_500_020);
80-
public static final TransportVersion V_8_10_X = def(8_500_061);
79+
public static final TransportVersion V_8_9_X = def(8_500_0_20);
80+
public static final TransportVersion V_8_10_X = def(8_500_0_61);
8181
public static final TransportVersion V_8_11_X = def(8_512_0_01);
8282
public static final TransportVersion V_8_12_0 = def(8_560_0_00);
8383
public static final TransportVersion V_8_12_1 = def(8_560_0_01);
@@ -242,16 +242,16 @@ static TransportVersion def(int id) {
242242
public static final TransportVersion RANDOM_SAMPLER_QUERY_BUILDER = def(9_063_0_00);
243243
public static final TransportVersion SETTINGS_IN_DATA_STREAMS = def(9_064_0_00);
244244
public static final TransportVersion INTRODUCE_FAILURES_LIFECYCLE = def(9_065_0_00);
245-
public static final TransportVersion PROJECT_METADATA_SETTINGS = def(9_066_00_0);
246-
public static final TransportVersion AGGREGATE_METRIC_DOUBLE_BLOCK = def(9_067_00_0);
245+
public static final TransportVersion PROJECT_METADATA_SETTINGS = def(9_066_0_00);
246+
public static final TransportVersion AGGREGATE_METRIC_DOUBLE_BLOCK = def(9_067_0_00);
247247
public static final TransportVersion PINNED_RETRIEVER = def(9_068_0_00);
248248
public static final TransportVersion ML_INFERENCE_SAGEMAKER = def(9_069_0_00);
249-
public static final TransportVersion WRITE_LOAD_INCLUDES_BUFFER_WRITES = def(9_070_00_0);
249+
public static final TransportVersion WRITE_LOAD_INCLUDES_BUFFER_WRITES = def(9_070_0_00);
250250
public static final TransportVersion INTRODUCE_FAILURES_DEFAULT_RETENTION = def(9_071_0_00);
251251
public static final TransportVersion FILE_SETTINGS_HEALTH_INFO = def(9_072_0_00);
252252
public static final TransportVersion FIELD_CAPS_ADD_CLUSTER_ALIAS = def(9_073_0_00);
253-
public static final TransportVersion INFERENCE_ADD_TIMEOUT_PUT_ENDPOINT = def(9_074_00_0);
254-
public static final TransportVersion ESQL_FIELD_ATTRIBUTE_DROP_TYPE = def(9_075_00_0);
253+
public static final TransportVersion INFERENCE_ADD_TIMEOUT_PUT_ENDPOINT = def(9_074_0_00);
254+
public static final TransportVersion ESQL_FIELD_ATTRIBUTE_DROP_TYPE = def(9_075_0_00);
255255

256256
/*
257257
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/cluster/service/MasterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.common.settings.ClusterSettings;
3737
import org.elasticsearch.common.settings.Setting;
3838
import org.elasticsearch.common.settings.Settings;
39-
import org.elasticsearch.common.text.Text;
4039
import org.elasticsearch.common.util.CollectionUtils;
4140
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
4241
import org.elasticsearch.common.util.concurrent.CountDown;
@@ -56,6 +55,7 @@
5655
import org.elasticsearch.tasks.TaskManager;
5756
import org.elasticsearch.threadpool.Scheduler;
5857
import org.elasticsearch.threadpool.ThreadPool;
58+
import org.elasticsearch.xcontent.Text;
5959

6060
import java.util.ArrayList;
6161
import java.util.Collections;

server/src/main/java/org/elasticsearch/cluster/service/PendingClusterTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.common.io.stream.Writeable;
16-
import org.elasticsearch.common.text.Text;
1716
import org.elasticsearch.core.TimeValue;
17+
import org.elasticsearch.xcontent.Text;
1818

1919
import java.io.IOException;
2020

server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import org.elasticsearch.common.collect.ImmutableOpenMap;
2424
import org.elasticsearch.common.geo.GeoPoint;
2525
import org.elasticsearch.common.settings.SecureString;
26-
import org.elasticsearch.common.text.Text;
2726
import org.elasticsearch.common.util.Maps;
2827
import org.elasticsearch.common.util.set.Sets;
2928
import org.elasticsearch.core.CharArrays;
3029
import org.elasticsearch.core.Nullable;
3130
import org.elasticsearch.core.TimeValue;
31+
import org.elasticsearch.xcontent.Text;
3232

3333
import java.io.EOFException;
3434
import java.io.FilterInputStream;
@@ -391,13 +391,23 @@ public Text readOptionalText() throws IOException {
391391
if (length == -1) {
392392
return null;
393393
}
394-
return new Text(readBytesReference(length));
394+
byte[] bytes = new byte[length];
395+
if (length > 0) {
396+
readBytes(bytes, 0, length);
397+
}
398+
var byteBuff = ByteBuffer.wrap(bytes);
399+
return new Text(byteBuff);
395400
}
396401

397402
public Text readText() throws IOException {
398-
// use StringAndBytes so we can cache the string if it's ever converted to it
403+
// use Text so we can cache the string if it's ever converted to it
399404
int length = readInt();
400-
return new Text(readBytesReference(length));
405+
byte[] bytes = new byte[length];
406+
if (length > 0) {
407+
readBytes(bytes, 0, length);
408+
}
409+
var byteBuff = ByteBuffer.wrap(bytes);
410+
return new Text(byteBuff);
401411
}
402412

403413
@Nullable

server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import org.elasticsearch.common.geo.GeoPoint;
2323
import org.elasticsearch.common.io.stream.Writeable.Writer;
2424
import org.elasticsearch.common.settings.SecureString;
25-
import org.elasticsearch.common.text.Text;
2625
import org.elasticsearch.common.util.ByteUtils;
2726
import org.elasticsearch.core.CharArrays;
2827
import org.elasticsearch.core.Nullable;
2928
import org.elasticsearch.core.TimeValue;
29+
import org.elasticsearch.xcontent.Text;
3030
import org.elasticsearch.xcontent.XContentType;
3131

3232
import java.io.IOException;
@@ -419,7 +419,7 @@ public void writeText(Text text) throws IOException {
419419
writeInt(spare.length());
420420
write(spare.bytes(), 0, spare.length());
421421
} else {
422-
BytesReference bytes = text.bytes();
422+
BytesReference bytes = BytesReference.fromByteBuffer(text.bytes());
423423
writeInt(bytes.length());
424424
bytes.writeTo(this);
425425
}

server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ public void apply(Settings value, Settings current, Settings previous) {
526526
IndexingMemoryController.MAX_INDEX_BUFFER_SIZE_SETTING,
527527
IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING,
528528
IndexingMemoryController.SHARD_MEMORY_INTERVAL_TIME_SETTING,
529+
IndexingMemoryController.PAUSE_INDEXING_ON_THROTTLE,
529530
ResourceWatcherService.ENABLED,
530531
ResourceWatcherService.RELOAD_INTERVAL_HIGH,
531532
ResourceWatcherService.RELOAD_INTERVAL_MEDIUM,

server/src/main/java/org/elasticsearch/index/codec/vectors/IVFVectorsFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747
public class IVFVectorsFormat extends KnnVectorsFormat {
4848

49-
static final FeatureFlag IVF_FORMAT_FEATURE_FLAG = new FeatureFlag("ivf_format");
49+
public static final FeatureFlag IVF_FORMAT_FEATURE_FLAG = new FeatureFlag("ivf_format");
5050
public static final String IVF_VECTOR_COMPONENT = "IVF";
5151
public static final String NAME = "IVFVectorsFormat";
5252
// centroid ordinals -> centroid values, offsets

0 commit comments

Comments
 (0)