sqoop export导出 map100% reduce0% 卡住的多种原因

我称这种bug是一个典型的“哈姆雷特”bug,就是指那种“报错情况相同但网上却会有各种五花缭乱解决办法”的bug,让我们不知道哪一个才是症结所在。

先看导入命令:

[root@host25 ~]# 
sqoop export --connect "jdbc:mysql://172.16.xxx.xxx:3306/dbname?useUnicode=true&characterEncoding=utf-8" 
--username=root --password=xxxxx --table rule_tag --update-key rule_code 
--update-mode allowinsert 
--export-dir /user/hive/warehouse/lmj_test.db/rule_tag --input-fields-terminated-by '\t' 
--input-null-string '\\N' --input-null-non-string '\\N' -m1

这个导入命令语法上其实是完全没问题的。

接下来是报错:

#截取部分
19/06/11 09:39:57 INFO mapreduce.Job: The url to track the job: http://dthost25:8088/proxy/application_1554176896418_0537/
19/06/11 09:39:57 INFO mapreduce.Job: Running job: job_1554176896418_0537
19/06/11 09:40:05 INFO mapreduce.Job: Job job_1554176896418_0537 running in uber mode : false
19/06/11 09:40:05 INFO mapreduce.Job:  map 0% reduce 0%
19/06/11 09:40:19 INFO mapreduce.Job:  map 100% reduce 0%
19/06/11 09:45:34 INFO mapreduce.Job: Task Id : attempt_1554176896418_0537_m_000000_0, Status : FAILED
AttemptID:attempt_1554176896418_0537_m_000000_0 Timed out after 300 secs
19/06/11 09:45:36 INFO mapreduce.Job:  map 0% reduce 0%
19/06/11 09:45:48 INFO mapreduce.Job:  map 100% reduce 0%
19/06/11 09:51:04 INFO mapreduce.Job: Task Id : attempt_1554176896418_0537_m_000000_1, Status : FAILED
AttemptID:attempt_1554176896418_0537_m_000000_1 Timed out after 300 secs
19/06/11 09:51:05 INFO mapreduce.Job:  map 0% reduce 0%
19/06/11 09:51:17 INFO mapreduce.Job:  map 100% reduce 0%
19/06/11 09:56:34 INFO mapreduce.Job: Task Id : attempt_1554176896418_0537_m_000000_2, Status : FAILED
AttemptID:attempt_1554176896418_0537_m_000000_2 Timed out after 300 secs
19/06/11 09:56:35 INFO mapreduce.Job:  map 0% reduce 0%
19/06/11 09:56:48 INFO mapreduce.Job:  map 100% reduce 0%
19/06/11 10:02:05 INFO mapreduce.Job: Job job_1554176896418_0537 failed with state FAILED due to: Task failed task_1554176896418_0537_m_000000
Job failed as tasks failed. failedMaps:1 failedReduces:0

19/06/11 10:02:05 INFO mapreduce.Job: Counters: 9
	Job Counters 
		Failed map tasks=4
		Launched map tasks=4
		Other local map tasks=3
		Data-local map tasks=1
		Total time spent by all maps in occupied slots (ms)=2624852
		Total time spent by all reduces in occupied slots (ms)=0
		Total time spent by all map tasks (ms)=1312426
		Total vcore-seconds taken by all map tasks=1312426
		Total megabyte-seconds taken by all map tasks=2687848448
19/06/11 10:02:05 WARN mapreduce.Counters: Group FileSystemCounters is deprecated. Use org.apache.hadoop.mapreduce.FileSystemCounter instead
19/06/11 10:02:05 INFO mapreduce.ExportJobBase: Transferred 0 bytes in 1,333.3153 seconds (0 bytes/sec)
19/06/11 10:02:05 WARN mapreduce.Counters: Group org.apache.hadoop.mapred.Task$Counter is deprecated. Use org.apache.hadoop.mapreduce.TaskCounter instead
19/06/11 10:02:05 INFO mapreduce.ExportJobBase: Exported 0 records.
19/06/11 10:02:05 ERROR tool.ExportTool: Error during export: Export job failed!


Time taken: 1340 s 
task IDE_TASK_ADE56470-B5A3-4303-EA75-44312FF8AA0C_20190611093945147 is complete.

可以看到,导入任务在INFO mapreduce.Job: map 100% reduce 0%时停住了,停了5分钟,然后任务自动重跑,又卡住停了5分钟,最后任务报了个超时的错误。

很显然,任务失败的直接原因是超时,但是超时的原因是因为导入过程的mapreduce任务卡住了,那mapreduce为什么会卡住呢?这个报错日志中并没有提到,这就是查原因时最麻烦的地方。

先说一下结果,最后查了很久才发现,是因为有一行的数据长度,超过了mysql设定的字段长度。也就是在往varchar(50)的字段里导入字符串“字符串很长很长很长很长很长很长很长很长很长”时,任务就阻塞住了。

在这里也跟大家汇总一下网上的各种原因,大家可以逐个检查

在map 100% reduce 0%时卡住的可能原因:(以往mysql导出为例)

  1. 长度溢出。导入的数据超过了mysql表的字段设定长度
    解决办法:重设字段长度即可
  2. 编码错误。导入的数据不在mysql的编码字符集内
    解决办法:其实在mysql数据库中对应UTF-8字符集的不是utf8编码,而是utf8mb4编码。所以当你的导入数据里有若如Emoji表情或者一些生僻汉字时,就会导不进去造成阻塞卡住。所以你需要注意两点:
    (1)导入语句中限定useUnicode=true&characterEncoding=utf-8,表示以utf-8的格式导出;
    (2)mysql建表语句中有ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
  3. 内存不足。导入数据量可能过大,或者分配内存太少
    解决办法:要么分批导入,要么给任务分配更多内存
  4. 主机名错误
    解决办法:这个好像是涉及到主机名的配置问题,可以参考https://bbs.csdn.net/topics/380060079
  5. 主键重复
    解决办法:这是因为你导入的数据中有重复的主键值,要针对性处理一下数据

你可能感兴趣的:(hive,mysql)