【问题标题】:Reading in a parameter file in Amazon Elastic MapReduce and S3在 Amazon Elastic MapReduce 和 S3 中读取参数文件
【发布时间】:2012-12-14 08:42:10
【问题描述】:

我正在尝试在 Amazon Elastic MapReduce 系统中运行我的 hadoop 程序。我的程序从本地文件系统获取一个输入文件,其中包含程序运行所需的参数。但是,由于该文件通常是使用FileInputStream 从本地文件系统读取的,因此在 AWS 环境中执行该任务时会失败,并显示未找到参数文件的错误。请注意,我已经将文件上传到 Amazon S3。我该如何解决这个问题?谢谢。下面是我用来读取参数文件并因此读取文件中参数的代码。

FileInputStream fstream = new FileInputStream(path);
            FileInputStream os = new FileInputStream(fstream);
            DataInputStream datain = new DataInputStream(os);
            BufferedReader br = new BufferedReader(new InputStreamReader(datain));

            String[] args = new String[7];

            int i = 0;
            String strLine;
            while ((strLine = br.readLine()) != null) {
                args[i++] = strLine;
            }

【问题讨论】:

标签: hadoop amazon-web-services amazon-s3 mapreduce elastic-map-reduce


【解决方案1】:

如果您必须从本地文件系统读取文件,您可以将 EMR 作业配置为使用 boostrap action 运行。在该操作中,只需使用 s3cmd 或类似方法将文件从 S3 复制到本地文件。

您还可以通过 Hadoop FileSystem 类来读取文件,因为我很确定 EMR 支持这样的直接访问。例如:

FileSystem fs = FileSystem.get(new URI("s3://my.bucket.name/"), conf);
DataInputStream in = fs.open(new Path("/my/parameter/file"));

【讨论】:

    【解决方案2】:

    我还没有尝试过 Amazon Elastic,但它看起来像是分布式缓存的经典应用程序。您使用-files 选项(如果您实现Tool/ToolRunner)或job.addCacheFile(URI uri) 方法添加文件缓存,并像本地存在一样访问它。

    【讨论】:

      【解决方案3】:

      您可以按如下方式将此文件添加到分布式缓存中:

      ...
      String s3FilePath = args[0];
      DistributedCache.addCacheFile(new URI(s3FilePath), conf);
      ...
      

      稍后,在 mapper/reducer 的 configure() 中,您可以执行以下操作:

      ...
      Path s3FilePath;
      @Override
      public void configure(JobConf job) {
      s3FilePath = DistributedCache.getLocalCacheFiles(job)[0];
      FileInputStream fstream = new FileInputStream(s3FilePath.toString());
      ...
      }
      

      【讨论】:

      • 感谢您的回答。但我不需要使用 DistributedCache。我只需要从文件中读取参数,然后开始执行我的 MapReduce 作业。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      相关资源
      最近更新 更多