thrift.transport.TTransport.TTransportException: TSocket read 0 bytes报错解决

太过爱你忘了你带给我的痛 2022-01-29 01:59 1162阅读 0赞

一、问题描述

  1. htrift版本:2.0.0-cdh6.0.1
  2. hbase版本:1.2.0-cdh5.7.0

使用 thrift client with python 连接 hbase 报错:

  1. File "C:\Users\HP\env1\lib\site-packages\thrift\transport\TSocket.py", line 132, in read
  2. message='TSocket read 0 bytes')
  3. thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

二、查找原因
1)hbase连接代码

  1. from thrift.transport import TSocket
  2. from thrift.protocol import TBinaryProtocol
  3. from thrift.transport import TTransport
  4. transport = TTransport.TBufferedTransport(TSocket.TSocket(10.201.7.113, int(port)))
  5. protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)

2) hbase-site.xml 配置如下

  1. <property>
  2. <name>hbase.regionserver.thrift.framed</name>
  3. <value>true</value>
  4. </property>
  5. <property>
  6. <name>hbase.regionserver.thrift.compact</name>
  7. <value>true</value>
  8. </property>

3) thrift server日志如下:(/var/log/hbase/hbase-hbase-thrift-.log)

  1. INFO [main] mortbay.log: Started HttpServer$SelectChannelConnectorWithSafeStartup@0.0.0.0:9095
  2. DEBUG [main] thrift.ThriftServerRunner: Using compact protocol
  3. DEBUG [main] thrift.ThriftServerRunner: Using framed transport
  4. 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功能,即:

  1. <property>
  2. <name>hbase.regionserver.thrift.framed</name>
  3. <value>false</value>
  4. </property>
  5. <property>
  6. <name>hbase.regionserver.thrift.compact</name>
  7. <value>false</value>
  8. </property>

重启thrift 服务器: service hbase-thrift restart

方案二:修改客户端代码

  1. transport = TFramedTransport(TSocket('192.168.0.10', 9090))
  2. protocol = TCompactProtocol.TCompactProtocol(transport)
  3. client = Hbase.Client(protocol)
  4. transport.open()

发表评论

表情:
评论列表 (有 0 条评论,1162人围观)

还没有评论,来说两句吧...

相关阅读