Skip to content

Commit 2a070af

Browse files
authored
[Transform] Do not fail upon ResourceAlreadyExistsException during destination index creation (#96274) (#96288)
1 parent ac028d0 commit 2a070af

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

docs/changelog/96274.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pr: 96274
2+
summary: Do not fail upon `ResourceAlreadyExistsException` during destination index
3+
creation
4+
area: Transform
5+
type: bug
6+
issues:
7+
- 95310

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public void testTransformDestIndexAliases() throws Exception {
109109
assertAliases(destIndex2, destAliasAll, destAliasLatest);
110110
}
111111

112-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/95310")
113112
public void testTransformDestIndexCreatedDuringUpdate() throws Exception {
114113
String transformId = "test_dest_index_on_update";
115114
String destIndex = transformId + "-dest";
@@ -130,11 +129,10 @@ public void testTransformDestIndexCreatedDuringUpdate() throws Exception {
130129
);
131130
startTransform(transformId);
132131

133-
// Verify that the destination index does not exist
134-
assertFalse(indexExists(destIndex));
135-
136132
// Update the unattended transform. This will trigger destination index creation.
137133
// The update has to change something in the config (here, max_page_search_size). Otherwise it would have been optimized away.
134+
// Note that at this point the destination index could have already been created by the indexing process of the running transform
135+
// but the update code should cope with this situation.
138136
updateTransform(transformId, """
139137
{ "settings": { "max_page_search_size": 123 } }""");
140138

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12+
import org.elasticsearch.ResourceAlreadyExistsException;
1213
import org.elasticsearch.Version;
1314
import org.elasticsearch.action.ActionListener;
1415
import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -160,9 +161,9 @@ public static void createDestinationIndex(
160161
}
161162
createDestinationIndexListener.onResponse(false);
162163
}, e -> {
163-
String msg = "Unable to determine destination index stats, error: " + e.getMessage();
164-
logger.warn(msg, e);
165-
auditor.warning(config.getId(), msg);
164+
String message = "Unable to determine destination index stats, error: " + e.getMessage();
165+
logger.warn(message, e);
166+
auditor.warning(config.getId(), message);
166167
createDestinationIndexListener.onResponse(false);
167168
}),
168169
client.admin().indices()::stats
@@ -192,12 +193,17 @@ static void createDestinationIndex(
192193
ActionListener.wrap(createIndexResponse -> {
193194
listener.onResponse(true);
194195
}, e -> {
196+
if (e instanceof ResourceAlreadyExistsException) {
197+
// Already existing index is ok, it could have been created by the indexing process of the running transform.
198+
listener.onResponse(false);
199+
return;
200+
}
195201
String message = TransformMessages.getMessage(
196202
TransformMessages.FAILED_TO_CREATE_DESTINATION_INDEX,
197203
config.getDestination().getIndex(),
198204
config.getId()
199205
);
200-
logger.error(message);
206+
logger.error(message, e);
201207
listener.onFailure(new RuntimeException(message, e));
202208
})
203209
);
@@ -236,7 +242,7 @@ static void setUpDestinationAliases(Client client, TransformConfig config, Actio
236242
config.getDestination().getIndex(),
237243
config.getId()
238244
);
239-
logger.error(message);
245+
logger.error(message, e);
240246
listener.onFailure(new RuntimeException(message, e));
241247
})
242248
);

0 commit comments

Comments
 (0)