Search code examples
apache-sparkamazon-s3emramazon-emr

SparkContext addFile causes FileNotFoundException


I am trying to deliver large file to each executor with sparkContext.addFile method.

Source of this large file is Amazon S3 (NOTE: In case of source is HDFS everything works fine)

val context = stream.context.sparkContext
context.addFile("s3n://bucket-name/file-path")
...
SparkFiles.get(file-name)

That is the cause of a error:

java.io.FileNotFoundException: File s3n://bucket-name/file-path does not exist.
    at com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem.listStatus(S3NativeFileSystem.java:945)
    at com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem.listStatus(S3NativeFileSystem.java:887)
    at com.amazon.ws.emr.hadoop.fs.EmrFileSystem.listStatus(EmrFileSystem.java:343)
    at org.apache.spark.util.Utils$.fetchHcfsFile(Utils.scala:596)
    at org.apache.spark.util.Utils$.doFetchFile(Utils.scala:566)
    at org.apache.spark.util.Utils$.fetchFile(Utils.scala:356)
    at org.apache.spark.executor.Executor$$anonfun$org$apache$spark$executor$Executor$$updateDependencies$3.apply(Executor.scala:393)
    at org.apache.spark.executor.Executor$$anonfun$org$apache$spark$executor$Executor$$updateDependencies$3.apply(Executor.scala:390)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
    at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:98)
    at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:98)
    at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:226)
    at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:39)
    at scala.collection.mutable.HashMap.foreach(HashMap.scala:98)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
    at org.apache.spark.executor.Executor.org$apache$spark$executor$Executor$$updateDependencies(Executor.scala:390)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:193)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

But when I do "fs -ls", file is accessable

    hadoop fs -ls s3n://bucket-name/file-path 

What could be the reason?

PS: Spark Version: 1.5.2


Solution

  • Suddenly, this was credentials problem. When I changed s3 URL to

      s3n://accessKey:secretKey@backet-name/path
    

    The problem was solved.