Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Brooks committed Oct 3, 2023
1 parent 6d0cd8d commit f45ccc9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

public class DataStreamAlias implements SimpleDiffable<DataStreamAlias>, ToXContentFragment {
Expand Down Expand Up @@ -324,11 +323,9 @@ public DataStreamAlias restore(DataStreamAlias previous, String renamePattern, S

String writeDataStream = this.writeDataStream;
if (renamePattern != null && renameReplacement != null) {
this.dataStreams.stream()
.map(s -> s.replaceAll(renamePattern, Matcher.quoteReplacement(renameReplacement)))
.forEach(mergedDataStreams::add);
this.dataStreams.stream().map(s -> s.replaceAll(renamePattern, renameReplacement)).forEach(mergedDataStreams::add);
if (writeDataStream != null) {
writeDataStream = writeDataStream.replaceAll(renamePattern, Matcher.quoteReplacement(renameReplacement));
writeDataStream = writeDataStream.replaceAll(renamePattern, renameReplacement);
}
} else {
mergedDataStreams.addAll(this.dataStreams);
Expand All @@ -338,10 +335,7 @@ public DataStreamAlias restore(DataStreamAlias previous, String renamePattern, S
if (writeDataStream != null && previous.getWriteDataStream() != null) {
String previousWriteDataStream = previous.getWriteDataStream();
if (renamePattern != null && renameReplacement != null) {
previousWriteDataStream = previousWriteDataStream.replaceAll(
renamePattern,
Matcher.quoteReplacement(renameReplacement)
);
previousWriteDataStream = previousWriteDataStream.replaceAll(renamePattern, renameReplacement);
}
if (writeDataStream.equals(previousWriteDataStream) == false) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -694,7 +693,7 @@ private Set<Index> resolveSystemIndicesToDelete(ClusterState currentState, Set<S
static DataStream updateDataStream(DataStream dataStream, Metadata.Builder metadata, RestoreSnapshotRequest request) {
String dataStreamName = dataStream.getName();
if (request.renamePattern() != null && request.renameReplacement() != null) {
dataStreamName = dataStreamName.replaceAll(request.renamePattern(), Matcher.quoteReplacement(request.renameReplacement()));
dataStreamName = dataStreamName.replaceAll(request.renamePattern(), request.renameReplacement());
}
List<Index> updatedIndices = dataStream.getIndices()
.stream()
Expand Down Expand Up @@ -939,7 +938,7 @@ private static String renameIndex(String index, RestoreSnapshotRequest request,
if (partOfDataStream) {
index = index.substring(DataStream.BACKING_INDEX_PREFIX.length());
}
renamedIndex = index.replaceAll(request.renamePattern(), Matcher.quoteReplacement(request.renameReplacement()));
renamedIndex = index.replaceAll(request.renamePattern(), request.renameReplacement());
if (partOfDataStream) {
renamedIndex = DataStream.BACKING_INDEX_PREFIX + renamedIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,6 @@ public void testRestoreWithRename() {
assertThat(result.getDataStreams(), containsInAnyOrder("ds-1", "ds-2", "ds-3", "ds-4", "ds-5"));
assertThat(result.getWriteDataStream(), equalTo("ds-3"));
}
{
// Ensure that $ and / work
DataStreamAlias alias1 = new DataStreamAlias("my-alias", List.of("ds-1", "ds-2", "ds-3$"), "ds-3$", null);
DataStreamAlias alias2 = new DataStreamAlias("my-alias", List.of("ds-2", "ds-4/", "ds-5"), "ds-2", null);
DataStreamAlias result = alias1.restore(alias2, "ds-2", "ds-3$");
assertThat(result.getDataStreams(), containsInAnyOrder("ds-1", "ds-2", "ds-3$", "ds-4/", "ds-5"));
assertThat(result.getWriteDataStream(), equalTo("ds-3$"));
}
}

public void testRestoreDataStreamWithWriteDataStreamThatDoesNotExistInOriginalAlias() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testUpdateDataStream() {

public void testUpdateDataStreamRename() {
String dataStreamName = "data-stream-1";
String renamedDataStreamName = "data-stream-2$";
String renamedDataStreamName = "data-stream-2";
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1);
String renamedBackingIndexName = DataStream.getDefaultBackingIndexName(renamedDataStreamName, 1);
List<Index> indices = Collections.singletonList(new Index(backingIndexName, "uuid"));
Expand All @@ -82,7 +82,7 @@ public void testUpdateDataStreamRename() {
Index renamedIndex = new Index(renamedBackingIndexName, "uuid2");
when(indexMetadata.getIndex()).thenReturn(renamedIndex);

RestoreSnapshotRequest request = new RestoreSnapshotRequest().renamePattern("data-stream-1").renameReplacement("data-stream-2$");
RestoreSnapshotRequest request = new RestoreSnapshotRequest().renamePattern("data-stream-1").renameReplacement("data-stream-2");

DataStream renamedDataStream = RestoreService.updateDataStream(dataStream, metadata, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ 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-leader$")).actionGet();
followerClient().execute(PutFollowAction.INSTANCE, putFollow("test-leader$", "test-follower$")).actionGet();
ensureFollowerGreen("test-follower$");
}

public void testFollowIndexMaxOperationSizeInBytes() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 @@ -186,7 +187,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 f45ccc9

Please sign in to comment.