1. 程式人生 > >MapReduce常見錯誤及解決方案

MapReduce常見錯誤及解決方案

常見錯誤及解決方案

1)導包容易出錯。尤其Text和CombineTextInputFormat。

2)Mapper中第一個輸入的引數必須是LongWritable或者NullWritable,不可以是IntWritable.  報的錯誤是型別轉換異常。

3)java.lang.Exception: java.io.IOException: Illegal partition for 13926435656 (4),說明partition和reducetask個數沒對上,調整reducetask個數。

4)如果分割槽數不是1,但是reducetask為1,是否執行分割槽過程。答案是:不執行分割槽過程。因為在maptask的原始碼中,執行分割槽的前提是先判斷reduceNum個數是否大於1。不大於1肯定不執行。

5)在Windows環境編譯的jar包匯入到linux環境中執行,

hadoop jar wc.jar com.atguigu.mapreduce.wordcount.WordCountDriver /user/atguigu/ /user/atguigu/output

報如下錯誤:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/atguigu/mapreduce/wordcount/WordCountDriver : Unsupported major.minor version 52.0

原因是Windows環境用的jdk1.7,linux環境用的jdk1.8。

解決方案:統一jdk版本。

6)快取pd.txt小檔案案例中,報找不到pd.txt檔案

原因:大部分為路徑書寫錯誤。還有就是要檢查pd.txt.txt的問題。還有個別電腦寫相對路徑找不到pd.txt,可以修改為絕對路徑。

7)報型別轉換異常。

通常都是在驅動函式中設定map輸出和最終輸出時編寫錯誤。

Map輸出的key如果沒有排序,也會報型別轉換異常。

8)叢集中執行wc.jar時出現了無法獲得輸入檔案。

原因:wordcount案例的輸入檔案不能放用hdfs叢集的根目錄。

9)出現瞭如下相關異常

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

              at org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Native Method)

              at org.apache.hadoop.io.nativeio.NativeIO$Windows.access(NativeIO.java:609)

              at org.apache.hadoop.fs.FileUtil.canRead(FileUtil.java:977)

java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

              at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:356)

              at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:371)

              at org.apache.hadoop.util.Shell.<clinit>(Shell.java:364)

解決方案:拷貝hadoop.dll檔案到windows目錄C:\Windows\System32。個別同學電腦還需要修改hadoop原始碼。

10)自定義outputformat時,注意在recordWirter中的close方法必須關閉流資源。否則輸出的檔案內容中資料為空。

    @Override

    public void close(TaskAttemptContext context) throws IOException, InterruptedException {

        if (atguigufos != null) {

            atguigufos.close();

        }

        if (otherfos != null) {

            otherfos.close();

        }

}