先 scan 原表,然后 bulkload 到新表。

采坑纪录
1. bulkload 产生 hfile 前,需要先对 hash(key) 做 repartition,在 shuffle 的 read 阶段,产生了以下错误

org.apache.spark.shuffle.FetchFailedException: failed to allocate 16777216 byte(s) of direct memory (used: 3623878656, max: 3635150848)
at org.apache.spark.storage.ShuffleBlockFetcherIterator.throwFetchFailedException(ShuffleBlockFetcherIterator.scala:523)
at org.apache.spark.storage.ShuffleBlockFetcherIterator.next(ShuffleBlockFetcherIterator.scala:454)
...
Caused by: io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 3623878656, max: 3635150848)
at io.netty.util.internal.PlatformDependent.incrementMemoryCounter(PlatformDependent.java:640)
at io.netty.util.internal.PlatformDependent.allocateDirectNoCleaner(PlatformDependent.java:594)
...

原因:在 shuffle 的 read 阶段,会申请一个跟 block(或partition)一样大小的内存,因为每个分区过大,内存不够了
相关说明:https://issues.apache.org/jira/browse/SPARK-13510

因为netty默认使用了offheap memory,所以报了这个错误。可选择加入java参数 "-Dio.netty.noUnsafe=true",不使用 offheap 内存

2. bulkload 产生 hfile 的时候,多次发生因 executor 被 killed,导致 application 失败。通过观察,发现是 executor 往本地写文件的时候,本地空间不够了。
相关问题:https://stackoverflow.com/questions/29131449/why-does-hadoop-report-unhealthy-node-local-dirs-and-log-dirs-are-bad

于是增加 yarn 集群机器,使用 hdfs balancer 均衡数据分布。

============= yarn-nodemanager =============
2019-02-15 10:18:45,562 WARN org.apache.hadoop.yarn.server.nodemanager.DirectoryCollection (DiskHealthMonitor-Timer): Directory /mnt/yarn error, used space above threshold of 90.0%, removing from list of valid directories
2019-02-15 10:18:45,563 WARN org.apache.hadoop.yarn.server.nodemanager.DirectoryCollection (DiskHealthMonitor-Timer): Directory /var/log/hadoop-yarn/containers error, used space above threshold of 90.0%, removing from list of valid directories
2019-02-15 10:18:45,563 INFO org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService (DiskHealthMonitor-Timer): Disk(s) failed: 1/1 local-dirs are bad: /mnt/yarn; 1/1 log-dirs are bad: /var/log/hadoop-yarn/containers
2019-02-15 10:18:45,563 ERROR org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService (DiskHealthMonitor-Timer): Most of the disks failed. 1/1 local-dirs are bad: /mnt/yarn; 1/1 log-dirs are bad: /var/log/hadoop-yarn/containers
2019-02-15 10:18:45,789 INFO org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService (AsyncDispatcher event handler): Cache Size Before Clean: 589300919, Total Deleted: 0, Public Deleted: 0, Private Deleted: 0
2019-02-15 10:18:46,668 INFO org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl (AsyncDispatcher event handler): Container container_1549968021090_0114_01_000006 transitioned from RUNNING to KILLING
2019-02-15 10:18:46,668 INFO org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl (AsyncDispatcher event handler): Container container_1549968021090_0114_01_000016 transitioned from RUNNING to KILLING ============= yarn-resourcemanager.log =============
019-02-15 10:18:45,664 INFO org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl (AsyncDispatcher event handler): Node ip-10-6-43-89.ap-south-1.compute.internal:8041 reported UNHEALTHY with details: 1/1 local-dirs are bad: /mnt/yarn; 1/1 log-dirs are bad: /var/log/hadoop-yarn/containers
2019-02-15 10:18:45,664 INFO org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl (AsyncDispatcher event handler): ip-10-6-43-89.ap-south-1.compute.internal:8041 Node Transitioned from RUNNING to UNHEALTHY
2019-02-15 10:18:45,664 INFO org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerImpl (ResourceManager Event Processor): container_1549968021090_0114_01_000006 Container Transitioned from RUNNING to KILLED

3. shuffle 在读取文件时,非常依赖 netty 的 offheap 堆栈,设置不使用 offheap memory 之后,会有以下错误(内存调很大也会出现)。

2019-02-17T02:56:12.949+0000: [Full GC (Ergonomics) [PSYoungGen: 465920K->465917K(931840K)] [ParOldGen: 2796146K->2796069K(2796544K)] 3262066K->3261987K(3728384K), [Metaspace: 67840K->67739K(1110016K)], 5.2891526 secs] [Times: user=18.15 sys=0.01, real=5.29 secs]
#
# java.lang.OutOfMemoryError: GC overhead limit exceeded
# -XX:OnOutOfMemoryError="kill -9 %p"
# Executing /bin/sh -c "kill -9 8023"...

  或者是

2019-02-17T02:59:43.073+0000: [Full GC (Ergonomics) [PSYoungGen: 123392K->123391K(422912K)] [ParOldGen: 2796365K->2796364K(2796544K)] 2919757K->2919756K(3219456K), [Metaspace: 67051K->67051K(1107968K)], 3.3979517 secs] [Times: user=13.45 sys=0.00, real=3.39 secs]
2019-02-17T02:59:43.073+0000: [Full GC (Ergonomics) ............
2019-02-17T02:59:43.073+0000: [Full GC (Ergonomics) ............
2019-02-17T02:59:43.073+0000: [Full GC (Ergonomics) ............
2019-02-17T02:59:43.073+0000: [Full GC (Ergonomics) ............ ExecutorLostFailure (executor 6 exited caused by one of the running tasks) Reason: Executor heartbeat timed out after 125095 ms

  

因为 shuffle 本身不占用太多内存,但产生 hfile 之前的 sort 需要很多内存,在 spark 的统一内存管理模型中,这是 other 部分的空间。推测是 spark 统一内存模型,计算出现错误,挤压了 other 部分的空间大小。于是加入下面的参数

spark.memory.fraction=0.2

4. 产生了 HFile 之后,需要导入到 hbase,遇到下面问题

Sat Feb 16 21:48:36 UTC 2019, RpcRetryingCaller{globalStartTime=1550353152797, pause=100, retries=35}, org.apache.hadoop.hbase.ipc.RemoteWithExtrasException(org.apache.hadoop.ipc.RemoteException): org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /apps/hbase/data/data/ap/users_v2/9a9d8ee1e23d335afb01aced349054d8/.tmp/70ad5fa3d4834fb6a47abee6101594ff could only be replicated to 0 nodes instead of minReplication (=1).  There are 4 datanode(s) running and no node(s) are excluded in this operation.
at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1719)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getNewBlockTargets(FSNamesystem.java:3372)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:3296)

因为我们 spark 与 hbase 不在一个 yarn 上,没有共享 hdfs。一开始 HFile 写在 spark 的集群上,于是产生了很多问题。之后改成 HFile 写在 hbase 的同集群中,这一步很快就过了。具体原因不详。

5. emr的配置中,spark 的本地文件缓存路径为 /mnt/yarn/usercache/hadoop/appcache/application_1549968021090_0135/blockmgr-535fd27a-4b80-4116-b855-17ab7be68f1c。与 hdfs 在一个硬盘上。

===============================================================================================

最终提交 spark 的命令为

spark-submit \
--master yarn \
--name UserTableFromPrimitiveToV2 \
--queue default \
--deploy-mode cluster \
--driver-cores 2 \
--driver-memory 5g \
--num-executors 30 \
--executor-cores 2 \
--executor-memory 4g \
--conf spark.driver.memoryOverhead=1g \
--conf spark.executor.memoryOverhead=2g \
--conf spark.dynamicAllocation.enabled=false \
--conf spark.yarn.maxAppAttempts=1 \
--conf spark.blacklist.enabled=false \
--conf spark.memory.fraction=0.2 \
--conf spark.executor.extraJavaOptions="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=0 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseParallelGC -XX:MaxHeapFreeRatio=70 -XX:+CMSClassUnloadingEnabled -XX:OnOutOfMemoryError='kill -9 %p' -Dio.netty.noUnsafe=true" \
--class com.hotstar.ap.ingest.batch.tool.migration.UserTableFromPrimitiveToV2 \
./batch/build/libs/batch-all.jar \
-e dev

  

在 aws emr 上,将 hbase table A 的数据,对 key 做 hash,写到另外一张 table B的更多相关文章

  1. AWS EMR上搭建HBase环境

    0. 概述 AWS的EMR服务为客户提供的托管 Hadoop 框架可以让您轻松.快 速.经济高效地在多个动态可扩展的 Amazon EC2 实例之间分发和处理 大量数据.您还可以运行其他常用的分发框架 ...

  2. 在AWS EMR上运行Map Reduce的Java示例程序 及 操作小计

    下面的代码中AffairClient类中包含了三个内之类,分别对应于Hadoop Mapreduce程序运行所需的Mapper类,Reducer类,和主类.AffairClient类中其余方法用于配置 ...

  3. Apache Hudi C位!云计算一哥AWS EMR 2020年度回顾

    1. 概述 成千上万的客户在Amazon EMR上使用Apache Spark,Apache Hive,Apache HBase,Apache Flink,Apache Hudi和Presto运行大规 ...

  4. 在aws ec2上使用root用户登录

    aws ec2默认是使用ec2-user账号登陆的,对很多文件夹是没有权限的.如何使用root账号执行命令就是一个问题了.解决办法如下: 1.根据官网提供的方法登录连接到EC2服务器(官网推荐wind ...

  5. Ubuntu 12.04上安装HBase并运行

    Ubuntu 12.04上安装HBase并运行 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.HBase的安装 在官网上下载HBase-1.1.2 ...

  6. Java通过aws java sdk在AWS S3上进行操作客户端

    有两种方式可以安装aws java sdk:方式一:可以在这个网站上下载适用于 Java 的 AWS 开发工具包https://aws.amazon.com/cn/sdk-for-java/点击网页右 ...

  7. Kubernetes-在Kubernetes集群上搭建HBase集群

    经过3天的努力,终于在Kubernetes上把HBase集群搭建起来了,搭建步骤如下. 创建HBase镜像   配置文件包含core-site.xml.hbase-site.xml.hdfs-site ...

  8. 【AWS】使用X-Ray做AWS云上全链路追踪监控系统

    功能 AWS X-Ray 是一项服务,收集应用程序所请求的相关数据,并提供用于查看.筛选和获取数据洞察力的工具,以确定问题和发现优化的机会. 对于任何被跟踪的对您应用程序的请求,不仅可以查看请求和响应 ...

  9. 划重点!AWS的湖仓一体使用哪种数据湖格式进行衔接?

    此前Apache Hudi社区一直有小伙伴询问能否使用Amazon Redshift查询Hudi表,现在它终于来了. 现在您可以使用Amazon Redshift查询Amazon S3 数据湖中Apa ...

随机推荐

  1. hadoop学习笔记(二):hdfs优点和缺点

    优点 其中的10k+,指的是每一个块必须>=1M 缺点 低延迟:是指hadoop处理数据都是以分钟为单位的,而不像storm那样的是以毫秒级为单位的. 高吞吐率:是指你分布式存储的文件块的大小必 ...

  2. Mysql 中使用 utfmb4 需要注意的问题

    查资料时看到一个前人的经验总结,非常有用: http://seanlook.com/2016/10/23/mysql-utf8mb4/

  3. 使用$.ajax时的注意事项

    做PHP难免接触js,我也是这样,使用ajax的时候,我比较习惯使用$.ajax({}),这种方式,因为通用性较强.有时候会较少使用js,隔一段时间后再使用,有些细节内容容易模糊不清,这一次,我又忘记 ...

  4. Python:列表类型

    概念 列表:有序的,可变的,元素集合 因为列表和字符串都是序列类型,所以很多操作和字符串很相似 但是注意:列表是可变类型,字符串是不可变类型 定义 基本定义 定义方法:[ 元素1, 元素2, .... ...

  5. 2019牛客暑期多校训练营(第十场) Han Xin and His Troop (高精度+拓展中国剩余定理)

    题意 裸题 思路 题中的模数之间并不互质,所以应该用拓展中国剩余定理. 但是交上去会炸,__int128过不了,所以用高精度的板子或者java大数都挺好过的. 这里推荐java大数,因为高精度板子用起 ...

  6. 【代码学习】PYTHON 抛出异常

    class ShortInputException(Exception): '''你定义的异常类.''' def __init__(self, length, atleast): Exception. ...

  7. spring整合web项目

    Web项目如何初始化SpringIOC容器 :思路:当服务启动时(tomcat),通过监听器将SpringIOC容器初始化一次(该监听器 spring-web.jar已经提供),web项目启动时 ,会 ...

  8. 【原】cookie和session的区别

    1.存放位置 cookie的数据存放在客户端的浏览器上,session存放在服务器上 2.安全程度 cookie不是很安全,别人通过分析本地的cookie并进行cookie欺骗:考虑到安全应该使用se ...

  9. C++判断txt文件编码格式

    转载:https://blog.csdn.net/kikityan/article/details/89923808 记事本打开txt文件,然后另存,有四种编码格式可供选择,分别是:ANSI     ...

  10. [原]SVN代码管理

    1.SVN工程结构 branches zhangsan lisi wangwu tags project-release trunk project-trunk branches:下为trunk的分支 ...