簡體   English   中英

在 hdfs 和 S3 之間傳輸文件的有效方法

[英]Efficient way to transfer files between hdfs and S3

我正在尋找在 S3 和 hdfs 之間傳輸文件的有效方法。在我的項目中,啟動了一個 ozzie 作業,它處理文件創建 tmp 文件並進入關鍵部分,該作業必須獲得 zookeeper 鎖然后執行一些操作。 它在獲取鎖后執行的操作之一是將文件從 hdfs 移動到 S3。 由於 zookeeper 鎖就位,我們很少有作業因超時而無法獲得 zookeeper 鎖。 為了確保沒有作業因超時問題而失敗,我正在嘗試提高文件傳輸的效率。 我也無法消除動物園管理員鎖。 我正在使用 InterProcessMutex 鎖。

我嘗試了幾種方法。

方法 1:我嘗試使用 apache DistCp api 使用以下更改,項目沒有構建 maven 錯誤。

final String[] args = new String[4];
          args[0] = "-overwrite";
           args[1] = "-pb";
            args[2] = source.toString();
            args[3] = destination.toString();
            LOGGER.info("Copying contents");
            DistCp distCp = null;
            try {
                DistCpOptions distCpOptions = new DistCpOptions.Builder(source, destination)
                       .withSyncFolder(true)
                        .withCRC(true)
                        .withOverwrite(true)
                       .build();
                distCp = new DistCp(configuration, distCpOptions);
            } catch (final Exception e) {
                throw new IOException("An Exception occured while creating a distCp object", e);
            }
           LOGGER.info("Copying contents of source path {} to destination path {} ", source, destination);
           final int distCopyExitCode = distCp.run(args);

錯誤:為了糾正這個錯誤,我看到了添加 guava-11.0.2 maven 依賴項的建議,但沒有解決問題。 關於如何解決此問題的任何想法?

java.lang.NoClassDefFoundError: org/apache/hadoop/thirdparty/com/google/common/base/Preconditions
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.hadoop.tools.DistCpOptions$Builder.<init>(DistCpOptions.java:530)

方法 2:我遇到了在 hdfs 和 S3 之間傳輸文件的 aws S3Distcp 工具,但是我沒有找到 S3Distcp java api。使用 S3Distcp 的一種方法是通過在 EMR 集群中創建一個步驟來自 EMR。 ( https://docs.aws.amazon.com/code-samples/latest/catalog/java-emr-emr-add-steps.java.html )。

在我的場景中,我有一個 EMR 步驟,它實際上啟動了作業,作業將處理輸入文件,然后將文件從 hdfs 移動到 S3,然后終止。

如果我使用上面鏈接中提供的解決方案,則以下步驟將是操作順序。

  1. 奧齊工作開始
  2. 作業處理輸入文件並在 hdfs 中創建 tmp 文件
  3. 獲取動物園管理員鎖
  4. 創建 EMR 步驟以使用 S3Distcp 觸發文件傳輸
  5. 將文件從 hdfs 傳輸到 S3
  6. EMR 步驟完成
  7. 工作完成

如果我使用這種方法——有多個並行作業被啟動,每個作業都會創建一個新的 EMR 步驟。 如果我弄錯了,請糾正我。 任何人都可以提供有關如何處理此問題的建議。

java.lang.NoClassDefFoundError: org/apache/hadoop/thirdparty/com/google/common/base/Preconditions

這表明缺少 hadoop-thirdparty 依賴項。 添加這個應該可以解決這個錯誤

      <dependency>
        <groupId>org.apache.hadoop.thirdparty</groupId>
        <artifactId>hadoop-shaded-guava</artifactId>
        <version>${hadoop-thirdparty-guava.version}</version>
     </dependency>

這個依賴可以按照hadoop版本選擇對應的版本,hadoop版本最新的是1.1.1 3.3.3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM