@@ -809,9 +809,33 @@ private void startCleaner() {
809
809
Releasables .close (releaseAll );
810
810
logger .info ("--> completed cleanup of [{}]" , trackedRepository .repositoryName );
811
811
final RepositoryCleanupResult result = cleanupRepositoryResponse .result ();
812
- assertThat (Strings .toString (result ), result .blobs (), equalTo (0L ));
813
- assertThat (Strings .toString (result ), result .bytes (), equalTo (0L ));
814
- startCleaner ();
812
+ if (result .bytes () > 0L || result .blobs () > 0L ) {
813
+ // we could legitimately run into dangling blobs as the result of a shard snapshot failing half-way
814
+ // through the snapshot because of a concurrent index-close or -delete. The second round of cleanup on
815
+ // the same repository however should always find no more dangling blobs and be a no-op since we block all
816
+ // concurrent operations on the repository.
817
+ client .admin ()
818
+ .cluster ()
819
+ .prepareCleanupRepository (trackedRepository .repositoryName )
820
+ .execute (mustSucceed (secondCleanupRepositoryResponse -> {
821
+ final RepositoryCleanupResult secondCleanupResult = secondCleanupRepositoryResponse .result ();
822
+ if (secondCleanupResult .blobs () == 1 ) {
823
+ // The previous cleanup actually leaves behind a stale index-N blob, so this cleanup removes it
824
+ // and reports it in its response. When https://github.com/elastic/elasticsearch/pull/100718 is
825
+ // fixed the second cleanup will be a proper no-op and we can remove this lenience -- TODO
826
+ } else {
827
+ assertThat (Strings .toString (secondCleanupResult ), secondCleanupResult .blobs (), equalTo (0L ));
828
+ assertThat (Strings .toString (secondCleanupResult ), secondCleanupResult .bytes (), equalTo (0L ));
829
+ }
830
+ Releasables .close (releaseAll );
831
+ logger .info ("--> completed second cleanup of [{}]" , trackedRepository .repositoryName );
832
+ startCleaner ();
833
+ }));
834
+ } else {
835
+ Releasables .close (releaseAll );
836
+ logger .info ("--> completed cleanup of [{}]" , trackedRepository .repositoryName );
837
+ startCleaner ();
838
+ }
815
839
}));
816
840
817
841
startedCleanup = true ;
0 commit comments