Skip to content

Commit

Permalink
Support $ and / in ccr follow (#99892) (#100294)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks authored Oct 4, 2023
1 parent 9aa6c19 commit 657cb5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog/99892.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 99892
summary: Support $ and / in restore rename replacements
area: Snapshot/Restore
type: bug
issues:
- 99078
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 657cb5d

Please sign in to comment.