Skip to content

Commit 657cb5d

Browse files
authored
Support $ and / in ccr follow (#99892) (#100294)
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.
1 parent 9aa6c19 commit 657cb5d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

docs/changelog/99892.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 99892
2+
summary: Support $ and / in restore rename replacements
3+
area: Snapshot/Restore
4+
type: bug
5+
issues:
6+
- 99078

x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ public void testFollowNonExistentIndex() throws Exception {
630630
);
631631
}
632632

633+
public void testFollowWith$InIndexName() throws Exception {
634+
String indexSettings = getIndexSettings(1, 0);
635+
assertAcked(leaderClient().admin().indices().prepareCreate("test-leader$").setSource(indexSettings, XContentType.JSON).get());
636+
followerClient().execute(PutFollowAction.INSTANCE, putFollow("test-leader$", "test-follower$")).actionGet();
637+
ensureFollowerGreen("test-follower$");
638+
}
639+
633640
public void testFollowIndexMaxOperationSizeInBytes() throws Exception {
634641
final String leaderIndexSettings = getIndexSettings(1, between(0, 1));
635642
assertAcked(leaderClient().admin().indices().prepareCreate("index1").setSource(leaderIndexSettings, XContentType.JSON));

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.Objects;
5252
import java.util.concurrent.Executor;
5353
import java.util.function.BiConsumer;
54+
import java.util.regex.Matcher;
5455
import java.util.stream.Collectors;
5556

5657
import static org.elasticsearch.cluster.metadata.DataStream.BACKING_INDEX_PREFIX;
@@ -185,7 +186,7 @@ private void createFollowerIndex(
185186
)
186187
.indicesOptions(request.indicesOptions())
187188
.renamePattern("^(.*)$")
188-
.renameReplacement(request.getFollowerIndex())
189+
.renameReplacement(Matcher.quoteReplacement(request.getFollowerIndex()))
189190
.masterNodeTimeout(request.masterNodeTimeout())
190191
.indexSettings(overrideSettings)
191192
.quiet(true);

0 commit comments

Comments
 (0)