好吧,我已经处理这个问题几天了,这让我发疯了。我需要使用带有事务的 Hive 数据库来执行“更新”和“删除”操作。
我已经以伪分布式模式在我的机器上安装了 Hadoop 和 Hive。我已关注此 tutorial用于安装。我使用的是 Java 1.8.0_31、Hadoop 2.6.0、Hive 1.0.0,我还更改了一些细节,但这些应该无关紧要。
现在,要启动我的环境(例如,重新启动后),我运行以下命令:
start-dfs.sh
start-yarn.sh
java -jar /usr/local/derby/lib/derbyrun.jar server start &
hive
一切似乎都运行良好。尽管本教程没有提到启动 derby,但如果我不启动它,则 Metastore 不可用(这似乎合乎逻辑)并且 hive 不会启动。
从这里,我可以创建表、显示表、连接我的 JDBC 客户端等,一切都很好。现在,我需要启用事务。关注此 link而这个 link我得到以下命令:
hive --hiveconf hive.root.logger=info,console
--hiveconf hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager
--hiveconf hive.compactor.initiator.on=true
--hiveconf hive.compactor.worker.threads=1
--hiveconf hive.txn.driver=jdbc:derby://localhost:1527/metastore_db;create=true
旁注:我更改命令而不是 hive-site.xml 只是因为在尝试哪些有效和哪些无效时更容易在命令之间进行更改,而不是重复更改 XML 文件。
我也尝试将驱动程序 url 更改为
jdbc:derby://localhost:1527/metastore_db;create=true;user=APP;password=mine
以防万一它是需要的,但没有变化。当我发出命令(如 show tables
)时,出现错误:15/03/04 23:26:17 [main]: ERROR metastore.RetryingHMSHandler:
MetaException(message:Unable to select from transaction database,
java.sql.SQLSyntaxErrorException: Table/View 'TXNS' does not exist.
根据this和 previous links 之一,好像是
hive.in.test
属性必须设置为 true
.所以,我的启动命令变成:hive --hiveconf hive.root.logger=info,console
--hiveconf hive.in.test=true
--hiveconf hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager
--hiveconf hive.compactor.initiator.on=true
--hiveconf hive.compactor.worker.threads=1
--hiveconf hive.txn.driver=jdbc:derby://localhost:1527/metastore_db;create=true;
使用此命令,我收到一个新错误:
ERROR metastore.RetryingHMSHandler: java.lang.NullPointerException
at org.apache.hadoop.hive.metastore.txn.TxnHandler.checkQFileTestHack(TxnHandler.java:1146)
而且这个错误在任何地方都不存在,我觉得我是互联网上唯一一个有它的人。无论如何,因为我找不到任何解决方案,所以我挖了源代码:
private void checkQFileTestHack() {
boolean hackOn = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST) ||
HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEZ_TEST);
LOG.info("Before if");
if (hackOn) {
LOG.info("Hacking in canned values for transaction manager");
// Set up the transaction/locking db in the derby metastore
TxnDbUtil.setConfValues(conf);
try {
TxnDbUtil.prepDb();
} catch (Exception e) {
// We may have already created the tables and thus don't need to redo it.
if (!e.getMessage().contains("already exists")) {
throw new RuntimeException("Unable to set up transaction database for" +
" testing: " + e.getMessage());
}
}
}
}
第 1146 行是
if (!e.getMessage().contains("already exists"))
行,这似乎没有多大意义,除非“e”是空值,这很奇怪。无论如何,我想我可以通过添加更多日志消息、构建项目并替换我修改过的原始 Metastore jar(这是 TxnHandler 类所在的位置)来进一步调试。为此,我下载了源代码并关注 this来 build 它。我试过maven2,没用,因为有的插件只对maven3有效,所以我从here得到了maven3并建立了这个项目。如果我用
mvn clean install -Phadoop-2,dist
构建它命令,不仅需要永远,而且在测试阶段失败。因为它不会在 Metastore 上失败(在 Metastore 上,它跳过 1 次测试,我不确定这是否应该发生),我想我可以不进行测试就构建它。所以,我们得到了这个:mvn clean install -DskipTests -Phadoop-2,dist
rm /usr/local/hive/lib/hive-metastore-1.0.0.jar
cp packaging/target/apache-hive-1.0.0-bin/apache-hive-1.0.0-bin/lib/hive-metastore-1.0.0.jar /usr/local/hive/lib/
旁注:为了节省时间,我也尝试了
-pl metastore -am
参数,但是虽然 maven 说已经构建了 Metastore,但 lib 文件夹中的 jar 没有改变,所以我猜我做错了什么。无论如何,这应该构建我修改过的 jar,替换 hive 中的那个,当我再次启动 hive 时,它应该加载我的。但是,即使我更改了代码,错误仍然显示相同,我的新日志信息未注册,甚至错误行保持不变。就像我在我的新 jar 里什么都没改变。
很奇怪,我知道 maven 正在编译我的代码,因为它可以识别编译错误,而且我可以在 jar 属性上看到它是一个新文件,那么为什么我的其余更改不显示?当我删除原始 jar 时,Hive 会识别出来,但是当我用修改后的版本替换它时,就像我什么都没改变一样。
不管怎样,正如你所看到的,我遇到了很多麻烦,我已经尝试解决其中的大部分问题。但是现在我陷入了这个困境,无法使用该死的“删除”命令,因为我无法启用交易。任何人都可以指出我正确的方向吗?泰姆!
......很抱歉这篇很长的帖子。
最佳答案
我关注了斯里尼瓦斯 advice并且错误消失了。我不再需要将“hive.in.test”属性设置为“true”,一切正常。
我仍然不知道为什么更改源不会影响 hive 程序的其余部分,但我有事务工作。
编辑:万一链接失效,这里有一个报价:
After extracting Hive version, you have to create Hive meta store
sudo apt-get install mysql-server sudo service mysql start sudo apt-get install libmysql-java ln -s /usr/share/java/libmysql-java.jar /usr/lib/hive/lib/libmysql-java.jar sudo chkconfig mysql on mysql -u root -p Enter password: mysql> CREATE DATABASE metastore; mysql> USE metastore; mysql> SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-0.12.0.mysql.sql; mysql> CREATE USER 'hive'@'metastorehost' IDENTIFIED BY 'mypassword'; ... mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'hive'@'metastorehost'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,LOCK TABLES,EXECUTE ON metastore.* TO 'hive'@'metastorehost'; mysql> FLUSH PRIVILEGES; mysql> quit;
Then in hive-site.xml, you need set the new parameters like
javax.jdo.option.ConnectionURL - jdbc:mysql://myhost/metastore javax.jdo.option.ConnectionDriverName - com.mysql.jdbc.Driver javax.jdo.option.ConnectionUserName - hive javax.jdo.option.ConnectionPassword - mypassword datanucleus.autoCreateSchema - false datanucleus.fixedDatastore - true datanucleus.autoStartMechanism - SchemaTable hive.metastore.uris - thrift://<n.n.n.n>:9083 hive.support.concurrency – true hive.enforce.bucketing – true hive.exec.dynamic.partition.mode – nonstrict hive.txn.manager – org.apache.hadoop.hive.ql.lockmgr.DbTxnManager hive.compactor.initiator.on – true hive.compactor.worker.threads – 1
Then restart Hive-server and Metastore. Now create one normal table and one external table with orc format and load from normal to orc table. Now you can update and delete records.
关于java - Hive 事务正在崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28867368/