Browse Source

[Transform] Consider search context missing exceptions as recoverable (#102602)

Przemysław Witek 1 year ago
parent
commit
3d5472a9ae

+ 5 - 0
docs/changelog/102602.yaml

@@ -0,0 +1,5 @@
+pr: 102602
+summary: Consider search context missing exceptions as recoverable
+area: Transform
+type: bug
+issues: []

+ 5 - 0
x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/utils/ExceptionRootCauseFinder.java

@@ -10,6 +10,7 @@ package org.elasticsearch.xpack.transform.utils;
 import org.elasticsearch.ElasticsearchException;
 import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.rest.RestStatus;
+import org.elasticsearch.search.SearchContextMissingException;
 import org.elasticsearch.tasks.TaskCancelledException;
 
 import java.util.Collection;
@@ -82,6 +83,10 @@ public final class ExceptionRootCauseFinder {
             if (elasticsearchException instanceof TaskCancelledException) {
                 return false;
             }
+            // We can safely retry SearchContextMissingException instead of failing the transform.
+            if (elasticsearchException instanceof SearchContextMissingException) {
+                return false;
+            }
             return true;
         }
         return false;

+ 7 - 1
x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/utils/ExceptionRootCauseFinderTests.java

@@ -21,6 +21,8 @@ import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.index.translog.TranslogException;
 import org.elasticsearch.indices.IndexClosedException;
 import org.elasticsearch.rest.RestStatus;
+import org.elasticsearch.search.SearchContextMissingException;
+import org.elasticsearch.search.internal.ShardSearchContextId;
 import org.elasticsearch.tasks.TaskCancelledException;
 import org.elasticsearch.test.ESTestCase;
 import org.elasticsearch.xcontent.XContentLocation;
@@ -158,6 +160,11 @@ public class ExceptionRootCauseFinderTests extends ESTestCase {
     public void testIsIrrecoverable() {
         assertFalse(ExceptionRootCauseFinder.isExceptionIrrecoverable(new MapperException("mappings problem")));
         assertFalse(ExceptionRootCauseFinder.isExceptionIrrecoverable(new TaskCancelledException("cancelled task")));
+        assertFalse(
+            ExceptionRootCauseFinder.isExceptionIrrecoverable(
+                new SearchContextMissingException(new ShardSearchContextId("session-id", 123, null))
+            )
+        );
         assertFalse(
             ExceptionRootCauseFinder.isExceptionIrrecoverable(
                 new CircuitBreakingException("circuit broken", CircuitBreaker.Durability.TRANSIENT)
@@ -175,5 +182,4 @@ public class ExceptionRootCauseFinderTests extends ESTestCase {
         assertEquals(t.getClass(), expectedClass);
         assertEquals(t.getMessage(), message);
     }
-
 }