public void deleteFile ( String filePath ) { int retryCount = 1 ; while ( retryCount <= deleteFileRetryCount ) { try { if ( writer . getFS ( ) . exists ( new Path ( filePath ) ) ) { Thread . sleep ( 1000 * retryCount ) ; writer . getFS ( ) . delete ( new Path ( filePath ) , false ) ; ++ retryCount ; } else { break ; } } catch ( Exception e ) { log . warn ( "Exception while deleting the file: " + e . getMessage ( ) , e ) ; } } }
With AWS EBS sometimes deletion failure without any IOException was observed To prevent the surplus files let s iterate file deletion . By default it will try for five times .