EDIT: This question and answer applies to anyone who is experiencing the exception stated in the subject line: TTransportException(type=4, message='TSocket read 0 bytes'); whether or not Cloudera and/or HappyBase is involved.
The root issue (as it turned out) stems from mismatching
protocoland/ortransportformats on theclient-sidewith what theserver-sideis implementing, and this can happen with any client/server paring. Mine just happened to be Cloudera and HappyBase, but yours needn't be and you can run into this same issue.
Has anyone recently tried using the happybase v1.1.0 (latest) Python package to interact with Hbase on Cloudera CDH v6.1.x?
I'm trying various options with it, but keep getting the exception:
thriftpy.transport.TTransportException:
TTransportException(type=4, message='TSocket read 0 bytes')
Here is how I start a session and submit a simple call to get a listing of tables (using Python v3.6.7:
import happybase
CDH6_HBASE_THRIFT_VER='0.92'
hbase_cnxn = happybase.Connection(
host='vps00', port=9090,
table_prefix=None,
compat=CDH6_HBASE_THRIFT_VER,
table_prefix_separator=b'_',
timeout=None,
autoconnect=True,
transport='buffered',
protocol='binary'
)
print('tables:', hbase_cnxn.tables()) # Exception happens here.
And here is how Cloudera CDH v6.1.x starts the Hbase Thrift server (truncated for brevity):
/usr/java/jdk1.8.0_141-cloudera/bin/java [... snip ... ] \
org.apache.hadoop.hbase.thrift.ThriftServer start \
--port 9090 -threadpool --bind 0.0.0.0 --framed --compact
I've tried several variations to options, but getting nowhere.
Has anyone ever got this to work?
EDIT:
I next compiled Hbase.thrift (from the Hbase source files -- same HBase version as used by CDH v6.1.x) and used the Python thrift bindings package (in other words, I removed happybase from the equation) and got the same exception.
(._.);
Thank you!
After a days worth of working on this, the answer to my question is the following:
Note that although this Q&A was framed in the context of
Cloudera, it turns out (as you'll see) that this wasThriftversions andThriftServer-Side configurations related, and so it applies toHortonworksandMapRusers, too.Explanation:
On
Cloudera CDH v6.1.x(and probably future versions, too) if you visit theHbase Thrift Server Configurationsection of its management U.I., you'll find -- among many other settings -- these:Notice that
compact protocolandframed transportare both enabled; so they correspondingly needed to be changed inhappybasefrom its defaults (which I show above).As mentioned in EDIT follow-up to my initial question, I also investigated a pure
Thrift(nonhappybase) solution. And with analogous changes to Python code for that case, I got that to work, too. Here is the code you should use for the pureThriftsolution (taking care to read my commented annotations below):I hope this spares people the pain I went through. =:)
CREDITS: