33
33
package org .opensearch .repositories .blobstore ;
34
34
35
35
import org .opensearch .action .admin .cluster .repositories .get .GetRepositoriesResponse ;
36
+ import org .opensearch .action .admin .cluster .repositories .verify .VerifyRepositoryResponse ;
37
+ import org .opensearch .action .support .master .AcknowledgedResponse ;
36
38
import org .opensearch .client .Client ;
37
39
import org .opensearch .cluster .metadata .RepositoryMetadata ;
38
40
import org .opensearch .common .settings .Settings ;
41
43
import org .opensearch .gateway .remote .RemoteClusterStateService ;
42
44
import org .opensearch .index .IndexSettings ;
43
45
import org .opensearch .index .snapshots .blobstore .RemoteStoreShardShallowCopySnapshot ;
46
+ import org .opensearch .indices .RemoteStoreSettings ;
44
47
import org .opensearch .indices .replication .common .ReplicationType ;
45
48
import org .opensearch .repositories .IndexId ;
46
49
import org .opensearch .repositories .RepositoriesService ;
47
50
import org .opensearch .repositories .RepositoryData ;
51
+ import org .opensearch .repositories .RepositoryException ;
48
52
import org .opensearch .repositories .fs .FsRepository ;
49
53
import org .opensearch .snapshots .SnapshotId ;
50
54
import org .opensearch .snapshots .SnapshotInfo ;
64
68
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT ;
65
69
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY ;
66
70
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY ;
71
+ import static org .opensearch .repositories .blobstore .BlobStoreRepository .REMOTE_STORE_INDEX_SHALLOW_COPY ;
72
+ import static org .opensearch .repositories .blobstore .BlobStoreRepository .SHALLOW_SNAPSHOT_V2 ;
73
+ import static org .opensearch .test .hamcrest .OpenSearchAssertions .assertAcked ;
67
74
import static org .hamcrest .Matchers .equalTo ;
68
75
69
76
/**
@@ -81,6 +88,7 @@ protected Settings nodeSettings() {
81
88
.put (Environment .PATH_HOME_SETTING .getKey (), tempDir )
82
89
.put (Environment .PATH_REPO_SETTING .getKey (), tempDir .resolve ("repo" ))
83
90
.put (Environment .PATH_SHARED_DATA_SETTING .getKey (), tempDir .getParent ())
91
+ .put (RemoteStoreSettings .CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED .getKey (), true )
84
92
.build ();
85
93
}
86
94
@@ -373,4 +381,78 @@ public void testRetrieveShallowCopySnapshotCase2() throws IOException {
373
381
assertThat (snapshotIds , equalTo (originalSnapshots ));
374
382
}
375
383
384
+ public void testRepositoryCreationShallowV2 () throws Exception {
385
+ Client client = client ();
386
+
387
+ Settings snapshotRepoSettings1 = Settings .builder ()
388
+ .put (node ().settings ())
389
+ .put ("location" , OpenSearchIntegTestCase .randomRepoPath (node ().settings ()))
390
+ .put (REMOTE_STORE_INDEX_SHALLOW_COPY .getKey (), true )
391
+ .put (SHALLOW_SNAPSHOT_V2 .getKey (), true )
392
+ .build ();
393
+
394
+ // Create repo with shallow snapshot V2 enabled
395
+ createRepository (client , "test-repo-1" , snapshotRepoSettings1 );
396
+
397
+ logger .info ("--> verify the repository" );
398
+ VerifyRepositoryResponse verifyRepositoryResponse = client .admin ().cluster ().prepareVerifyRepository ("test-repo-1" ).get ();
399
+ assertNotNull (verifyRepositoryResponse .getNodes ());
400
+
401
+ GetRepositoriesResponse getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
402
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
403
+
404
+ Settings snapshotRepoSettings2 = Settings .builder ()
405
+ .put (node ().settings ())
406
+ .put ("location" , OpenSearchIntegTestCase .randomRepoPath (node ().settings ()))
407
+ .put (REMOTE_STORE_INDEX_SHALLOW_COPY .getKey (), true )
408
+ .put (SHALLOW_SNAPSHOT_V2 .getKey (), true )
409
+ .build ();
410
+
411
+ // Create another repo with shallow snapshot V2 enabled, this should fail.
412
+ assertThrows (RepositoryException .class , () -> createRepository (client , "test-repo-2" , snapshotRepoSettings2 ));
413
+
414
+ // Disable shallow snapshot V2 setting on test-repo-1
415
+ updateRepository (
416
+ client ,
417
+ "test-repo-1" ,
418
+ Settings .builder ().put (snapshotRepoSettings1 ).put (SHALLOW_SNAPSHOT_V2 .getKey (), false ).build ()
419
+ );
420
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
421
+ assertFalse (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
422
+
423
+ // Create test-repo-2 with shallow snapshot V2 enabled, this should pass now.
424
+ createRepository (client , "test-repo-2" , snapshotRepoSettings2 );
425
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-2" ).get ();
426
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
427
+
428
+ final String indexName = "test-idx" ;
429
+ createIndex (indexName );
430
+ ensureGreen ();
431
+ indexDocuments (client , indexName );
432
+
433
+ // Create pinned timestamp snapshot in test-repo-2
434
+ SnapshotInfo snapshotInfo = createSnapshot ("test-repo-2" , "test-snap-1" , new ArrayList <>());
435
+ assertNotNull (snapshotInfo .snapshotId ());
436
+
437
+ // As snapshot is present, even after disabling shallow snapshot setting in test-repo-2, we will not be able to
438
+ // enable shallow snapshot v2 setting in test-repo-1
439
+ updateRepository (
440
+ client ,
441
+ "test-repo-2" ,
442
+ Settings .builder ().put (snapshotRepoSettings2 ).put (SHALLOW_SNAPSHOT_V2 .getKey (), false ).build ()
443
+ );
444
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-2" ).get ();
445
+ assertFalse (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
446
+
447
+ assertThrows (RepositoryException .class , () -> updateRepository (client , "test-repo-1" , snapshotRepoSettings1 ));
448
+
449
+ // After deleting the snapshot, we will be able to enable shallow snapshot v2 setting in test-repo-1
450
+ AcknowledgedResponse deleteSnapshotResponse = client ().admin ().cluster ().prepareDeleteSnapshot ("test-repo-2" , "test-snap-1" ).get ();
451
+
452
+ assertAcked (deleteSnapshotResponse );
453
+
454
+ updateRepository (client , "test-repo-1" , snapshotRepoSettings1 );
455
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
456
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
457
+ }
376
458
}
0 commit comments