@@ -39,6 +39,8 @@ import org.apache.spark.util.{JsonProtocol, ManualClock, Utils}
3939
4040class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matchers with Logging {
4141
42+ import FsHistoryProvider ._
43+
4244 private var testDir : File = null
4345
4446 before {
@@ -67,48 +69,39 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
6769 // Write a new-style application log.
6870 val newAppComplete = newLogFile(" new1" , None , inProgress = false )
6971 writeFile(newAppComplete, true , None ,
70- SparkListenerApplicationStart (
71- " new-app-complete " , Some ( " new-app-complete " ), 1L , " test " , None ),
72+ SparkListenerApplicationStart (newAppComplete.getName(), Some ( " new-app-complete " ), 1L , " test " ,
73+ None ),
7274 SparkListenerApplicationEnd (5L )
7375 )
7476
7577 // Write a new-style application log.
7678 val newAppCompressedComplete = newLogFile(" new1compressed" , None , inProgress = false ,
7779 Some (" lzf" ))
7880 writeFile(newAppCompressedComplete, true , None ,
79- SparkListenerApplicationStart (
80- " new-app-compressed-complete " , Some ( " new-app-compressed-complete " ), 1L , " test" , None ),
81+ SparkListenerApplicationStart (newAppCompressedComplete.getName(), Some ( " new-complete-lzf " ),
82+ 1L , " test" , None ),
8183 SparkListenerApplicationEnd (4L ))
8284
8385 // Write an unfinished app, new-style.
8486 val newAppIncomplete = newLogFile(" new2" , None , inProgress = true )
8587 writeFile(newAppIncomplete, true , None ,
86- SparkListenerApplicationStart (
87- " new-app-incomplete " , Some ( " new-app-incomplete " ), 1L , " test " , None )
88+ SparkListenerApplicationStart (newAppIncomplete.getName(), Some ( " new-incomplete " ), 1L , " test " ,
89+ None )
8890 )
8991
9092 // Write an old-style application log.
91- val oldAppComplete = new File (testDir, " old1" )
92- oldAppComplete.mkdir()
93- createEmptyFile(new File (oldAppComplete, provider.SPARK_VERSION_PREFIX + " 1.0" ))
94- writeFile(new File (oldAppComplete, provider.LOG_PREFIX + " 1" ), false , None ,
95- SparkListenerApplicationStart (
96- " old-app-complete" , Some (" old-app-complete" ), 2L , " test" , None ),
93+ val oldAppComplete = writeOldLog(" old1" , " 1.0" , None , true ,
94+ SparkListenerApplicationStart (" old1" , Some (" old-app-complete" ), 2L , " test" , None ),
9795 SparkListenerApplicationEnd (3L )
9896 )
99- createEmptyFile(new File (oldAppComplete, provider.APPLICATION_COMPLETE ))
10097
10198 // Check for logs so that we force the older unfinished app to be loaded, to make
10299 // sure unfinished apps are also sorted correctly.
103100 provider.checkForLogs()
104101
105102 // Write an unfinished app, old-style.
106- val oldAppIncomplete = new File (testDir, " old2" )
107- oldAppIncomplete.mkdir()
108- createEmptyFile(new File (oldAppIncomplete, provider.SPARK_VERSION_PREFIX + " 1.0" ))
109- writeFile(new File (oldAppIncomplete, provider.LOG_PREFIX + " 1" ), false , None ,
110- SparkListenerApplicationStart (
111- " old-app-incomplete" , Some (" old-app-incomplete" ), 2L , " test" , None )
103+ val oldAppIncomplete = writeOldLog(" old2" , " 1.0" , None , false ,
104+ SparkListenerApplicationStart (" old2" , None , 2L , " test" , None )
112105 )
113106
114107 // Force a reload of data from the log directory, and check that both logs are loaded.
@@ -129,16 +122,15 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
129122 List (ApplicationAttemptInfo (None , start, end, lastMod, user, completed)))
130123 }
131124
132- list(0 ) should be (makeAppInfo(" new-app-complete" , " new-app-complete " , 1L , 5L ,
125+ list(0 ) should be (makeAppInfo(" new-app-complete" , newAppComplete.getName() , 1L , 5L ,
133126 newAppComplete.lastModified(), " test" , true ))
134- list(1 ) should be (makeAppInfo(" new-app-compressed-complete" ,
135- " new-app-compressed-complete" , 1L , 4L , newAppCompressedComplete.lastModified(), " test" ,
136- true ))
137- list(2 ) should be (makeAppInfo(" old-app-complete" , " old-app-complete" , 2L , 3L ,
127+ list(1 ) should be (makeAppInfo(" new-complete-lzf" , newAppCompressedComplete.getName(),
128+ 1L , 4L , newAppCompressedComplete.lastModified(), " test" , true ))
129+ list(2 ) should be (makeAppInfo(" old-app-complete" , oldAppComplete.getName(), 2L , 3L ,
138130 oldAppComplete.lastModified(), " test" , true ))
139- list(3 ) should be (makeAppInfo(" old-app-incomplete " , " old-app-incomplete " , 2L , - 1L ,
140- oldAppIncomplete.lastModified(), " test" , false ))
141- list(4 ) should be (makeAppInfo(" new-app- incomplete" , " new-app-incomplete " , 1L , - 1L ,
131+ list(3 ) should be (makeAppInfo(oldAppIncomplete.getName(), oldAppIncomplete.getName() , 2L ,
132+ - 1L , oldAppIncomplete.lastModified(), " test" , false ))
133+ list(4 ) should be (makeAppInfo(" new-incomplete" , newAppIncomplete.getName() , 1L , - 1L ,
142134 newAppIncomplete.lastModified(), " test" , false ))
143135
144136 // Make sure the UI can be rendered.
@@ -160,12 +152,12 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
160152 val codec = if (valid) CompressionCodec .createCodec(new SparkConf (), codecName) else null
161153 val logDir = new File (testDir, codecName)
162154 logDir.mkdir()
163- createEmptyFile(new File (logDir, provider. SPARK_VERSION_PREFIX + " 1.0" ))
164- writeFile(new File (logDir, provider. LOG_PREFIX + " 1" ), false , Option (codec),
165- SparkListenerApplicationStart (" app2" , Some ( " app2 " ) , 2L , " test" , None ),
155+ createEmptyFile(new File (logDir, SPARK_VERSION_PREFIX + " 1.0" ))
156+ writeFile(new File (logDir, LOG_PREFIX + " 1" ), false , Option (codec),
157+ SparkListenerApplicationStart (" app2" , None , 2L , " test" , None ),
166158 SparkListenerApplicationEnd (3L )
167159 )
168- createEmptyFile(new File (logDir, provider. COMPRESSION_CODEC_PREFIX + codecName))
160+ createEmptyFile(new File (logDir, COMPRESSION_CODEC_PREFIX + codecName))
169161
170162 val logPath = new Path (logDir.getAbsolutePath())
171163 try {
@@ -390,6 +382,33 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
390382 }
391383 }
392384
385+ test(" SPARK-8372: new logs with no app ID are ignored" ) {
386+ val provider = new FsHistoryProvider (createTestConf())
387+
388+ // Write a new log file without an app id, to make sure it's ignored.
389+ val logFile1 = newLogFile(" app1" , None , inProgress = true )
390+ writeFile(logFile1, true , None ,
391+ SparkListenerLogStart (" 1.4" )
392+ )
393+
394+ // Write a 1.2 log file with no start event (= no app id), it should be ignored.
395+ writeOldLog(" v12Log" , " 1.2" , None , false )
396+
397+ // Write 1.0 and 1.1 logs, which don't have app ids.
398+ writeOldLog(" v11Log" , " 1.1" , None , true ,
399+ SparkListenerApplicationStart (" v11Log" , None , 2L , " test" , None ),
400+ SparkListenerApplicationEnd (3L ))
401+ writeOldLog(" v10Log" , " 1.0" , None , true ,
402+ SparkListenerApplicationStart (" v10Log" , None , 2L , " test" , None ),
403+ SparkListenerApplicationEnd (4L ))
404+
405+ updateAndCheck(provider) { list =>
406+ list.size should be (2 )
407+ list(0 ).id should be (" v10Log" )
408+ list(1 ).id should be (" v11Log" )
409+ }
410+ }
411+
393412 /**
394413 * Asks the provider to check for logs and calls a function to perform checks on the updated
395414 * app list. Example:
@@ -429,4 +448,23 @@ class FsHistoryProviderSuite extends SparkFunSuite with BeforeAndAfter with Matc
429448 new SparkConf ().set(" spark.history.fs.logDirectory" , testDir.getAbsolutePath())
430449 }
431450
451+ private def writeOldLog (
452+ fname : String ,
453+ sparkVersion : String ,
454+ codec : Option [CompressionCodec ],
455+ completed : Boolean ,
456+ events : SparkListenerEvent * ): File = {
457+ val log = new File (testDir, fname)
458+ log.mkdir()
459+
460+ val oldEventLog = new File (log, LOG_PREFIX + " 1" )
461+ createEmptyFile(new File (log, SPARK_VERSION_PREFIX + sparkVersion))
462+ writeFile(new File (log, LOG_PREFIX + " 1" ), false , codec, events : _* )
463+ if (completed) {
464+ createEmptyFile(new File (log, APPLICATION_COMPLETE ))
465+ }
466+
467+ log
468+ }
469+
432470}
0 commit comments