11
11
import org .opensearch .action .DocWriteResponse ;
12
12
import org .opensearch .action .admin .cluster .remotestore .restore .RestoreRemoteStoreRequest ;
13
13
import org .opensearch .action .admin .cluster .snapshots .create .CreateSnapshotResponse ;
14
+ import org .opensearch .action .admin .cluster .snapshots .get .GetSnapshotsRequest ;
15
+ import org .opensearch .action .admin .cluster .snapshots .get .GetSnapshotsResponse ;
14
16
import org .opensearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
15
17
import org .opensearch .action .admin .indices .delete .DeleteIndexRequest ;
16
18
import org .opensearch .action .admin .indices .recovery .RecoveryResponse ;
25
27
import org .opensearch .common .blobstore .BlobPath ;
26
28
import org .opensearch .common .io .PathUtils ;
27
29
import org .opensearch .common .settings .Settings ;
30
+ import org .opensearch .common .unit .TimeValue ;
28
31
import org .opensearch .common .util .io .IOUtils ;
29
32
import org .opensearch .core .common .unit .ByteSizeUnit ;
30
33
import org .opensearch .core .index .Index ;
63
66
import java .util .Objects ;
64
67
import java .util .Optional ;
65
68
import java .util .concurrent .ExecutionException ;
69
+ import java .util .concurrent .TimeUnit ;
66
70
import java .util .stream .Collectors ;
67
71
import java .util .stream .Stream ;
68
72
@@ -997,7 +1001,7 @@ public void testConcurrentSnapshotV2CreateOperation() throws InterruptedExceptio
997
1001
assertThat (repositoryData .getSnapshotIds ().size (), greaterThanOrEqualTo (1 ));
998
1002
}
999
1003
1000
- public void testConcurrentSnapshotV2CreateOperation_MasterChange () throws InterruptedException , ExecutionException , IOException {
1004
+ public void testConcurrentSnapshotV2CreateOperation_MasterChange () throws Exception {
1001
1005
internalCluster ().startClusterManagerOnlyNode (pinnedTimestampSettings ());
1002
1006
internalCluster ().startClusterManagerOnlyNode (pinnedTimestampSettings ());
1003
1007
internalCluster ().startClusterManagerOnlyNode (pinnedTimestampSettings ());
@@ -1033,14 +1037,16 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
1033
1037
Thread thread = new Thread (() -> {
1034
1038
try {
1035
1039
String snapshotName = "snapshot-earlier-master" ;
1036
- CreateSnapshotResponse createSnapshotResponse2 = client ().admin ()
1040
+ internalCluster ().nonClusterManagerClient ()
1041
+ .admin ()
1037
1042
.cluster ()
1038
1043
.prepareCreateSnapshot (snapshotRepoName , snapshotName )
1039
1044
.setWaitForCompletion (true )
1045
+ .setMasterNodeTimeout (TimeValue .timeValueSeconds (60 ))
1040
1046
.get ();
1041
- } catch (Exception e ) {}
1042
- });
1043
1047
1048
+ } catch (Exception ignored ) {}
1049
+ });
1044
1050
thread .start ();
1045
1051
1046
1052
// stop existing master
@@ -1049,17 +1055,18 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
1049
1055
1050
1056
// Validate that we have greater one snapshot has been created
1051
1057
String snapshotName = "new-snapshot" ;
1052
- CreateSnapshotResponse createSnapshotResponse2 = client ().admin ()
1053
- .cluster ()
1054
- .prepareCreateSnapshot (snapshotRepoName , snapshotName )
1055
- .setWaitForCompletion (false )
1056
- .get ();
1057
- Repository repository = internalCluster ().getInstance (RepositoriesService .class ).repository (snapshotRepoName );
1058
- PlainActionFuture <RepositoryData > repositoryDataPlainActionFuture = new PlainActionFuture <>();
1059
- repository .getRepositoryData (repositoryDataPlainActionFuture );
1058
+ try {
1059
+ client ().admin ().cluster ().prepareCreateSnapshot (snapshotRepoName , snapshotName ).setWaitForCompletion (true ).get ();
1060
+ } catch (Exception e ) {
1061
+ logger .info ("Exception while creating new-snapshot" , e );
1062
+ }
1060
1063
1061
- RepositoryData repositoryData = repositoryDataPlainActionFuture .get ();
1062
- assertThat (repositoryData .getSnapshotIds ().size (), greaterThanOrEqualTo (1 ));
1064
+ // Validate that snapshot is present in repository data
1065
+ assertBusy (() -> {
1066
+ GetSnapshotsRequest request = new GetSnapshotsRequest (snapshotRepoName );
1067
+ GetSnapshotsResponse response2 = client ().admin ().cluster ().getSnapshots (request ).actionGet ();
1068
+ assertThat (response2 .getSnapshots ().size (), greaterThanOrEqualTo (1 ));
1069
+ }, 30 , TimeUnit .SECONDS );
1063
1070
thread .join ();
1064
1071
}
1065
1072
0 commit comments