浏览代码

Don't generate stacktrace in TaskCancelledException (#125002)

Ignacio Vera 7 月之前
父节点
当前提交
aba54e8af8

+ 5 - 0
docs/changelog/125002.yaml

@@ -0,0 +1,5 @@
+pr: 125002
+summary: Don't generate stacktrace in `TaskCancelledException`
+area: Search
+type: bug
+issues: []

+ 4 - 3
modules/aggregations/src/internalClusterTest/java/org/elasticsearch/aggregations/bucket/SearchCancellationIT.java

@@ -43,6 +43,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
 
 
 public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
 public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
 
 
@@ -97,9 +98,7 @@ public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
         }
         }
 
 
         logger.info("Executing search");
         logger.info("Executing search");
-        // we have to explicitly set error_trace=true for the later exception check for `TimeSeriesIndexSearcher`
         Client client = client();
         Client client = client();
-        client.threadPool().getThreadContext().putHeader("error_trace", "true");
         TimeSeriesAggregationBuilder timeSeriesAggregationBuilder = new TimeSeriesAggregationBuilder("test_agg");
         TimeSeriesAggregationBuilder timeSeriesAggregationBuilder = new TimeSeriesAggregationBuilder("test_agg");
         ActionFuture<SearchResponse> searchResponse = client.prepareSearch("test")
         ActionFuture<SearchResponse> searchResponse = client.prepareSearch("test")
             .setQuery(matchAllQuery())
             .setQuery(matchAllQuery())
@@ -129,7 +128,9 @@ public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
         logger.info("All shards failed with", ex);
         logger.info("All shards failed with", ex);
         if (lowLevelCancellation) {
         if (lowLevelCancellation) {
             // Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase
             // Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase
-            assertThat(ExceptionsHelper.stackTrace(ex), containsString("TimeSeriesIndexSearcher"));
+            assertThat(ExceptionsHelper.stackTrace(ex), not(containsString("not building sub-aggregations due to task cancellation")));
+        } else {
+            assertThat(ExceptionsHelper.stackTrace(ex), containsString("not building sub-aggregations due to task cancellation"));
         }
         }
     }
     }
 }
 }

+ 5 - 0
server/src/main/java/org/elasticsearch/tasks/TaskCancelledException.java

@@ -27,6 +27,11 @@ public class TaskCancelledException extends ElasticsearchException {
         super(in);
         super(in);
     }
     }
 
 
+    @Override
+    public Throwable fillInStackTrace() {
+        return this;  // this exception doesn't imply a bug, no need for a stack trace
+    }
+
     @Override
     @Override
     public RestStatus status() {
     public RestStatus status() {
         // Tasks are typically cancelled at the request of the client, so a 4xx status code is more accurate than the default of 500 (and
         // Tasks are typically cancelled at the request of the client, so a 4xx status code is more accurate than the default of 500 (and