Skip to content

Commit

Permalink
Do not allow shallow snapshot v2 repo name to contain SNAPSHOT_PINNED…
Browse files Browse the repository at this point in the history
…_TIMESTAMP_DELIMITER

Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
sachinpkale committed Sep 12, 2024
1 parent 0d86005 commit de752dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,16 @@ public static void validateRepositoryMetadataSettings(
+ minVersionInCluster
);
}
if (repositoryName.contains(SnapshotsService.SNAPSHOT_PINNED_TIMESTAMP_DELIMITER)) {
throw new RepositoryException(
repositoryName,
"setting "
+ SHALLOW_SNAPSHOT_V2.getKey()
+ " cannot be enabled for repository with "
+ SnapshotsService.SNAPSHOT_PINNED_TIMESTAMP_DELIMITER
+ " in the name as this delimiter is used to create pinning entity"
);
}
if (repositoryWithShallowV2Exists(repositories)) {
throw new RepositoryException(
repositoryName,
Expand Down Expand Up @@ -766,17 +776,9 @@ private static boolean pinnedTimestampExistsWithDifferentRepository(
settings,
repositoriesService
);
for (String pinningEntiy : pinningEntityTimestampMap.keySet()) {
String[] tokens = pinningEntiy.split(SnapshotsService.SNAPSHOT_PINNED_TIMESTAMP_DELIMITER);
if (tokens.length > 2) {
logger.warn(
"With more than one {} in the pinning entity = {}, not able to determine if there is a pinned timestamp created with different repository",
SnapshotsService.SNAPSHOT_PINNED_TIMESTAMP_DELIMITER,
pinningEntiy
);
return true;
}
if (tokens[0].equals(newRepoName) == false) {
for (String pinningEntity : pinningEntityTimestampMap.keySet()) {
String repoNameWithPinnedTimestamps = pinningEntity.split(SnapshotsService.SNAPSHOT_PINNED_TIMESTAMP_DELIMITER)[0];
if (repoNameWithPinnedTimestamps.equals(newRepoName) == false) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.opensearch.repositories.fs.FsRepository;
import org.opensearch.snapshots.SnapshotId;
import org.opensearch.snapshots.SnapshotInfo;
import org.opensearch.snapshots.SnapshotsService;
import org.opensearch.test.OpenSearchIntegTestCase;

import java.io.IOException;
Expand Down Expand Up @@ -391,6 +392,18 @@ public void testRepositoryCreationShallowV2() throws Exception {
.put(SHALLOW_SNAPSHOT_V2.getKey(), true)
.build();

String invalidRepoName = "test" + SnapshotsService.SNAPSHOT_PINNED_TIMESTAMP_DELIMITER + "repo-1";
try {
createRepository(client, invalidRepoName, snapshotRepoSettings1);
} catch (RepositoryException e) {
assertEquals(
"["
+ invalidRepoName
+ "] setting shallow_snapshot_v2 cannot be enabled for repository with __ in the name as this delimiter is used to create pinning entity",
e.getMessage()
);
}

// Create repo with shallow snapshot V2 enabled
createRepository(client, "test-repo-1", snapshotRepoSettings1);

Expand Down

0 comments on commit de752dc

Please sign in to comment.