Skip to content

Commit f16029f

Browse files
authored
Merge branch 'main' into entitlements/files-policy-base-dir
2 parents 1116b90 + 2c846e7 commit f16029f

File tree

33 files changed

+610
-135
lines changed

33 files changed

+610
-135
lines changed

docs/changelog/122074.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pr: 122074
2+
summary: If the Transform is configured to write to an alias as its destination index,
3+
when the delete_dest_index parameter is set to true, then the Delete API will now
4+
delete the write index backing the alias
5+
area: Transform
6+
type: bug
7+
issues:
8+
- 121913

docs/changelog/122365.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122365
2+
summary: Fix handling of auto expand replicas for stateless indices
3+
area: "Search"
4+
type: bug
5+
issues: []

muted-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ tests:
320320
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
321321
method: testGetUsersWithProfileUid
322322
issue: https://github.com/elastic/elasticsearch/issues/121483
323-
- class: org.elasticsearch.xpack.transform.checkpoint.TransformCCSCanMatchIT
324-
method: testTransformLifecycle_RangeQueryThatMatchesNoShards
325-
issue: https://github.com/elastic/elasticsearch/issues/121480
326323
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
327324
method: testSuggestProfilesWithHint
328325
issue: https://github.com/elastic/elasticsearch/issues/121116
@@ -404,6 +401,9 @@ tests:
404401
issue: https://github.com/elastic/elasticsearch/issues/122377
405402
- class: org.elasticsearch.repositories.blobstore.testkit.analyze.HdfsRepositoryAnalysisRestIT
406403
issue: https://github.com/elastic/elasticsearch/issues/122378
404+
- class: org.elasticsearch.xpack.esql.action.EsqlActionBreakerIT
405+
method: testStatsMissingFieldWithStats
406+
issue: https://github.com/elastic/elasticsearch/issues/122327
407407

408408
# Examples:
409409
#

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static TransportVersion def(int id) {
185185
public static final TransportVersion ESQL_DRIVER_TASK_DESCRIPTION = def(9_005_0_00);
186186
public static final TransportVersion ESQL_RETRY_ON_SHARD_LEVEL_FAILURE = def(9_006_0_00);
187187
public static final TransportVersion ESQL_PROFILE_ASYNC_NANOS = def(9_007_00_0);
188+
public static final TransportVersion ESQL_LOOKUP_JOIN_SOURCE_TEXT = def(9_008_0_00);
188189

189190
/*
190191
* STOP! READ THIS FIRST! No, really,
@@ -197,6 +198,8 @@ static TransportVersion def(int id) {
197198
* A new transport version should be added EVERY TIME a change is made to the serialization protocol of one or more classes. Each
198199
* transport version should only be used in a single merged commit (apart from the BwC versions copied from o.e.Version, ≤V_8_8_1).
199200
*
201+
* More information about versions and backporting at docs/internal/Versioning.md
202+
*
200203
* ADDING A TRANSPORT VERSION
201204
* To add a new transport version, add a new constant at the bottom of the list, above this comment. Don't add other lines,
202205
* comments, etc. The version id has the following layout:

server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ public static Map<Integer, List<String>> getAutoExpandReplicaChanges(
156156
)) {
157157
if (indexMetadata.getNumberOfReplicas() == 0) {
158158
nrReplicasChanged.computeIfAbsent(1, ArrayList::new).add(indexMetadata.getIndex().getName());
159-
} else {
160-
continue;
161159
}
160+
continue;
162161
}
163162
if (allocation == null) {
164163
allocation = allocationSupplier.get();

server/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,16 +438,7 @@ public static boolean isKeyDesc(BucketOrder order) {
438438
* @return {@code true} if the order matches, {@code false} otherwise.
439439
*/
440440
private static boolean isOrder(BucketOrder order, BucketOrder expected) {
441-
if (order == expected) {
442-
return true;
443-
} else if (order instanceof CompoundOrder) {
444-
// check if its a compound order with the first element that matches
445-
List<BucketOrder> orders = ((CompoundOrder) order).orderElements;
446-
if (orders.size() >= 1) {
447-
return isOrder(orders.get(0), expected);
448-
}
449-
}
450-
return false;
441+
return order == expected || (order instanceof CompoundOrder compoundOrder && compoundOrder.orderElements.getFirst() == expected);
451442
}
452443

453444
/**

server/src/test/java/org/elasticsearch/cluster/metadata/AutoExpandReplicasTests.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
2121
import org.elasticsearch.cluster.routing.RoutingNodesHelper;
2222
import org.elasticsearch.cluster.routing.ShardRoutingState;
23+
import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator;
2324
import org.elasticsearch.common.settings.Settings;
2425
import org.elasticsearch.core.Strings;
26+
import org.elasticsearch.index.IndexVersion;
2527
import org.elasticsearch.indices.cluster.ClusterStateChanges;
2628
import org.elasticsearch.test.ESTestCase;
2729
import org.elasticsearch.threadpool.TestThreadPool;
@@ -31,11 +33,14 @@
3133
import java.util.Collections;
3234
import java.util.HashSet;
3335
import java.util.List;
36+
import java.util.Map;
3437
import java.util.Set;
3538
import java.util.concurrent.atomic.AtomicInteger;
3639
import java.util.stream.Collectors;
3740

41+
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING;
3842
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS;
43+
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
3944
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
4045
import static org.hamcrest.Matchers.equalTo;
4146
import static org.hamcrest.Matchers.everyItem;
@@ -221,4 +226,48 @@ public void testCalculateDesiredNumberOfReplicas() {
221226
assertThat(autoExpandReplicas.calculateDesiredNumberOfReplicas(matchingNodes), equalTo(Math.max(lowerBound, matchingNodes - 1)));
222227
assertThat(autoExpandReplicas.calculateDesiredNumberOfReplicas(max + 1), equalTo(max));
223228
}
229+
230+
public void testGetAutoExpandReplicaChangesStatelessIndices() {
231+
{
232+
// number of replicas is adjusted to 1 when it is initialized to 0
233+
Metadata metadata = Metadata.builder()
234+
.put(
235+
IndexMetadata.builder("test")
236+
.settings(
237+
Settings.builder()
238+
.put(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey(), "stateless")
239+
.put("index.version.created", IndexVersion.current())
240+
.put(SETTING_NUMBER_OF_SHARDS, 1)
241+
.put(SETTING_NUMBER_OF_REPLICAS, 0)
242+
.put(INDEX_AUTO_EXPAND_REPLICAS_SETTING.getKey(), "0-all")
243+
)
244+
)
245+
.build();
246+
Map<Integer, List<String>> autoExpandReplicaChanges = AutoExpandReplicas.getAutoExpandReplicaChanges(metadata, null);
247+
assertEquals(1, autoExpandReplicaChanges.size());
248+
List<String> indices = autoExpandReplicaChanges.get(1);
249+
assertEquals(1, indices.size());
250+
assertEquals("test", indices.getFirst());
251+
}
252+
{
253+
// no changes when number of replicas is set to anything other than 0
254+
Metadata metadata = Metadata.builder()
255+
.put(
256+
IndexMetadata.builder("test")
257+
.settings(
258+
Settings.builder()
259+
.put(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey(), "stateless")
260+
.put("index.version.created", IndexVersion.current())
261+
.put(SETTING_NUMBER_OF_SHARDS, 1)
262+
.put(SETTING_NUMBER_OF_REPLICAS, randomIntBetween(1, 10))
263+
.put(INDEX_AUTO_EXPAND_REPLICAS_SETTING.getKey(), "0-all")
264+
)
265+
)
266+
.build();
267+
Map<Integer, List<String>> autoExpandReplicaChanges = AutoExpandReplicas.getAutoExpandReplicaChanges(metadata, () -> {
268+
throw new UnsupportedOperationException();
269+
});
270+
assertEquals(0, autoExpandReplicaChanges.size());
271+
}
272+
}
224273
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/AsyncOperator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.io.stream.StreamInput;
1818
import org.elasticsearch.common.io.stream.StreamOutput;
1919
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
20+
import org.elasticsearch.common.util.concurrent.ThreadContext;
2021
import org.elasticsearch.compute.data.Page;
2122
import org.elasticsearch.core.TimeValue;
2223
import org.elasticsearch.index.seqno.LocalCheckpointTracker;
@@ -34,6 +35,11 @@
3435
* to reduce communication overhead and fetches a {@code Fetched} at a time.
3536
* It's the responsibility of subclasses to transform that {@code Fetched} into
3637
* output.
38+
* <p>
39+
* This operator will also take care of merging response headers from the thread context into the main thread,
40+
* which <b>must</b> be the one that closes this.
41+
* </p>
42+
*
3743
* @see #performAsync(Page, ActionListener)
3844
*/
3945
public abstract class AsyncOperator<Fetched> implements Operator {
@@ -45,6 +51,7 @@ public abstract class AsyncOperator<Fetched> implements Operator {
4551
private final DriverContext driverContext;
4652

4753
private final int maxOutstandingRequests;
54+
private final ResponseHeadersCollector responseHeadersCollector;
4855
private final LongAdder processNanos = new LongAdder();
4956

5057
private boolean finished = false;
@@ -66,9 +73,10 @@ public abstract class AsyncOperator<Fetched> implements Operator {
6673
*
6774
* @param maxOutstandingRequests the maximum number of outstanding requests
6875
*/
69-
public AsyncOperator(DriverContext driverContext, int maxOutstandingRequests) {
76+
public AsyncOperator(DriverContext driverContext, ThreadContext threadContext, int maxOutstandingRequests) {
7077
this.driverContext = driverContext;
7178
this.maxOutstandingRequests = maxOutstandingRequests;
79+
this.responseHeadersCollector = new ResponseHeadersCollector(threadContext);
7280
}
7381

7482
@Override
@@ -97,6 +105,7 @@ public void addInput(Page input) {
97105
});
98106
final long startNanos = System.nanoTime();
99107
performAsync(input, ActionListener.runAfter(listener, () -> {
108+
responseHeadersCollector.collect();
100109
driverContext.removeAsyncAction();
101110
processNanos.add(System.nanoTime() - startNanos);
102111
}));
@@ -172,6 +181,7 @@ public final void close() {
172181
finish();
173182
closed = true;
174183
discardResults();
184+
responseHeadersCollector.finish();
175185
doClose();
176186
}
177187

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/Warnings.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,23 @@ private Warnings(int lineNumber, int columnNumber, String sourceText, String fir
102102
}
103103

104104
public void registerException(Exception exception) {
105+
registerException(exception.getClass(), exception.getMessage());
106+
}
107+
108+
/**
109+
* Register an exception to be included in the warnings.
110+
* <p>
111+
* This overload avoids the need to instantiate the exception, which can be expensive.
112+
* Instead, it asks only the required pieces to build the warning.
113+
* </p>
114+
*/
115+
public void registerException(Class<? extends Exception> exceptionClass, String message) {
105116
if (addedWarnings < MAX_ADDED_WARNINGS) {
106117
if (addedWarnings == 0) {
107118
addWarning(first);
108119
}
109120
// location needs to be added to the exception too, since the headers are deduplicated
110-
addWarning(location + exception.getClass().getName() + ": " + exception.getMessage());
121+
addWarning(location + exceptionClass.getName() + ": " + message);
111122
addedWarnings++;
112123
}
113124
}

0 commit comments

Comments
 (0)