Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] BugFix - Extract snapshot UUID from pinned entity correctly #16401

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ private void cleanOrphanTimestamp(String repoName, RepositoryData repositoryData
deleteOrphanTimestamps(pinnedEntities, orphanPinnedEntities);
}

private boolean isOrphanPinnedEntity(String repoName, Collection<String> snapshotUUIDs, String pinnedEntity) {
static boolean isOrphanPinnedEntity(String repoName, Collection<String> snapshotUUIDs, String pinnedEntity) {
Tuple<String, String> tokens = getRepoSnapshotUUIDTuple(pinnedEntity);
return Objects.equals(tokens.v1(), repoName) && snapshotUUIDs.contains(tokens.v2()) == false;
}
Expand Down Expand Up @@ -931,7 +931,8 @@ public static String getPinningEntity(String repositoryName, String snapshotUUID

public static Tuple<String, String> getRepoSnapshotUUIDTuple(String pinningEntity) {
String[] tokens = pinningEntity.split(SNAPSHOT_PINNED_TIMESTAMP_DELIMITER);
return new Tuple<>(tokens[0], tokens[1]);
String snapUUID = String.join(SNAPSHOT_PINNED_TIMESTAMP_DELIMITER, Arrays.copyOfRange(tokens, 1, tokens.length));
return new Tuple<>(tokens[0], snapUUID);
}

private void cloneSnapshotPinnedTimestamp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.cluster.routing.TestShardRouting;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.UUIDs;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
Expand All @@ -68,6 +69,7 @@
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -78,6 +80,7 @@
import org.mockito.ArgumentCaptor;

import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED;
import static org.opensearch.snapshots.SnapshotsService.getRepoSnapshotUUIDTuple;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -804,6 +807,36 @@ public void testRunReadyCloneCompletionListenerFailure() throws Exception {
assertEquals(expectedUpdate.hashCode(), capturedUpdate.hashCode());
}

public void testGetRepoSnapshotUUIDTuple() {
String repoName = "repoName";
String pinningEntity = "repoName__OstrHGrERqaR__-597zHYQ";
Tuple<String, String> t = getRepoSnapshotUUIDTuple(pinningEntity);
assertEquals(repoName, t.v1());
assertEquals("OstrHGrERqaR__-597zHYQ", t.v2());
}

public void testIsOrphanPinnedEntity() {
String repoName = "repoName";
ArrayList<String> snapshotUUIDs = new ArrayList<>(
Arrays.asList("OouZCQ30TqypFBZGgk1C7g", "RSP6GLJfSO6SsMmUjZNAaA", "OstrHGrERqaR__-597zHYQ, Zjlnf8IHRxqFBijj0m52gw")
);

ArrayList<String> pinnedEntities = new ArrayList<>(
Arrays.asList(
"repoName__OouZCQ30TqypFBZGgk1C7g",
"repoName__RSP6GLJfSO6SsMmUjZNAaA",
"repoName__OstrHGrERqaR__-597zHYQ, Zjlnf8IHRxqFBijj0m52gw"
)
);

for (String pinnedEntity : pinnedEntities) {
assertFalse(SnapshotsService.isOrphanPinnedEntity(repoName, snapshotUUIDs, pinnedEntity));
}

String orphanEntity = "repoName__orphan";
assertTrue(SnapshotsService.isOrphanPinnedEntity(repoName, snapshotUUIDs, orphanEntity));
}

/**
* Helper method to create a SnapshotsService instance with a provided ClusterService.
* This method mocks all necessary dependencies for the SnapshotsService.
Expand Down
Loading