1
0
Эх сурвалжийг харах

[Transform] Do not fail upon ResourceAlreadyExistsException during destination index creation (#96274)

Przemysław Witek 2 жил өмнө
parent
commit
e35e40a8df

+ 7 - 0
docs/changelog/96274.yaml

@@ -0,0 +1,7 @@
+pr: 96274
+summary: Do not fail upon `ResourceAlreadyExistsException` during destination index
+  creation
+area: Transform
+type: bug
+issues:
+ - 95310

+ 2 - 4
x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformDestIndexIT.java

@@ -109,7 +109,6 @@ public class TransformDestIndexIT extends TransformRestTestCase {
         assertAliases(destIndex2, destAliasAll, destAliasLatest);
     }
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/95310")
     public void testTransformDestIndexCreatedDuringUpdate() throws Exception {
         String transformId = "test_dest_index_on_update";
         String destIndex = transformId + "-dest";
@@ -130,11 +129,10 @@ public class TransformDestIndexIT extends TransformRestTestCase {
         );
         startTransform(transformId);
 
-        // Verify that the destination index does not exist
-        assertFalse(indexExists(destIndex));
-
         // Update the unattended transform. This will trigger destination index creation.
         // The update has to change something in the config (here, max_page_search_size). Otherwise it would have been optimized away.
+        // Note that at this point the destination index could have already been created by the indexing process of the running transform
+        // but the update code should cope with this situation.
         updateTransform(transformId, """
             { "settings": { "max_page_search_size": 123 } }""");
 

+ 11 - 5
x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformIndex.java

@@ -9,6 +9,7 @@ package org.elasticsearch.xpack.transform.persistence;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.elasticsearch.ResourceAlreadyExistsException;
 import org.elasticsearch.Version;
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -160,9 +161,9 @@ public final class TransformIndex {
                     }
                     createDestinationIndexListener.onResponse(false);
                 }, e -> {
-                    String msg = "Unable to determine destination index stats, error: " + e.getMessage();
-                    logger.warn(msg, e);
-                    auditor.warning(config.getId(), msg);
+                    String message = "Unable to determine destination index stats, error: " + e.getMessage();
+                    logger.warn(message, e);
+                    auditor.warning(config.getId(), message);
                     createDestinationIndexListener.onResponse(false);
                 }),
                 client.admin().indices()::stats
@@ -192,12 +193,17 @@ public final class TransformIndex {
             ActionListener.wrap(createIndexResponse -> {
                 listener.onResponse(true);
             }, e -> {
+                if (e instanceof ResourceAlreadyExistsException) {
+                    // Already existing index is ok, it could have been created by the indexing process of the running transform.
+                    listener.onResponse(false);
+                    return;
+                }
                 String message = TransformMessages.getMessage(
                     TransformMessages.FAILED_TO_CREATE_DESTINATION_INDEX,
                     config.getDestination().getIndex(),
                     config.getId()
                 );
-                logger.error(message);
+                logger.error(message, e);
                 listener.onFailure(new RuntimeException(message, e));
             })
         );
@@ -236,7 +242,7 @@ public final class TransformIndex {
                     config.getDestination().getIndex(),
                     config.getId()
                 );
-                logger.error(message);
+                logger.error(message, e);
                 listener.onFailure(new RuntimeException(message, e));
             })
         );