Skip to content

Commit 89efe2c

Browse files
authored
Fix MasterService to execute tasks in the context in which the task was originally created (#127799)
Previously MasterService executed tasks in a completely empty context rather than the original context which was captured when the task was created. This PR fixes MasterService to restore and use the original context. Fixes #108628
1 parent 696716c commit 89efe2c

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ tests:
6666
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
6767
method: test {p0=transform/transforms_start_stop/Test start already started transform}
6868
issue: https://github.com/elastic/elasticsearch/issues/98802
69-
- class: org.elasticsearch.xpack.deprecation.DeprecationHttpIT
70-
method: testDeprecatedSettingsReturnWarnings
71-
issue: https://github.com/elastic/elasticsearch/issues/108628
7269
- class: org.elasticsearch.xpack.shutdown.NodeShutdownIT
7370
method: testAllocationPreventedForRemoval
7471
issue: https://github.com/elastic/elasticsearch/issues/116363

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ public void onFailure(Exception failure) {
913913

914914
@Override
915915
public Releasable captureResponseHeaders() {
916-
final var storedContext = threadContext.newStoredContext();
916+
final var storedContext = threadContextSupplier.get();
917917
return Releasables.wrap(() -> {
918918
final var newResponseHeaders = threadContext.getResponseHeaders();
919919
if (newResponseHeaders.isEmpty()) {

server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ public void testThreadContext() {
299299
}
300300

301301
try (ThreadContext.StoredContext ignored = threadPool.getThreadContext().stashContext()) {
302-
303302
final var expectedHeaders = new HashMap<String, String>();
304303
expectedHeaders.put(randomIdentifier(), randomIdentifier());
305304
for (final var copiedHeader : Task.HEADERS_TO_COPY) {
@@ -319,8 +318,10 @@ public void testThreadContext() {
319318
new AckedClusterStateUpdateTask(ackedRequest(ackTimeout, masterTimeout), null) {
320319
@Override
321320
public ClusterState execute(ClusterState currentState) {
322-
assertTrue(threadPool.getThreadContext().isSystemContext());
323-
assertEquals(Collections.emptyMap(), threadPool.getThreadContext().getHeaders());
321+
// the task is executed in the context in which the task was originally created.
322+
// note: this is typically not a system context.
323+
assertExpectedThreadContext(Map.of());
324+
324325
expectedResponseHeaders.forEach(
325326
(name, values) -> values.forEach(v -> threadPool.getThreadContext().addResponseHeader(name, v))
326327
);

x-pack/plugin/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ tasks.named("yamlRestCompatTestTransform").configure({ task ->
105105
task.skipTest("esql/130_spatial/values unsupported for geo_point", "Spatial types are now supported in VALUES aggregation")
106106
task.skipTest("esql/130_spatial/values unsupported for geo_point status code", "Spatial types are now supported in VALUES aggregation")
107107
// Expected deprecation warning to compat yaml tests:
108-
task.addAllowedWarningRegex(".*rollup functionality will be removed in Elasticsearch.*")
108+
task.addAllowedWarningRegex(
109+
".*rollup functionality will be removed in Elasticsearch.*",
110+
// https://github.com/elastic/elasticsearch/issues/127911
111+
"Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed in a future Elasticsearch version."
112+
)
109113
task.skipTest("esql/40_tsdb/from doc with aggregate_metric_double", "TODO: support for subset of metric fields")
110114
task.skipTest("esql/40_tsdb/stats on aggregate_metric_double", "TODO: support for subset of metric fields")
111115
task.skipTest("esql/40_tsdb/from index pattern unsupported counter", "TODO: support for subset of metric fields")

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/profiling/10_basic.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
---
22
setup:
33
- requires:
4+
test_runner_features: [ "allowed_warnings_regex" ]
45
cluster_features: ["gte_v8.13.0"]
56
reason: "Universal Profiling test infrastructure is available in 8.12+"
67

78
- do:
9+
allowed_warnings_regex:
10+
# https://github.com/elastic/elasticsearch/issues/127911
11+
- "Index \\[\\.profiling-.*\\] name begins with a dot .* and will not be allowed in a future Elasticsearch version."
812
cluster.put_settings:
913
body:
1014
persistent:

0 commit comments

Comments
 (0)