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 ;
55
+ import org .opensearch .snapshots .SnapshotsService ;
51
56
import org .opensearch .test .OpenSearchIntegTestCase ;
52
57
53
58
import java .io .IOException ;
64
69
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT ;
65
70
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY ;
66
71
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY ;
72
+ import static org .opensearch .repositories .blobstore .BlobStoreRepository .REMOTE_STORE_INDEX_SHALLOW_COPY ;
73
+ import static org .opensearch .repositories .blobstore .BlobStoreRepository .SHALLOW_SNAPSHOT_V2 ;
74
+ import static org .opensearch .test .hamcrest .OpenSearchAssertions .assertAcked ;
67
75
import static org .hamcrest .Matchers .equalTo ;
68
76
69
77
/**
@@ -80,6 +88,7 @@ protected Settings nodeSettings() {
80
88
.put (Environment .PATH_HOME_SETTING .getKey (), tempDir )
81
89
.put (Environment .PATH_REPO_SETTING .getKey (), tempDir .resolve ("repo" ))
82
90
.put (Environment .PATH_SHARED_DATA_SETTING .getKey (), tempDir .getParent ())
91
+ .put (RemoteStoreSettings .CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED .getKey (), true )
83
92
.build ();
84
93
}
85
94
@@ -372,4 +381,119 @@ public void testRetrieveShallowCopySnapshotCase2() throws IOException {
372
381
assertThat (snapshotIds , equalTo (originalSnapshots ));
373
382
}
374
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
+ String invalidRepoName = "test" + SnapshotsService .SNAPSHOT_PINNED_TIMESTAMP_DELIMITER + "repo-1" ;
395
+ try {
396
+ createRepository (client , invalidRepoName , snapshotRepoSettings1 );
397
+ } catch (RepositoryException e ) {
398
+ assertEquals (
399
+ "["
400
+ + invalidRepoName
401
+ + "] setting shallow_snapshot_v2 cannot be enabled for repository with __ in the name as this delimiter is used to create pinning entity" ,
402
+ e .getMessage ()
403
+ );
404
+ }
405
+
406
+ // Create repo with shallow snapshot V2 enabled
407
+ createRepository (client , "test-repo-1" , snapshotRepoSettings1 );
408
+
409
+ logger .info ("--> verify the repository" );
410
+ VerifyRepositoryResponse verifyRepositoryResponse = client .admin ().cluster ().prepareVerifyRepository ("test-repo-1" ).get ();
411
+ assertNotNull (verifyRepositoryResponse .getNodes ());
412
+
413
+ GetRepositoriesResponse getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
414
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
415
+
416
+ Settings snapshotRepoSettings2 = Settings .builder ()
417
+ .put (node ().settings ())
418
+ .put ("location" , OpenSearchIntegTestCase .randomRepoPath (node ().settings ()))
419
+ .put (REMOTE_STORE_INDEX_SHALLOW_COPY .getKey (), true )
420
+ .put (SHALLOW_SNAPSHOT_V2 .getKey (), true )
421
+ .build ();
422
+
423
+ // Create another repo with shallow snapshot V2 enabled, this should fail.
424
+ try {
425
+ createRepository (client , "test-repo-2" , snapshotRepoSettings2 );
426
+ } catch (RepositoryException e ) {
427
+ assertEquals (
428
+ "[test-repo-2] setting shallow_snapshot_v2 cannot be enabled as this setting can be enabled only on one repository and one or more repositories in the cluster have the setting as enabled" ,
429
+ e .getMessage ()
430
+ );
431
+ }
432
+
433
+ // Disable shallow snapshot V2 setting on test-repo-1
434
+ updateRepository (
435
+ client ,
436
+ "test-repo-1" ,
437
+ Settings .builder ().put (snapshotRepoSettings1 ).put (SHALLOW_SNAPSHOT_V2 .getKey (), false ).build ()
438
+ );
439
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
440
+ assertFalse (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
441
+
442
+ // Create test-repo-2 with shallow snapshot V2 enabled, this should pass now.
443
+ createRepository (client , "test-repo-2" , snapshotRepoSettings2 );
444
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-2" ).get ();
445
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
446
+
447
+ final String indexName = "test-idx" ;
448
+ createIndex (indexName );
449
+ ensureGreen ();
450
+ indexDocuments (client , indexName );
451
+
452
+ // Create pinned timestamp snapshot in test-repo-2
453
+ SnapshotInfo snapshotInfo = createSnapshot ("test-repo-2" , "test-snap-2" , new ArrayList <>());
454
+ assertNotNull (snapshotInfo .snapshotId ());
455
+
456
+ // As snapshot is present, even after disabling shallow snapshot setting in test-repo-2, we will not be able to
457
+ // enable shallow snapshot v2 setting in test-repo-1
458
+ updateRepository (
459
+ client ,
460
+ "test-repo-2" ,
461
+ Settings .builder ().put (snapshotRepoSettings2 ).put (SHALLOW_SNAPSHOT_V2 .getKey (), false ).build ()
462
+ );
463
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-2" ).get ();
464
+ assertFalse (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
465
+
466
+ try {
467
+ updateRepository (client , "test-repo-1" , snapshotRepoSettings1 );
468
+ } catch (RepositoryException e ) {
469
+ assertEquals (
470
+ "[test-repo-1] setting shallow_snapshot_v2 cannot be enabled if there are existing snapshots created with shallow V2 setting using different repository." ,
471
+ e .getMessage ()
472
+ );
473
+ }
474
+
475
+ // After deleting the snapshot, we will be able to enable shallow snapshot v2 setting in test-repo-1
476
+ AcknowledgedResponse deleteSnapshotResponse = client ().admin ().cluster ().prepareDeleteSnapshot ("test-repo-2" , "test-snap-2" ).get ();
477
+
478
+ assertAcked (deleteSnapshotResponse );
479
+
480
+ updateRepository (client , "test-repo-1" , snapshotRepoSettings1 );
481
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
482
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
483
+
484
+ // Having a snapshot in the same repo should allow disabling and re-enabling shallow snapshot v2 setting
485
+ snapshotInfo = createSnapshot ("test-repo-1" , "test-snap-1" , new ArrayList <>());
486
+ assertNotNull (snapshotInfo .snapshotId ());
487
+ updateRepository (
488
+ client ,
489
+ "test-repo-1" ,
490
+ Settings .builder ().put (snapshotRepoSettings1 ).put (SHALLOW_SNAPSHOT_V2 .getKey (), false ).build ()
491
+ );
492
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
493
+ assertFalse (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
494
+
495
+ updateRepository (client , "test-repo-1" , snapshotRepoSettings1 );
496
+ getRepositoriesResponse = client .admin ().cluster ().prepareGetRepositories ("test-repo-1" ).get ();
497
+ assertTrue (SHALLOW_SNAPSHOT_V2 .get (getRepositoriesResponse .repositories ().get (0 ).settings ()));
498
+ }
375
499
}
0 commit comments