实践数据湖iceberg 第十四课 元数据合并(解决元数据随时间增加而元数据膨胀的问题)

文章通过创建两个Iceberg表,对比了默认设置与开启元数据清理功能的差异。在开启清理的表中,每次插入数据后,元数据文件数量会控制在一定范围内,从而有效解决了元数据随时间膨胀的问题。通过这种方式,可以避免元数据占用过多存储空间。

系列文章目录

实践数据湖iceberg 第一课 入门
实践数据湖iceberg 第二课 iceberg基于hadoop的底层数据格式
实践数据湖iceberg 第三课 在sqlclient中,以sql方式从kafka读数据到iceberg
实践数据湖iceberg 第四课 在sqlclient中,以sql方式从kafka读数据到iceberg(升级版本到flink1.12.7)
实践数据湖iceberg 第五课 hive catalog特点
实践数据湖iceberg 第六课 从kafka写入到iceberg失败问题 解决
实践数据湖iceberg 第七课 实时写入到iceberg
实践数据湖iceberg 第八课 hive与iceberg集成
实践数据湖iceberg 第九课 合并小文件
实践数据湖iceberg 第十课 快照删除
实践数据湖iceberg 第十一课 测试分区表完整流程(造数、建表、合并、删快照)
实践数据湖iceberg 第十二课 catalog是什么
实践数据湖iceberg 第十三课 metadata比数据文件大很多倍的问题
实践数据湖iceberg 第十四课 元数据合并(解决元数据随时间增加而元数据膨胀的问题)



摘要

元数据随时间增加而元数据膨胀的问题:iceberg合并,删除快照,但元数据还是没有删除,6M的数据大小,有几十G的元数据。
为解决这个问题,是本课主要目的

本文整体思路:建立一个有自动清理table_a5与没有自动清理(默认)的分区表table_a,不断往分区表insert数据,insert前后,查看metadata目录的变化,并记录变化。
为什么用分区表,生产环境大部分是分区表。


1. 元数据随时间增加而元数据膨胀的问题

元数据随时间增加而元数据膨胀的问题:iceberg合并,删除快照,但元数据还是没有删除,6M的数据大小,有几十G的元数据。

2. 解决方案

在建表时,增加这2个参数
‘write.metadata.delete-after-commit.enabled’=‘true’,
‘write.metadata.previous-versions-max’=‘5’
增加参数的方法:

CREATE TABLE iceberg_db6.table_a5 (
  id bigint, name string
) PARTITIONED BY (
  dt string
) STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler'
TBLPROPERTIES (
 'write.distribution-mode'='hash',
 'write.metadata.delete-after-commit.enabled'='true',
 'write.metadata.previous-versions-max'='5'
);

这个语法,需要在hive客户端执行

3. 建立一个自动清理元数据与默认方式的表,进行比对

测试本方案的可行性

table_a 没有自动合并metadata
table_a5 保留5个之前的metadata,加上目录新写入的,总共6个。

[root@hadoop101 software]# hive
hive (default)> add jar /opt/module/hive/lib/iceberg-hive-runtime-0.12.1.jar;
Added [/opt/module/hive/lib/iceberg-hive-runtime-0.12.1.jar] to class path
Added resources: [/opt/module/hive/lib/iceberg-hive-runtime-0.12.1.jar]
hive (default)> use iceberg_db6;
OK
hive (iceberg_db6)> CREATE TABLE iceberg_db6.table_a (
                  >   id bigint, name string
                  > ) PARTITIONED BY (
                  >   dt string
                  > ) STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler';
OK
Time taken: 0.546 seconds
hive (iceberg_db6)> CREATE TABLE iceberg_db6.table_a5 (
                  >   id bigint, name string
                  > ) PARTITIONED BY (
                  >   dt string
                  > ) STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler'
                  > TBLPROPERTIES (
                  >  'write.distribution-mode'='hash',
                  >  'write.metadata.delete-after-commit.enabled'='true',
                  >  'write.metadata.previous-versions-max'='5'
                  > );
OK

4. 写数据并记录metadata的变化

在hive中insert数据

hive (iceberg_db6)> insert into table_a values(1,'apple','20220101')
                  > ;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = root_20220211115034_c75f4d78-073c-4643-a49a-0d659ca5dcb2
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1642579431487_0020, Tracking URL = http://hadoop101:8088/proxy/application_1642579431487_0020/
Kill Command = /opt/module/hadoop/bin/hadoop job  -kill job_1642579431487_0020
Hadoop job information for Stage-3: number of mappers: 1; number of reducers: 0
2022-02-11 11:50:43,643 Stage-3 map = 0%,  reduce = 0%
2022-02-11 11:50:50,911 Stage-3 map = 100%,  reduce = 0%, Cumulative CPU 4.16 sec
MapReduce Total cumulative CPU time: 4 seconds 160 msec
Ended Job = job_1642579431487_0020
MapReduce Jobs Launched: 
Stage-Stage-3: Map: 1   Cumulative CPU: 4.16 sec   HDFS Read: 115157 HDFS Write: 3616 SUCCESS
Total MapReduce CPU Time Spent: 4 seconds 160 msec
OK
_col0   _col1   _col2
Time taken: 18.719 seconds

没有合并元数据的表,每次执行,metadata增加3个文件,metadata.json, snap文件增加,-m0.avro文件增加

insert into table_a values(2,'apple2','20220101');
insert into table_a values(2,'apple2','20220101');
insert into table_a values(3,'apple3','20220101');
insert into table_a values(4,'apple4','20220101');
insert into table_a values(5,'apple5','20220101');
insert into table_a values(6,'apple6','20220101');

合并元数据的表:

insert into table_a5 values(1,'apple1','20220101');  
insert into table_a5 values(2,'apple2','20220101');   有7个元数据文件生成
insert into table_a5 values(2,'apple2','20220101');   总共有10个元数据文件生成
insert into table_a5 values(3,'apple3','20220101');   总共有13个元数据文件生成
insert into table_a5 values(4,'apple4','20220101');   总共有16个元数据文件生成
insert into table_a5 values(5,'apple5','20220101');   总共有18个元数据文件生成
insert into table_a5 values(6,'apple6','20220101');   总共有20个元数据文件生成

第二次insert table_a5

[root@hadoop103 ~]# hadoop fs -ls /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata
Found 7 items
-rw-r--r--   2 root supergroup       1846 2022-02-11 11:22 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/00000-af035f2a-6178-4b06-8c55-3182ecfec103.metadata.json
-rw-r--r--   2 root supergroup       2812 2022-02-11 11:57 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/00001-a058dcf4-4394-4691-a508-212290920ef2.metadata.json
-rw-r--r--   2 root supergroup       3813 2022-02-11 11:57 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/00002-de593422-a794-4acf-a0b8-3edaa444a1eb.metadata.json
-rw-r--r--   2 root supergroup       6108 2022-02-11 11:57 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/a2adc8c6-779d-4634-9840-ace594f56ac0-m0.avro
-rw-r--r--   2 root supergroup       6108 2022-02-11 11:57 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/bb1c1064-fc53-4e82-ab7a-16b3d306ccd6-m0.avro
-rw-r--r--   2 root supergroup       3865 2022-02-11 11:57 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/snap-8601063452676878887-1-bb1c1064-fc53-4e82-ab7a-16b3d306ccd6.avro
-rw-r--r--   2 root supergroup       3796 2022-02-11 11:57 /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata/snap-9064233795022707236-1-a2adc8c6-779d-4634-9840-ace594f56ac0.avro

第三次insert后,总共10个元数据文件,比上次增加三个文件。每种文件类型增加一个。

[root@hadoop103 ~]# hadoop fs -ls /user/hive/warehouse/hive_catalog6/iceberg_db6.db/table_a5/metadata
Found 10 items
-rw-r--r--   2 root supergroup       1846 2022-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值