@@ -341,27 +341,17 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) {
341341 if (isReadOnly ()) {
342342 throw new RepositoryException (metadata .name (), "cannot delete snapshot from a readonly repository" );
343343 }
344+
344345 final RepositoryData repositoryData = getRepositoryData ();
345- List <String > indices = Collections .emptyList ();
346346 SnapshotInfo snapshot = null ;
347347 try {
348348 snapshot = getSnapshotInfo (snapshotId );
349- indices = snapshot .indices ();
350349 } catch (SnapshotMissingException ex ) {
351350 throw ex ;
352351 } catch (IllegalStateException | SnapshotException | ElasticsearchParseException ex ) {
353352 logger .warn (() -> new ParameterizedMessage ("cannot read snapshot file [{}]" , snapshotId ), ex );
354353 }
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+
365355 try {
366356 // Delete snapshot from the index file, since it is the maintainer of truth of active snapshots
367357 final RepositoryData updatedRepositoryData = repositoryData .removeSnapshot (snapshotId );
@@ -373,24 +363,29 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) {
373363 deleteGlobalMetaDataBlobIgnoringErrors (snapshot , snapshotId .getUUID ());
374364
375365 // 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+
387381 if (indexMetaData != null ) {
388382 for (int shardId = 0 ; shardId < indexMetaData .getNumberOfShards (); shardId ++) {
389383 try {
390384 delete (snapshotId , snapshot .version (), indexId , new ShardId (indexMetaData .getIndex (), shardId ));
391385 } catch (SnapshotException ex ) {
392386 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 );
394389 }
395390 }
396391 }
@@ -448,6 +443,16 @@ private void deleteGlobalMetaDataBlobIgnoringErrors(final SnapshotInfo snapshotI
448443 }
449444 }
450445
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+
451456 /**
452457 * {@inheritDoc}
453458 */
@@ -508,44 +513,6 @@ public IndexMetaData getSnapshotIndexMetaData(final SnapshotId snapshotId, final
508513 return indexMetaDataFormat .read (blobStore ().blobContainer (indexPath ), snapshotId .getUUID ());
509514 }
510515
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-
549516 /**
550517 * Configures RateLimiter based on repository and global settings
551518 *
0 commit comments