protected void finalize(List<SnapshotFiles> snapshots,int fileListGeneration,Map<String,BlobMetaData> blobs){
  BlobStoreIndexShardSnapshots newSnapshots=new BlobStoreIndexShardSnapshots(snapshots);
  List<String> blobsToDelete=new ArrayList<>();
  for (  String blobName : blobs.keySet()) {
    if (indexShardSnapshotsFormat.isTempBlobName(blobName) || blobName.startsWith(SNAPSHOT_INDEX_PREFIX)) {
      blobsToDelete.add(blobName);
    }
  }
  try {
    blobContainer.deleteBlobs(blobsToDelete);
  }
 catch (  IOException e) {
    throw new IndexShardSnapshotFailedException(shardId,"error deleting index files during cleanup, reason: " + e.getMessage(),e);
  }
  blobsToDelete=new ArrayList<>();
  for (  String blobName : blobs.keySet()) {
    if (blobName.startsWith(DATA_BLOB_PREFIX)) {
      if (newSnapshots.findNameFile(FileInfo.canonicalName(blobName)) == null) {
        blobsToDelete.add(blobName);
      }
    }
  }
  try {
    blobContainer.deleteBlobs(blobsToDelete);
  }
 catch (  IOException e) {
    logger.debug("[{}] [{}] error deleting some of the blobs [{}] during cleanup",e,snapshotId,shardId,blobsToDelete);
  }
  if (snapshots.size() > 0) {
    try {
      indexShardSnapshotsFormat.writeAtomic(newSnapshots,blobContainer,Integer.toString(fileListGeneration));
    }
 catch (    IOException e) {
      throw new IndexShardSnapshotFailedException(shardId,"Failed to write file list",e);
    }
  }
}

protected void finalize ( List < SnapshotFiles > snapshots , int fileListGeneration , Map < String , BlobMetaData > blobs ) { BlobStoreIndexShardSnapshots newSnapshots = new BlobStoreIndexShardSnapshots ( snapshots ) ; List < String > blobsToDelete = new ArrayList < > ( ) ; for ( String blobName : blobs . keySet ( ) ) { if ( indexShardSnapshotsFormat . isTempBlobName ( blobName ) || blobName . startsWith ( SNAPSHOT_INDEX_PREFIX ) ) { blobsToDelete . add ( blobName ) ; } } try { blobContainer . deleteBlobs ( blobsToDelete ) ; } catch ( IOException e ) { throw new IndexShardSnapshotFailedException ( shardId , "error deleting index files during cleanup, reason: " + e . getMessage ( ) , e ) ; } blobsToDelete = new ArrayList < > ( ) ; for ( String blobName : blobs . keySet ( ) ) { if ( blobName . startsWith ( DATA_BLOB_PREFIX ) ) { if ( newSnapshots . findNameFile ( FileInfo . canonicalName ( blobName ) ) == null ) { blobsToDelete . add ( blobName ) ; } } } try { blobContainer . deleteBlobs ( blobsToDelete ) ; } catch ( IOException e ) { logger . debug ( "[{}] [{}] error deleting some of the blobs [{}] during cleanup" , e , snapshotId , shardId , blobsToDelete ) ; } if ( snapshots . size ( ) > 0 ) { try { indexShardSnapshotsFormat . writeAtomic ( newSnapshots , blobContainer , Integer . toString ( fileListGeneration ) ) ; } catch ( IOException e ) { throw new IndexShardSnapshotFailedException ( shardId , "Failed to write file list" , e ) ; } } }
removes all unreferenced files from the repository and writes new index file we need to be really careful in handling index files in case of failures to make sure we have index file that points to files that were deleted .
