【问题标题】:hadoop distributed copy overwrite not workinghadoop分布式复制覆盖不起作用
【发布时间】:2019-10-15 14:24:25
【问题描述】:

我正在尝试使用 org.apache.hadoop.tools.DistCp 类将一些文件复制到 S3 存储桶中。但是,尽管将覆盖标志显式设置为 true,覆盖功能仍无法正常工作

复制工作正常,但如果存在现有文件,它不会覆盖。复制映射器会跳过这些文件。我已将“覆盖”选项明确设置为 true。

import com.typesafe.scalalogging.LazyLogging
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.Path
import org.apache.hadoop.tools.{DistCp, DistCpOptions}
import org.apache.hadoop.util.ToolRunner
import scala.collection.JavaConverters._

object  distcptest extends  App with LazyLogging {


  def copytoS3( hdfsSrcFilePathStr: String, s3DestPathStr: String) = {
    val hdfsSrcPathList = List(new Path(hdfsSrcFilePathStr))
    val s3DestPath = new Path(s3DestPathStr)
    val distcpOpt = new DistCpOptions(hdfsSrcPathList.asJava, s3DestPath)

    // Overwriting is not working inspite of explicitly setting it to true.
    distcpOpt.setOverwrite(true)

    val conf: Configuration = new Configuration()
    conf.set("fs.s3n.awsSecretAccessKey", "secret key")
    conf.set("fs.s3n.awsAccessKeyId", "access key")
    conf.set("fs.s3n.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")

    val distCp: DistCp = new DistCp(conf, distcpOpt)
    val filepaths: Array[String] = Array(hdfsSrcFilePathStr, s3DestPathStr)

    try {
      val distCp_result = ToolRunner.run(distCp, filepaths)
      if (distCp_result != 0) {
        logger.error(s"DistCP has failed with - error code = $distCp_result")
      }
    }
    catch {
      case e: Exception => {
        e.printStackTrace()
      }
    }
  }

  copytoS3("hdfs://abc/pqr", "s3n://xyz/wst")
}

【问题讨论】:

    标签: java scala hadoop overwrite distcp


    【解决方案1】:

    我认为问题在于您调用了 ToolRunner.run(distCp, filepaths)。

    如果查看 DistCp 的源代码,在 run 方法中会覆盖 inputOptions,所以传递给构造函数的 DistCpOptions 将不起作用。

      @Override
      public int run(String[] argv) {
        ...
    
        try {
          inputOptions = (OptionsParser.parse(argv));
          ...
        } catch (Throwable e) {
          ...
        }
        ...
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-31
      • 2020-07-10
      • 2016-12-22
      • 1970-01-01
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      相关资源
      最近更新 更多