HBase: Thrift写数据报错——socket.error: [Errno 32] Broken pip

版权声明:作者原创,转载请附上文章链接。 https://blog.csdn.net/qq_36330643/article/details/83106759

博主用的是python来读写hbase

需要安装 pip install thrift 和 pip install hbase-thrift

hbase客户端创建:

from thrift import Thrift
from thrift.transport import TSocket, TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
 
#server端地址和端口,web是HMaster也就是thriftServer主机名,9090是thriftServer默认端口
transport = TSocket.TSocket('hadoop4’, 9090)
#可以设置超时
transport.setTimeout(5000)
#设置传输方式(TFramedTransport或TBufferedTransport)
trans = TTransport.TBufferedTransport(transport)
#设置传输协议
protocol = TBinaryProtocol.TBinaryProtocol(trans)
#确定客户端
client = Hbase.Client(protocol)
#打开连接
transport.open()  

如果,在读写hbase过程中报错:socket.error: [Errno 32] Broken pip,原因大致是因为,数据还没有读写进去,socket已经关闭了,解决办法就是在创建客户端设置超时时间。

#可以设置超时
transport.setTimeout(5000)

或者直接在配置文件conf/hbase-site.xml中添加如下配置(每个节点都添加):

<property>
         <name>hbase.thrift.server.socket.read.timeout</name>
         <value>6000000</value>
         <description>eg:milisecond</description>
</property>

即设置超时时间为60s。

猜你喜欢

转载自blog.csdn.net/qq_36330643/article/details/83106759