@@ -716,42 +716,62 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
716716 }
717717
718718 test(" SPARK-21571: clean up removes invalid history files" ) {
719+ // TODO: "maxTime" becoming negative in cleanLogs() causes this test to fail, so avoid that
720+ // until we figure out what's causing the problem.
719721 val clock = new ManualClock (TimeUnit .DAYS .toMillis(120 ))
720- val conf = createTestConf().set(" spark.history.fs.cleaner.maxAge " , s " 2d " )
722+ val conf = createTestConf().set(MAX_LOG_AGE_S .key , s " 2d " )
721723 val provider = new FsHistoryProvider (conf, clock) {
722724 override def getNewLastScanTime (): Long = clock.getTimeMillis()
723725 }
724726
725727 // Create 0-byte size inprogress and complete files
726- val logfile1 = newLogFile(" emptyInprogressLogFile" , None , inProgress = true )
727- logfile1.createNewFile()
728- logfile1.setLastModified(clock.getTimeMillis())
728+ var logCount = 0
729+ var validLogCount = 0
729730
730- val logfile2 = newLogFile(" emptyFinishedLogFile" , None , inProgress = false )
731- logfile2.createNewFile()
732- logfile2.setLastModified(clock.getTimeMillis())
731+ val emptyInProgress = newLogFile(" emptyInprogressLogFile" , None , inProgress = true )
732+ emptyInProgress.createNewFile()
733+ emptyInProgress.setLastModified(clock.getTimeMillis())
734+ logCount += 1
735+
736+ val slowApp = newLogFile(" slowApp" , None , inProgress = true )
737+ slowApp.createNewFile()
738+ slowApp.setLastModified(clock.getTimeMillis())
739+ logCount += 1
740+
741+ val emptyFinished = newLogFile(" emptyFinishedLogFile" , None , inProgress = false )
742+ emptyFinished.createNewFile()
743+ emptyFinished.setLastModified(clock.getTimeMillis())
744+ logCount += 1
733745
734746 // Create an incomplete log file, has an end record but no start record.
735- val logfile3 = newLogFile(" nonEmptyCorruptLogFile" , None , inProgress = false )
736- writeFile(logfile3, true , None , SparkListenerApplicationEnd (0 ))
737- logfile3.setLastModified(clock.getTimeMillis())
747+ val corrupt = newLogFile(" nonEmptyCorruptLogFile" , None , inProgress = false )
748+ writeFile(corrupt, true , None , SparkListenerApplicationEnd (0 ))
749+ corrupt.setLastModified(clock.getTimeMillis())
750+ logCount += 1
738751
739752 provider.checkForLogs()
740753 provider.cleanLogs()
741- assert(new File (testDir.toURI).listFiles().size === 3 )
754+ assert(new File (testDir.toURI).listFiles().size === logCount )
742755
743756 // Move the clock forward 1 day and scan the files again. They should still be there.
744757 clock.advance(TimeUnit .DAYS .toMillis(1 ))
745758 provider.checkForLogs()
746759 provider.cleanLogs()
747- assert(new File (testDir.toURI).listFiles().size === 3 )
760+ assert(new File (testDir.toURI).listFiles().size === logCount)
761+
762+ // Update the slow app to contain valid info. Code should detect the change and not clean
763+ // it up.
764+ writeFile(slowApp, true , None ,
765+ SparkListenerApplicationStart (slowApp.getName(), Some (slowApp.getName()), 1L , " test" , None ))
766+ slowApp.setLastModified(clock.getTimeMillis())
767+ validLogCount += 1
748768
749769 // Move the clock forward another 2 days and scan the files again. This time the cleaner should
750770 // pick up the invalid files and get rid of them.
751771 clock.advance(TimeUnit .DAYS .toMillis(2 ))
752772 provider.checkForLogs()
753773 provider.cleanLogs()
754- assert(new File (testDir.toURI).listFiles().size === 0 )
774+ assert(new File (testDir.toURI).listFiles().size === validLogCount )
755775 }
756776
757777 /**
0 commit comments