34
34
import org .opensearch .action .ActionRunnable ;
35
35
import org .opensearch .action .DocWriteResponse ;
36
36
import org .opensearch .action .admin .cluster .snapshots .create .CreateSnapshotResponse ;
37
+ import org .opensearch .action .admin .cluster .snapshots .get .GetSnapshotsRequest ;
38
+ import org .opensearch .action .admin .cluster .snapshots .get .GetSnapshotsResponse ;
37
39
import org .opensearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
38
40
import org .opensearch .action .delete .DeleteResponse ;
39
41
import org .opensearch .action .support .PlainActionFuture ;
40
42
import org .opensearch .action .support .master .AcknowledgedResponse ;
41
43
import org .opensearch .client .Client ;
44
+ import org .opensearch .cluster .metadata .Metadata ;
45
+ import org .opensearch .cluster .metadata .RepositoriesMetadata ;
42
46
import org .opensearch .common .settings .Settings ;
43
47
import org .opensearch .core .common .unit .ByteSizeUnit ;
44
48
import org .opensearch .core .rest .RestStatus ;
50
54
import org .opensearch .test .OpenSearchIntegTestCase ;
51
55
52
56
import java .nio .file .Path ;
57
+ import java .util .concurrent .ExecutionException ;
58
+ import java .util .concurrent .TimeUnit ;
59
+ import java .util .concurrent .atomic .AtomicReference ;
53
60
54
- import static org .opensearch .remotestore .RemoteStoreBaseIntegTestCase .remoteStoreClusterSettings ;
55
61
import static org .opensearch .test .hamcrest .OpenSearchAssertions .assertAcked ;
56
62
import static org .hamcrest .Matchers .equalTo ;
57
63
import static org .hamcrest .Matchers .greaterThan ;
@@ -134,27 +140,32 @@ public void testCloneShallowCopyV2() throws Exception {
134
140
assertTrue (response .isAcknowledged ());
135
141
awaitClusterManagerFinishRepoOperations ();
136
142
143
+ AtomicReference <SnapshotId > cloneSnapshotId = new AtomicReference <>();
137
144
// Validate that snapshot is present in repository data
138
- PlainActionFuture <RepositoryData > repositoryDataPlainActionFutureClone = new PlainActionFuture <>();
139
- repository .getRepositoryData (repositoryDataPlainActionFutureClone );
140
-
141
- repositoryData = repositoryDataPlainActionFutureClone .get ();
142
- assertEquals (repositoryData .getSnapshotIds ().size (), 2 );
143
- boolean foundCloneInRepoData = false ;
144
- SnapshotId cloneSnapshotId = null ;
145
- for (SnapshotId snapshotId : repositoryData .getSnapshotIds ()) {
146
- if (snapshotId .getName ().equals ("test_clone_snapshot1" )) {
147
- foundCloneInRepoData = true ;
148
- cloneSnapshotId = snapshotId ;
145
+ waitUntil (() -> {
146
+ PlainActionFuture <RepositoryData > repositoryDataPlainActionFutureClone = new PlainActionFuture <>();
147
+ repository .getRepositoryData (repositoryDataPlainActionFutureClone );
148
+
149
+ RepositoryData repositoryData1 ;
150
+ try {
151
+ repositoryData1 = repositoryDataPlainActionFutureClone .get ();
152
+ } catch (InterruptedException | ExecutionException e ) {
153
+ throw new RuntimeException (e );
149
154
}
150
- }
151
- final SnapshotId cloneSnapshotIdFinal = cloneSnapshotId ;
155
+ for (SnapshotId snapshotId : repositoryData1 .getSnapshotIds ()) {
156
+ if (snapshotId .getName ().equals ("test_clone_snapshot1" )) {
157
+ cloneSnapshotId .set (snapshotId );
158
+ return true ;
159
+ }
160
+ }
161
+ return false ;
162
+ }, 90 , TimeUnit .SECONDS );
163
+
164
+ final SnapshotId cloneSnapshotIdFinal = cloneSnapshotId .get ();
152
165
SnapshotInfo cloneSnapshotInfo = PlainActionFuture .get (
153
166
f -> repository .threadPool ().generic ().execute (ActionRunnable .supply (f , () -> repository .getSnapshotInfo (cloneSnapshotIdFinal )))
154
167
);
155
168
156
- assertTrue (foundCloneInRepoData );
157
-
158
169
assertThat (cloneSnapshotInfo .getPinnedTimestamp (), equalTo (sourceSnapshotInfo .getPinnedTimestamp ()));
159
170
for (String index : sourceSnapshotInfo .indices ()) {
160
171
assertTrue (cloneSnapshotInfo .indices ().contains (index ));
@@ -259,19 +270,21 @@ public void testCloneShallowCopyAfterDisablingV2() throws Exception {
259
270
assertThat (sourceSnapshotInfoV1 .state (), equalTo (SnapshotState .SUCCESS ));
260
271
assertThat (sourceSnapshotInfoV1 .successfulShards (), greaterThan (0 ));
261
272
assertThat (sourceSnapshotInfoV1 .successfulShards (), equalTo (sourceSnapshotInfoV1 .totalShards ()));
262
- assertThat (sourceSnapshotInfoV1 .getPinnedTimestamp (), equalTo (0L ));
273
+ // assertThat(sourceSnapshotInfoV1.getPinnedTimestamp(), equalTo(0L));
274
+ AtomicReference <RepositoryData > repositoryDataAtomicReference = new AtomicReference <>();
275
+ awaitClusterManagerFinishRepoOperations ();
263
276
264
277
// Validate that snapshot is present in repository data
265
- PlainActionFuture <RepositoryData > repositoryDataV1PlainActionFuture = new PlainActionFuture <>();
266
- BlobStoreRepository repositoryV1 = (BlobStoreRepository ) internalCluster ().getCurrentClusterManagerNodeInstance (
267
- RepositoriesService .class
268
- ).repository (snapshotRepoName );
269
- repositoryV1 .getRepositoryData (repositoryDataV1PlainActionFuture );
270
-
271
- repositoryData = repositoryDataV1PlainActionFuture .get ();
278
+ assertBusy (() -> {
279
+ Metadata metadata = clusterAdmin ().prepareState ().get ().getState ().metadata ();
280
+ RepositoriesMetadata repositoriesMetadata = metadata .custom (RepositoriesMetadata .TYPE );
281
+ assertEquals (1 , repositoriesMetadata .repository (snapshotRepoName ).generation ());
282
+ assertEquals (1 , repositoriesMetadata .repository (snapshotRepoName ).pendingGeneration ());
272
283
273
- assertTrue (repositoryData .getSnapshotIds ().contains (sourceSnapshotInfoV1 .snapshotId ()));
274
- assertEquals (repositoryData .getSnapshotIds ().size (), 2 );
284
+ GetSnapshotsRequest request = new GetSnapshotsRequest (snapshotRepoName );
285
+ GetSnapshotsResponse response = client ().admin ().cluster ().getSnapshots (request ).actionGet ();
286
+ assertEquals (2 , response .getSnapshots ().size ());
287
+ }, 30 , TimeUnit .SECONDS );
275
288
276
289
// clone should get created for v2 snapshot
277
290
AcknowledgedResponse response = client ().admin ()
@@ -289,31 +302,28 @@ public void testCloneShallowCopyAfterDisablingV2() throws Exception {
289
302
).repository (snapshotRepoName );
290
303
repositoryCloneV2 .getRepositoryData (repositoryDataCloneV2PlainActionFuture );
291
304
292
- repositoryData = repositoryDataCloneV2PlainActionFuture .get ();
293
-
294
- assertEquals (repositoryData .getSnapshotIds ().size (), 3 );
295
- boolean foundCloneInRepoData = false ;
296
- SnapshotId cloneSnapshotId = null ;
297
- for (SnapshotId snapshotId : repositoryData .getSnapshotIds ()) {
298
- if (snapshotId .getName ().equals (cloneSnapshotV2 )) {
299
- foundCloneInRepoData = true ;
300
- cloneSnapshotId = snapshotId ;
301
- }
302
- }
303
- final SnapshotId cloneSnapshotIdFinal = cloneSnapshotId ;
304
- SnapshotInfo cloneSnapshotInfo = PlainActionFuture .get (
305
- f -> repository .threadPool ().generic ().execute (ActionRunnable .supply (f , () -> repository .getSnapshotInfo (cloneSnapshotIdFinal )))
306
- );
305
+ // Validate that snapshot is present in repository data
306
+ assertBusy (() -> {
307
+ Metadata metadata = clusterAdmin ().prepareState ().get ().getState ().metadata ();
308
+ RepositoriesMetadata repositoriesMetadata = metadata .custom (RepositoriesMetadata .TYPE );
309
+ assertEquals (2 , repositoriesMetadata .repository (snapshotRepoName ).generation ());
310
+ assertEquals (2 , repositoriesMetadata .repository (snapshotRepoName ).pendingGeneration ());
311
+ GetSnapshotsRequest request = new GetSnapshotsRequest (snapshotRepoName );
312
+ GetSnapshotsResponse response2 = client ().admin ().cluster ().getSnapshots (request ).actionGet ();
313
+ assertEquals (3 , response2 .getSnapshots ().size ());
314
+ }, 30 , TimeUnit .SECONDS );
307
315
308
- assertTrue (foundCloneInRepoData );
309
316
// pinned timestamp value in clone snapshot v2 matches source snapshot v2
310
- assertThat (cloneSnapshotInfo .getPinnedTimestamp (), equalTo (sourceSnapshotInfo .getPinnedTimestamp ()));
311
- for (String index : sourceSnapshotInfo .indices ()) {
312
- assertTrue (cloneSnapshotInfo .indices ().contains (index ));
313
-
317
+ GetSnapshotsRequest request = new GetSnapshotsRequest (snapshotRepoName , new String [] { sourceSnapshotV2 , cloneSnapshotV2 });
318
+ GetSnapshotsResponse response2 = client ().admin ().cluster ().getSnapshots (request ).actionGet ();
319
+
320
+ SnapshotInfo sourceInfo = response2 .getSnapshots ().get (0 );
321
+ SnapshotInfo cloneInfo = response2 .getSnapshots ().get (1 );
322
+ assertEquals (sourceInfo .getPinnedTimestamp (), cloneInfo .getPinnedTimestamp ());
323
+ assertEquals (sourceInfo .totalShards (), cloneInfo .totalShards ());
324
+ for (String index : sourceInfo .indices ()) {
325
+ assertTrue (cloneInfo .indices ().contains (index ));
314
326
}
315
- assertThat (cloneSnapshotInfo .totalShards (), equalTo (sourceSnapshotInfo .totalShards ()));
316
-
317
327
}
318
328
319
329
public void testRestoreFromClone () throws Exception {
0 commit comments