报错java.lang.NoSuchFieldError: METASTORE_CLIENT_SOCKET_LIFETIME升级报错Required field 'client_protocol' is unset! 终级解决方案

一、问题描述

 最近碰到一个令人郁闷的问题,因为客户的 CDH 版本比较低,hive1.1.0 版本,而我们现在使用的 spark 版本都比较近搞,这样就会造成,如果我使用 hive1.1.0 版本就会报错:

java.lang.NoSuchFieldError: METASTORE_CLIENT_SOCKET_LIFETIME

 网上查询之后,原因是高版本的 hive-exc1.2.1 驱动中有这个字段,但是 hive1.1.0 版本中没有,二者对不上,建议将 hive 驱动版本升级到 1.1.0;而我将版本升级到 hive1.2.1 之后,就会报错:

Required field 'client_protocol' is unset!”

 网上查询之后,说是 hive 客户端驱动版本和 hive 服务器版本不一致;需要将驱动版本设置成 hive1.1.0,郁闷中...

 二、问题解决

  经同事提醒,这个版本不一致,是否可以 CDH 平台的版本验证参数关闭,于是乎,讲过查询版本验证参数为:hive.metastore.schema.verification。再查看 CDH 平台中此参数设置,发现原来默认的 false 被改成了 true;将该参数恢复默认。spark 调试通过。

三、补充一些 hive 的参数配置

关于 MetaStore:metastore 是个独立的关系数据库,用来持久化 schema 和系统元数据。

hive.metastore.local:控制 hive 是否连接一个远程 metastore 服务器还是开启一个本地客户端 jvm,默认是 true,Hive0.10 已经取消了该配置项;

javax.jdo.option.ConnectionURL:JDBC 连接字符串,默认 jdbc:derby:;databaseName=metastore_db;create=true;

javax.jdo.option.ConnectionDriverName:JDBC 的 driver,默认org.apache.derby.jdbc.EmbeddedDriver

javax.jdo.PersisteneManagerFactoryClass:实现 JDO PersistenceManagerFactory 的类名,默认 org.datanucleus.jdo.JDOPersistenceManagerFactory;

javax.jdo.option.DetachAllOnCommit:事务提交后 detach 所有提交的对象,默认是 true;

javax.jdo.option.NonTransactionalRead:是否允许非事务的读,默认是 true;

javax.jdo.option.ConnectionUserName:username,默认 APP;

javax.jdo.option.ConnectionPassword:password,默认 mine;

javax.jdo.option.Multithreaded:是否支持并发访问 metastore,默认是 true;

datanucleus.connectionPoolingType:使用连接池来访问 JDBC metastore,默认是 DBCP;

datanucleus.validateTables:检查是否存在表的 schema,默认是 false;

datanucleus.validateColumns:检查是否存在列的 schema,默认 false;

datanucleus.validateConstraints:检查是否存在 constraint 的 schema,默认 false;

datanucleus.stroeManagerType:元数据存储类型,默认 rdbms;

datanucleus.autoCreateSchema:在不存在时是否自动创建必要的 schema,默认是 true;

datanucleus.aotuStartMechanismMode:如果元数据表不正确,抛出异常,默认是 checked;

datanucleus.transactionIsolation:默认的事务隔离级别,默认是 read-committed;

datanucleus.cache.level2:使用二级缓存,默认是 false;

datanucleus.cache.level2.type:二级缓存的类型,有两种,SOFT: 软引用,WEAK: 弱引用,默认是 SOFT;

datanucleus.identifierFactory:id 工厂生产表和列名的名字,默认是 datanucleus;

datanucleus.plugin.pluginRegistryBundleCheck:当 plugin 被发现并且重复时的行为,默认是 LOG;

hive.metastroe.warehouse.dir:数据仓库的位置,默认是 /user/hive/warehouse;

hive.metastore.execute.setugi:非安全模式,设置为 true 会令 metastore 以客户端的用户和组权限执行 DFS 操作,默认是 false,这个属性需要服务端和客户端同时设置;

hive.metastore.event.listeners:metastore 的事件监听器列表,逗号隔开,默认是空;

hive.metastore.partition.inherit.table.properties:当新建分区时自动继承的 key 列表,默认是空;

hive.metastore.end.function.listeners:metastore 函数执行结束时的监听器列表,默认是空;

hive.metastore.event.expiry.duration:事件表中事件的过期时间,默认是 0;

hive.metastore.event.clean.freq:metastore 中清理过期事件的定时器的运行周期,默认是 0;

hive.metastore.connect.retries:创建 metastore 连接时的重试次数,默认是 5;

hive.metastore.client.connect.retry.delay:客户端在连续的重试连接等待的时间,默认 1;

hive.metastore.client.socket.timeout:客户端 socket 超时时间,默认 20 秒;

hive.metastore.rawstore.impl:原始 metastore 的存储实现类,默认是 org.apache.hadoop.hive.metastore.ObjectStore;

hive.metastore.batch.retrieve.max:在一个 batch 获取中,能从 metastore 里取出的最大记录数,默认是 300;

hive.metastore.ds.connection.url.hook:查找 JDO 连接 url 时 hook 的名字,默认是 javax.jdo.option.ConnectionURL;

hive.metastore.ds.retry.attempts:当出现连接错误时重试连接的次数,默认是 1 次;

hive.metastore.ds.retry.interval:metastore 重试连接的间隔时间,默认 1000 毫秒;

hive.metastore.server.min.threads:在 thrift 服务池中最小的工作线程数,默认是 200;

hive.metastore.server.max.threads:最大线程数,默认是 100000;

hive.metastore.server.tcp.keepalive:metastore 的 server 是否开启长连接,长连可以预防半连接的积累,默认是 true;

hive.metastore.sasl.enabled:metastore thrift 接口的安全策略,开启则用 SASL 加密接口,客户端必须要用 Kerberos 机制鉴权,默认是不开启 false;

hive.metastore.kerberos.keytab.file:在开启 sasl 后 kerberos 的 keytab 文件存放路径,默认是空;

hive.metastore.kerberos.principal:kerberos 的 principal,_HOST 部分会动态替换,默认是hive-metastore/_HOST@EXAMPLE.COM

hive.metastore.cache.pinobjtypes:在 cache 中支持的 metastore 的对象类型,由逗号分隔,默认是 Table,StorageDescriptor,SerDeInfo,Partition,Database,Type,FieldSchema,Order;

hive.metastore.authorization.storage.checks:在做类似 drop partition 操作时,metastore 是否要认证权限,默认是 false;

hive.metastore.schema.verification:强制 metastore 的 schema 一致性,开启的话会校验在 metastore 中存储的信息的版本和 hive 的 jar 包中的版本一致性,并且关闭自动 schema 迁移,用户必须手动的升级 hive 并且迁移 schema,关闭的话只会在版本不一致时给出警告,默认是 false 不开启;