1

我在名为hadoop.

core-site.xml文件的fs.defaultFS(等效于fs.default.name)设置为以下内容:

<property>
  <name>fs.defaultFS</name>
  <value>hdfs://hadoop:8020</value>
</property>

我有一个非常简单的表test_table,该表当前存在于 HDFS 上的 Hive 服务器中。也就是说,它存储在/user/hive/warehouse/test_table. 它是在 Hive 中使用一个非常简单的命令创建的:

CREATE TABLE new_table (record_id INT);

如果我尝试在本地(即使用LOAD DATA LOCAL)将数据加载到表中,一切都会按预期进行。但是,如果数据存储在 HDFS 上并且我想从那里加载,则会出现问题。

我运行一个非常简单的查询来尝试这个加载:

hive> LOAD DATA INPATH '/user/haduser/test_table.csv' INTO TABLE test_table;

这样做会导致以下错误:

FAILED: SemanticException [Error 10028]: Line 1:17 Path is not legal ''/user/haduser/test_table.csv'':
Move from: hdfs://hadoop:8020/user/haduser/test_table.csv to: hdfs://localhost:8020/user/hive/warehouse/test_table is not valid.
Please check that values for params "default.fs.name" and "hive.metastore.warehouse.dir" do not conflict.

正如错误所述,它正试图从 移动hdfs://hadoop:8020/user/haduser/test_table.csvhdfs://localhost:8020/user/hive/warehouse/test_table。第一条路径是正确的,因为它引用了hadoop:8020; 第二条路径不正确,因为它引用了localhost:8020.

core-site.xml文件明确规定使用hdfs://hadoop:8020. 中的hive.metastore.warehousehive-site.xml正确指向/user/hive/warehouse。因此,我怀疑此错误消息是否具有任何真实价值。

创建表时如何让 Hive 服务器使用正确的 NameNode 地址?

4

1 回答 1

5

我发现 Hive 元存储跟踪每个表的位置。您可以在 Hive 控制台中看到该位置正在运行以下命令。

hive> DESCRIBE EXTENDED test_table;

core-site.xml因此,如果在 Metastore 服务仍在运行时更改了 NameNode,则会出现此问题。因此,要解决此问题,应在该计算机上重新启动服务:

$ sudo service hive-metastore restart

Then, the metastore will use the new fs.defaultFS for newly created tables such.

Already Existing Tables

The location for tables that already exist can be corrected by running the following set of commands. These were obtained from Cloudera documentation to configure the Hive metastore to use High-Availability.

$ /usr/lib/hive/bin/metatool -listFSRoot
...
Listing FS Roots..
hdfs://localhost:8020/user/hive/warehouse
hdfs://localhost:8020/user/hive/warehouse/test.db

Correcting the NameNode location:

$ /usr/lib/hive/bin/metatool -updateLocation hdfs://hadoop:8020 hdfs://localhost:8020

Now the listed NameNode is correct.

$ /usr/lib/hive/bin/metatool -listFSRoot
...
Listing FS Roots..
hdfs://hadoop:8020/user/hive/warehouse
hdfs://hadoop:8020/user/hive/warehouse/test.db
于 2013-10-17T16:03:56.373 回答