@@ -341,27 +341,17 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) {
341
341
if (isReadOnly ()) {
342
342
throw new RepositoryException (metadata .name (), "cannot delete snapshot from a readonly repository" );
343
343
}
344
+
344
345
final RepositoryData repositoryData = getRepositoryData ();
345
- List <String > indices = Collections .emptyList ();
346
346
SnapshotInfo snapshot = null ;
347
347
try {
348
348
snapshot = getSnapshotInfo (snapshotId );
349
- indices = snapshot .indices ();
350
349
} catch (SnapshotMissingException ex ) {
351
350
throw ex ;
352
351
} catch (IllegalStateException | SnapshotException | ElasticsearchParseException ex ) {
353
352
logger .warn (() -> new ParameterizedMessage ("cannot read snapshot file [{}]" , snapshotId ), ex );
354
353
}
355
- MetaData metaData = null ;
356
- try {
357
- if (snapshot != null ) {
358
- metaData = readSnapshotMetaData (snapshotId , snapshot .version (), repositoryData .resolveIndices (indices ), true );
359
- } else {
360
- metaData = readSnapshotMetaData (snapshotId , null , repositoryData .resolveIndices (indices ), true );
361
- }
362
- } catch (IOException | SnapshotException ex ) {
363
- logger .warn (() -> new ParameterizedMessage ("cannot read metadata for snapshot [{}]" , snapshotId ), ex );
364
- }
354
+
365
355
try {
366
356
// Delete snapshot from the index file, since it is the maintainer of truth of active snapshots
367
357
final RepositoryData updatedRepositoryData = repositoryData .removeSnapshot (snapshotId );
@@ -373,24 +363,29 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) {
373
363
deleteGlobalMetaDataBlobIgnoringErrors (snapshot , snapshotId .getUUID ());
374
364
375
365
// Now delete all indices
376
- for (String index : indices ) {
377
- final IndexId indexId = repositoryData .resolveIndexId (index );
378
- BlobPath indexPath = basePath ().add ("indices" ).add (indexId .getId ());
379
- BlobContainer indexMetaDataBlobContainer = blobStore ().blobContainer (indexPath );
380
- try {
381
- indexMetaDataFormat .delete (indexMetaDataBlobContainer , snapshotId .getUUID ());
382
- } catch (IOException ex ) {
383
- logger .warn (() -> new ParameterizedMessage ("[{}] failed to delete metadata for index [{}]" , snapshotId , index ), ex );
384
- }
385
- if (metaData != null ) {
386
- IndexMetaData indexMetaData = metaData .index (index );
366
+ if (snapshot != null ) {
367
+ final List <String > indices = snapshot .indices ();
368
+ for (String index : indices ) {
369
+ final IndexId indexId = repositoryData .resolveIndexId (index );
370
+
371
+ IndexMetaData indexMetaData = null ;
372
+ try {
373
+ indexMetaData = getSnapshotIndexMetaData (snapshotId , indexId );
374
+ } catch (ElasticsearchParseException | IOException ex ) {
375
+ logger .warn (() ->
376
+ new ParameterizedMessage ("[{}] [{}] failed to read metadata for index" , snapshotId , index ), ex );
377
+ }
378
+
379
+ deleteIndexMetaDataBlobIgnoringErrors (snapshot , indexId );
380
+
387
381
if (indexMetaData != null ) {
388
382
for (int shardId = 0 ; shardId < indexMetaData .getNumberOfShards (); shardId ++) {
389
383
try {
390
384
delete (snapshotId , snapshot .version (), indexId , new ShardId (indexMetaData .getIndex (), shardId ));
391
385
} catch (SnapshotException ex ) {
392
386
final int finalShardId = shardId ;
393
- logger .warn (() -> new ParameterizedMessage ("[{}] failed to delete shard data for shard [{}][{}]" , snapshotId , index , finalShardId ), ex );
387
+ logger .warn (() -> new ParameterizedMessage ("[{}] failed to delete shard data for shard [{}][{}]" ,
388
+ snapshotId , index , finalShardId ), ex );
394
389
}
395
390
}
396
391
}
@@ -448,6 +443,16 @@ private void deleteGlobalMetaDataBlobIgnoringErrors(final SnapshotInfo snapshotI
448
443
}
449
444
}
450
445
446
+ private void deleteIndexMetaDataBlobIgnoringErrors (final SnapshotInfo snapshotInfo , final IndexId indexId ) {
447
+ final SnapshotId snapshotId = snapshotInfo .snapshotId ();
448
+ BlobContainer indexMetaDataBlobContainer = blobStore ().blobContainer (basePath ().add ("indices" ).add (indexId .getId ()));
449
+ try {
450
+ indexMetaDataFormat .delete (indexMetaDataBlobContainer , snapshotId .getUUID ());
451
+ } catch (IOException ex ) {
452
+ logger .warn (() -> new ParameterizedMessage ("[{}] failed to delete metadata for index [{}]" , snapshotId , indexId .getName ()), ex );
453
+ }
454
+ }
455
+
451
456
/**
452
457
* {@inheritDoc}
453
458
*/
@@ -508,44 +513,6 @@ public IndexMetaData getSnapshotIndexMetaData(final SnapshotId snapshotId, final
508
513
return indexMetaDataFormat .read (blobStore ().blobContainer (indexPath ), snapshotId .getUUID ());
509
514
}
510
515
511
- /**
512
- * Returns the global metadata associated with the snapshot.
513
- * <p>
514
- * The returned meta data contains global metadata as well as metadata
515
- * for all indices listed in the indices parameter.
516
- */
517
- private MetaData readSnapshotMetaData (final SnapshotId snapshotId ,
518
- final Version snapshotVersion ,
519
- final List <IndexId > indices ,
520
- final boolean ignoreErrors ) throws IOException {
521
- if (snapshotVersion == null ) {
522
- // When we delete corrupted snapshots we might not know which version we are dealing with
523
- // We can try detecting the version based on the metadata file format
524
- assert ignoreErrors ;
525
- if (globalMetaDataFormat .exists (snapshotsBlobContainer , snapshotId .getUUID ()) == false ) {
526
- throw new SnapshotMissingException (metadata .name (), snapshotId );
527
- }
528
- }
529
-
530
- final MetaData .Builder metaData = MetaData .builder (getSnapshotGlobalMetaData (snapshotId ));
531
- if (indices != null ) {
532
- for (IndexId index : indices ) {
533
- try {
534
- metaData .put (getSnapshotIndexMetaData (snapshotId , index ), false );
535
- } catch (ElasticsearchParseException | IOException ex ) {
536
- if (ignoreErrors == false ) {
537
- throw new SnapshotException (metadata .name (), snapshotId ,
538
- "[" + index .getName () + "] failed to read metadata for index" , ex );
539
- } else {
540
- logger .warn (() ->
541
- new ParameterizedMessage ("[{}] [{}] failed to read metadata for index" , snapshotId , index .getName ()), ex );
542
- }
543
- }
544
- }
545
- }
546
- return metaData .build ();
547
- }
548
-
549
516
/**
550
517
* Configures RateLimiter based on repository and global settings
551
518
*
0 commit comments