【问题标题】:Partition in metastore but path doesn't exist in HDFSMetastore 中的分区,但 HDFS 中不存在路径
【发布时间】:2017-12-09 10:07:43
【问题描述】:

我们的摄取过程存在问题,导致分区被添加到 Hive 中的表中,但 HDFS 中的路径实际上并不存在。我们已经解决了这个问题,但我们仍然有这些坏分区。当使用 Tez 查询这些表时,我们得到 FileNotFound 异常,指向 HDFS 中不存在的位置。如果我们使用 MR 而不是 Tez,查询可以工作(这让我很困惑),但它太慢了。

有没有办法列出所有有这个问题的分区? MSCK REPAIR 似乎处理了相反的问题,即数据存在于 HDFS 中但 Hive 中没有分区。

编辑:更多信息。 这是文件未找到异常的输出:

java.io.FileNotFoundException: File hdfs://<server>/db/tables/2016/03/14/mytable does not exist.

如果我运行show partitions <db.mytable>,我将获得所有分区,包括dt=2016-03-14 的一个。

show table extended like '<db.mytable>' partition(dt='2016-03-14' 返回相同的位置: location:hdfs://server/db/tables/2016/03/14/mytable.

【问题讨论】:

  • 另一个分区的位置如何?
  • 其他分区看起来几乎一样:location:hdfs://server/db/tables/2017/06/07/mytable。唯一的区别是它确实存在。
  • 请检查路径之一(metastore / hdfs)是否包含白色字符

标签: hive hdfs


【解决方案1】:

MSCK REPAIR TABLE <tablename> 不提供此功能,我也面临同样的问题,我找到了解决方案,

我们知道'msck repair'命令根据目录添加分区,所以首先删除所有分区

hive>ALTER TABLE mytable drop if exists partitions(p<>'');

以上命令删除所有分区,

然后使用msck repair 命令然后它将从表位置存在的目录创建分区。

hive>msck repair table mytable

【讨论】:

    【解决方案2】:

    似乎MSCK REPAIR TABLE 不会删除指向丢失目录的分区,但它确实列出了这些分区(请参阅Partitions not in metastore:),因此通过一些脚本/手动工作,您可以根据给定的列表删除它们。

    hive> create table mytable (i int) partitioned by (p int);
    OK
    Time taken: 0.539 seconds
    
    hive> !mkdir mytable/p=1;
    hive> !mkdir mytable/p=2;
    hive> !mkdir mytable/p=3;
    
    hive> msck repair table mytable;
    OK
    Partitions not in metastore:    mytable:p=1 mytable:p=2 mytable:p=3
    Repair: Added partition to metastore mytable:p=1
    Repair: Added partition to metastore mytable:p=2
    Repair: Added partition to metastore mytable:p=3
    Time taken: 0.918 seconds, Fetched: 4 row(s)
    
    hive> show partitions mytable;
    OK
    p=1
    p=2
    p=3
    Time taken: 0.331 seconds, Fetched: 3 row(s)
    
    hive> !rmdir mytable/p=1;
    hive> !rmdir mytable/p=2;
    hive> !rmdir mytable/p=3;
    
    hive> msck repair table mytable;
    OK
    Partitions missing from filesystem: mytable:p=1 mytable:p=2 mytable:p=3
    Time taken: 0.425 seconds, Fetched: 1 row(s)
    
    hive> show partitions mytable;
    OK
    p=1
    p=2
    p=3
    Time taken: 0.56 seconds, Fetched: 3 row(s)
    

    【讨论】:

    • msck repair table db.mytable 返回No rows affected。我在原始帖子中添加了更多信息,以防万一。
    • 你的 Hive 版本是什么?
    • Apache Hive(版本 1.2.1000.2.6.0.3-8)
    猜你喜欢
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 2021-03-16
    相关资源
    最近更新 更多