HBase version: 0.98.6
Thrift Version: 0.9.0
Use thrift client with Python to connect HBase error:
1 Traceback (most recent):2File"D:\workspace\Python\py\helloworld.py", line 27,inch<module>3tables =client.gettablenames ()4File"E:\mazhongsoft\python\lib\hbase\Hbase.py", line 788,inchGettablenames5 returnself.recv_gettablenames ()6File"E:\mazhongsoft\python\lib\hbase\Hbase.py", line 798,inchRecv_gettablenames7(fname, mtype, rseqid) =Self._iprot.readmessagebegin ()8File"E:\mazhongsoft\python\lib\thrift\protocol\TBinaryProtocol.py", line 126,inchReadmessagebegin9SZ =self.readi32 ()TenFile"E:\mazhongsoft\python\lib\thrift\protocol\TBinaryProtocol.py", Line 203,inchreadI32 OneBuff = Self.trans.readAll (4) AFile"E:\mazhongsoft\python\lib\thrift\transport\TTransport.py", line 58,inchReadAll -Chunk = Self.read (sz-Have ) -File"E:\mazhongsoft\python\lib\thrift\transport\TTransport.py", line 155,inchRead theSelf.__rbuf= Stringio (self.__trans. Read (max (SZ, self. Default_buffer ))) -File"E:\mazhongsoft\python\lib\thrift\transport\TSocket.py", line 94,inchRead - RaiseTtransportexception ('tsocket Read 0 bytes') -Thrift.transport.TTransport.TTransportException:None
To find the cause, the process is as follows:
1) Client code
Transport = Ttransport. Tbufferedtransport(Tsocket (' 192.168.0.10 ', 9090))2 protocol = tbinaryprotocol. Tbinaryprotocol(transport)3 client = hbase.client (protocol)4 transport.open ()
2) hbase-site.xml configuration as follows
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 logs are as follows: (/var/log/hbase/hbase-hbase-thrift-
1Wed Jan 14:54:43 CST starting thrift on 2Core file size (blocks,-c) 03Data seg Size (Kbytes,-d) Unlimited4Scheduling Priority (-e) 05File size (blocks,-f) Unlimited6Pending signals (-i) 1919567Max locked Memory (Kbytes,-l) Unlimited8Max memory Size (Kbytes,-m) Unlimited9Open files (-N) 32768TenPipe Size (bytes,-p) 8 OnePOSIX message queues (bytes,-Q) 819200 AReal-time Priority (-r) 0 -Stack size (Kbytes,-s) 10240 -CPU time (seconds,-t) unlimited theMAX User Processes (-u) 1024 -Virtual Memory (Kbytes,-v) Unlimited -File Locks (-x) Unlimited -INFO [main] util. Versioninfo:hbase 0.98.6-cdh5.3.0 +INFO [main] util. Versioninfo:subversion file:///data/jenkins/workspace/generic-package-rhel64-6-0/topdir/BUILD/hbase-0.98.6-cdh5.3.0-R Unknown -INFO [main] util. Versioninfo:compiled by Jenkins on Tue Dec 19:13:29 PST 2014 + INFO [main] thrift. Thriftserverrunner:using Default Thrift server type A INFO [main] thrift. Thriftserverrunner:using Thrift Server Type ThreadPool atINFO [main] impl. metricsconfig:loaded Properties fromhadoop-metrics2-hbase.properties -INFO [main] impl. metricssystemimpl:scheduled Snapshot period at 10second (s). - INFO [main] impl. Metricssystemimpl:hbase Metrics System started - INFO [main] mortbay.log:Logging to Org.slf4j.impl.Log4jLoggerAdapter (Org.mortbay.log) via Org.mortbay.log.Slf4jLog -INFO [main] http. httpserver:addedGlobalFilter' safety ' (class=org.apache.hadoop.http.httpserver$quotinginputfilter)-INFO [main] http. httpserver:added Filter Static_user_filter (class=org.apache.hadoop.http.lib.staticuserwebfilter$staticuserfilter ) to Context Thrift inINFO [main] http. httpserver:added Filter Static_user_filter (class=org.apache.hadoop.http.lib.staticuserwebfilter$staticuserfilter ) to context Static -INFO [main] http. Httpserver:jetty bound to Port 9095 toINFO [main] mortbay.log:jetty-6.1.26.cloudera.4 +INFO [main] mortbay.log:Started [email protected]:9095 - DEBUG [main] thrift. Thriftserverrunner: Using Compact Protocol the 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
It is known from the above red text , because the server side of the thrift and the client side of the protocol mismatch caused.
The solution has the following two:
Scenario One: Modify the Hbase-site.xml, disable the Tframedtransport and Tcompactprotocol functions, i.e.:
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>
Restart Thrift Server: Service hbase-thrift restart
Scenario Two: Modifying client code
1 transport = Tframedtransport (Tsocket ('192.168.0.10', 9090)) 2 protocol = Tcompactprotocol.tcompactprotocol (transport) 3 client = Hbase.client (protocol) 4 transport.open ()
If the error does not find Tframedtransport and Tcompactprotocol, check the/usr/lib/python2.6/site-packages/thrift directory for any protocol/ tcompactprotocol.py file, check the transport/ttransport.py file for any class Tframedtransport. If not, you can download the source package thrift-0.9.2.tar.gz in the Thrift official website, with the lib/py/src/covered/usr/lib/python2.6/site-packages/thrift/directory.
"HBase" uses thrift with Python to access hbase