18
18
*/
19
19
package org .elasticsearch .snapshots ;
20
20
21
+ import org .elasticsearch .Version ;
21
22
import org .elasticsearch .action .ActionRunnable ;
22
23
import org .elasticsearch .action .admin .cluster .snapshots .create .CreateSnapshotResponse ;
23
24
import org .elasticsearch .action .support .PlainActionFuture ;
27
28
import org .elasticsearch .cluster .metadata .MetaData ;
28
29
import org .elasticsearch .cluster .metadata .RepositoriesMetaData ;
29
30
import org .elasticsearch .cluster .service .ClusterService ;
31
+ import org .elasticsearch .common .bytes .BytesReference ;
30
32
import org .elasticsearch .common .settings .Settings ;
31
33
import org .elasticsearch .common .unit .ByteSizeUnit ;
34
+ import org .elasticsearch .common .xcontent .XContentFactory ;
32
35
import org .elasticsearch .repositories .RepositoriesService ;
33
36
import org .elasticsearch .repositories .Repository ;
34
37
import org .elasticsearch .repositories .RepositoryData ;
35
38
import org .elasticsearch .repositories .RepositoryException ;
39
+ import org .elasticsearch .repositories .ShardGenerations ;
36
40
import org .elasticsearch .repositories .blobstore .BlobStoreRepository ;
37
41
import org .elasticsearch .threadpool .ThreadPool ;
38
42
39
43
import java .nio .file .Files ;
40
44
import java .nio .file .Path ;
45
+ import java .nio .file .StandardOpenOption ;
46
+ import java .util .Collections ;
41
47
import java .util .Locale ;
48
+ import java .util .function .Function ;
49
+ import java .util .stream .Collectors ;
42
50
43
51
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
44
52
import static org .hamcrest .Matchers .containsString ;
@@ -263,11 +271,24 @@ public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
263
271
logger .info ("--> delete root level snapshot metadata blob for snapshot [{}]" , snapshotToCorrupt );
264
272
Files .delete (repo .resolve (String .format (Locale .ROOT , BlobStoreRepository .SNAPSHOT_NAME_FORMAT , snapshotToCorrupt .getUUID ())));
265
273
274
+ logger .info ("--> strip version information from index-N blob" );
275
+ final RepositoryData withoutVersions = new RepositoryData (repositoryData .getGenId (),
276
+ repositoryData .getSnapshotIds ().stream ().collect (Collectors .toMap (
277
+ SnapshotId ::getUUID , Function .identity ())),
278
+ repositoryData .getSnapshotIds ().stream ().collect (Collectors .toMap (
279
+ SnapshotId ::getUUID , repositoryData ::getSnapshotState )),
280
+ Collections .emptyMap (), Collections .emptyMap (), ShardGenerations .EMPTY );
281
+
282
+ Files .write (repo .resolve (BlobStoreRepository .INDEX_FILE_PREFIX + withoutVersions .getGenId ()),
283
+ BytesReference .toBytes (BytesReference .bytes (withoutVersions .snapshotsToXContent (XContentFactory .jsonBuilder (),
284
+ true ))), StandardOpenOption .TRUNCATE_EXISTING );
285
+
266
286
logger .info ("--> verify that repo is assumed in old metadata format" );
267
287
final SnapshotsService snapshotsService = internalCluster ().getCurrentMasterNodeInstance (SnapshotsService .class );
268
288
final ThreadPool threadPool = internalCluster ().getCurrentMasterNodeInstance (ThreadPool .class );
269
289
assertThat (PlainActionFuture .get (f -> threadPool .generic ().execute (
270
- ActionRunnable .supply (f , () -> snapshotsService .hasOldVersionSnapshots (repoName , repositoryData , null )))), is (true ));
290
+ ActionRunnable .supply (f , () -> snapshotsService .hasOldVersionSnapshots (repoName , getRepositoryData (repository ), null )))),
291
+ is (true ));
271
292
272
293
logger .info ("--> verify that snapshot with missing root level metadata can be deleted" );
273
294
assertAcked (client ().admin ().cluster ().prepareDeleteSnapshot (repoName , snapshotToCorrupt .getName ()).get ());
@@ -276,6 +297,10 @@ public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
276
297
assertThat (PlainActionFuture .get (f -> threadPool .generic ().execute (
277
298
ActionRunnable .supply (f , () -> snapshotsService .hasOldVersionSnapshots (repoName , getRepositoryData (repository ), null )))),
278
299
is (false ));
300
+ final RepositoryData finalRepositoryData = getRepositoryData (repository );
301
+ for (SnapshotId snapshotId : finalRepositoryData .getSnapshotIds ()) {
302
+ assertThat (finalRepositoryData .getVersion (snapshotId ), is (Version .CURRENT ));
303
+ }
279
304
}
280
305
281
306
private void assertRepositoryBlocked (Client client , String repo , String existingSnapshot ) {
0 commit comments