Skip to content

Commit

Permalink
BugFix - Extract snapshot UUID from pinned entity correctly (#16398)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Bafna <gbbafna@amazon.com>
(cherry picked from commit c4a9cc1)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Oct 21, 2024
1 parent 1a48a08 commit 039f894
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
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

0 comments on commit 039f894

Please sign in to comment.