From 3b81ee7c13719a9a485b9fc97ac5a2f6063d89c0 Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Wed, 4 Oct 2023 12:07:57 -0600 Subject: [PATCH] Support $ and / in ccr follow (#99892) Currently the renameReplacement variable in the restore snapshot request is intended to be a string literal for ccr. However, when a string is passed to replaceAll in java $ and / will be treated as special characters. This means that following indices with $ in them breaks. This commit fixes the issue by quoting the special characters before calling replaceAll. Fixes #99078. --- docs/changelog/99892.yaml | 6 ++++++ .../java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java | 7 +++++++ .../xpack/ccr/action/TransportPutFollowAction.java | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/99892.yaml diff --git a/docs/changelog/99892.yaml b/docs/changelog/99892.yaml new file mode 100644 index 0000000000000..5090d1d888b65 --- /dev/null +++ b/docs/changelog/99892.yaml @@ -0,0 +1,6 @@ +pr: 99892 +summary: Support $ and / in restore rename replacements +area: Snapshot/Restore +type: bug +issues: + - 99078 diff --git a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 309805f9b80c4..dae2a102948dd 100644 --- a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -630,6 +630,13 @@ public void testFollowNonExistentIndex() throws Exception { ); } + public void testFollowWith$InIndexName() throws Exception { + String indexSettings = getIndexSettings(1, 0); + assertAcked(leaderClient().admin().indices().prepareCreate("test-leader$").setSource(indexSettings, XContentType.JSON).get()); + followerClient().execute(PutFollowAction.INSTANCE, putFollow("test-leader$", "test-follower$")).actionGet(); + ensureFollowerGreen("test-follower$"); + } + public void testFollowIndexMaxOperationSizeInBytes() throws Exception { final String leaderIndexSettings = getIndexSettings(1, between(0, 1)); assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON)); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index 713da462a90be..bc67a8fb35b07 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -51,6 +51,7 @@ import java.util.Objects; import java.util.concurrent.Executor; import java.util.function.BiConsumer; +import java.util.regex.Matcher; import java.util.stream.Collectors; import static org.elasticsearch.cluster.metadata.DataStream.BACKING_INDEX_PREFIX; @@ -185,7 +186,7 @@ private void createFollowerIndex( ) .indicesOptions(request.indicesOptions()) .renamePattern("^(.*)$") - .renameReplacement(request.getFollowerIndex()) + .renameReplacement(Matcher.quoteReplacement(request.getFollowerIndex())) .masterNodeTimeout(request.masterNodeTimeout()) .indexSettings(overrideSettings) .quiet(true);