thrift.transport.TTransport.TTransportException: TSocket read 0 bytes报错解决
一、问题描述
htrift版本:2.0.0-cdh6.0.1
hbase版本:1.2.0-cdh5.7.0
使用 thrift client with python 连接 hbase 报错:
File "C:\Users\HP\env1\lib\site-packages\thrift\transport\TSocket.py", line 132, in read
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
二、查找原因
1)hbase连接代码
from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTransport
transport = TTransport.TBufferedTransport(TSocket.TSocket(10.201.7.113, int(port)))
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
2) hbase-site.xml 配置如下
<property>
<name>hbase.regionserver.thrift.framed</name>
<value>true</value>
</property>
<property>
<name>hbase.regionserver.thrift.compact</name>
<value>true</value>
</property>
3) thrift server日志如下:(/var/log/hbase/hbase-hbase-thrift-.log)
INFO [main] mortbay.log: Started HttpServer$SelectChannelConnectorWithSafeStartup@0.0.0.0:9095
DEBUG [main] thrift.ThriftServerRunner: Using compact protocol
DEBUG [main] thrift.ThriftServerRunner: Using framed transport
INFO [main] thrift.ThriftServerRunner: starting TBoundedThreadPoolServer on /0.0.0.0:9090; min worker threads=16, max worker threads=1000, max queued requests=1000
由以上可知,是因为thrift 的server端和client端的协议不匹配造成的。
解决方案:
方案一:修改hbase-site.xml,禁用TFramedTransport和TCompactProtocol功能,即:
<property>
<name>hbase.regionserver.thrift.framed</name>
<value>false</value>
</property>
<property>
<name>hbase.regionserver.thrift.compact</name>
<value>false</value>
</property>
重启thrift 服务器: service hbase-thrift restart
方案二:修改客户端代码
transport = TFramedTransport(TSocket('192.168.0.10', 9090))
protocol = TCompactProtocol.TCompactProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
还没有评论,来说两句吧...