99import java .io .File ;
1010import java .nio .file .Files ;
1111import java .nio .file .Path ;
12+ import java .time .LocalDate ;
1213import java .util .List ;
1314import java .util .concurrent .ExecutorService ;
14- import java .util .stream .Collectors ;
1515
1616@ Slf4j
1717@ RequiredArgsConstructor
@@ -25,14 +25,10 @@ public class BlobCleanupJob implements Runnable {
2525
2626 @ Override
2727 public void run () {
28- if (true ) {
29- return ;
30- }
31-
3228 try {
3329 List <String > dataDirs = Lists .newCopyOnWriteArrayList ();
3430
35- Files .find (blobDirectory , 3 , (p , bfa ) -> !bfa .isRegularFile ())
31+ Files .find (blobDirectory , 4 , (p , bfa ) -> !bfa .isRegularFile () && isDataDir ( p . toFile (). getAbsolutePath () ))
3632 .forEach (dataDir -> dataDirs .add (dataDir .toFile ().getAbsolutePath ()));
3733
3834 log .debug ("Found {} data directories" , dataDirs .size ());
@@ -44,11 +40,21 @@ public void run() {
4440 dir .delete ();
4541 }
4642
47- log .debug ("Submitting DataDirectoryCleanupJob for {}" , dataDirPath );
48- executorService .submit (new DataDirectoryCleanupJob (dataDirPath , executorService , fileSystemJsonBlobManager ,blobAccessTtl , om , deleteEnabled ));
43+ String [] dateParts = dataDirPath .replace (blobDirectory .toFile ().getAbsolutePath (), "" ).split ("/" , 4 );
44+
45+ LocalDate localDate = LocalDate .of (Integer .parseInt (dateParts [1 ]), Integer .parseInt (dateParts [2 ]), Integer .parseInt (dateParts [3 ]));
46+
47+ if (localDate .isBefore (LocalDate .now ().minusDays (blobAccessTtl .toDays ()))) {
48+ log .debug ("Submitting DataDirectoryCleanupJob for {}" , dataDirPath );
49+ executorService .submit (new DataDirectoryCleanupJob (dataDirPath , executorService , fileSystemJsonBlobManager , blobAccessTtl , om , deleteEnabled ));
50+ }
4951 }
5052 } catch (Exception e ) {
5153 log .warn ("Couldn't remove old blobs" , e );
5254 }
5355 }
56+
57+ private boolean isDataDir (String path ) {
58+ return path .replace (blobDirectory .toFile ().getAbsolutePath (), "" ).split ("/" ).length == 4 ;
59+ }
5460}
0 commit comments