26
26
run_coro ,
27
27
)
28
28
29
+ try :
30
+ from thriftpy2_httpx_client import make_aio_client as make_http_client
31
+ except ImportError :
32
+ async def make_http_client (* _ , ** __ ):
33
+ raise RuntimeError ("thriftpy2_httpx_client is required to"
34
+ " use the HTTP client protocol." )
35
+
29
36
logger = logging .getLogger (__name__ )
30
37
31
38
COMPAT_MODES = ('0.90' , '0.92' , '0.94' , '0.96' , '0.98' )
35
42
DEFAULT_COMPAT = os .environ .get ('AIOHAPPYBASE_COMPAT' , '0.98' )
36
43
DEFAULT_TRANSPORT = os .environ .get ('AIOHAPPYBASE_TRANSPORT' , 'buffered' )
37
44
DEFAULT_PROTOCOL = os .environ .get ('AIOHAPPYBASE_PROTOCOL' , 'binary' )
45
+ DEFAULT_CLIENT = os .environ .get ('AIOHAPPYBASE_CLIENT' , 'socket' )
38
46
39
47
40
48
class Connection :
@@ -88,6 +96,17 @@ class Connection:
88
96
process as well. ``TBinaryProtocol`` is the default protocol that
89
97
AIOHappyBase uses.
90
98
99
+ The optional `client` argument specifies the type of Thrift client
100
+ to use. Supported values for this argument are ``socket``
101
+ (the default) and ``http``. Make sure to choose the right one,
102
+ since otherwise you might see non-obvious connection errors or
103
+ program hangs when making a connection. To check which client
104
+ you should use, refer to the ``hbase.regionserver.thrift.http``
105
+ setting. If it is ``true`` use ``http``, otherwise use ``socket``.
106
+
107
+ .. versionadded:: v1.4.0
108
+ `client` argument
109
+
91
110
.. versionadded:: 0.9
92
111
`protocol` argument
93
112
@@ -109,7 +128,10 @@ class Connection:
109
128
binary = TAsyncBinaryProtocolFactory (decode_response = False ),
110
129
compact = TAsyncCompactProtocolFactory (decode_response = False ),
111
130
)
112
- THRIFT_CLIENT_FACTORY = staticmethod (make_client )
131
+ THRIFT_CLIENTS = dict (
132
+ socket = make_client ,
133
+ http = make_http_client ,
134
+ )
113
135
114
136
def __init__ (self ,
115
137
host : str = DEFAULT_HOST ,
@@ -121,6 +143,7 @@ def __init__(self,
121
143
compat : str = DEFAULT_COMPAT ,
122
144
transport : str = DEFAULT_TRANSPORT ,
123
145
protocol : str = DEFAULT_PROTOCOL ,
146
+ client : str = DEFAULT_CLIENT ,
124
147
** client_kwargs : Any ):
125
148
"""
126
149
:param host: The host to connect to
@@ -132,6 +155,7 @@ def __init__(self,
132
155
:param compat: Compatibility mode (optional)
133
156
:param transport: Thrift transport mode (optional)
134
157
:param protocol: Thrift protocol mode (optional)
158
+ :param client: Thrift client mode (optional)
135
159
:param client_kwargs:
136
160
Extra keyword arguments for `make_client()`. See the ThriftPy2
137
161
documentation for more information.
@@ -149,6 +173,7 @@ def __init__(self,
149
173
compat = (compat , COMPAT_MODES ),
150
174
transport = (transport , self .THRIFT_TRANSPORTS ),
151
175
protocol = (protocol , self .THRIFT_PROTOCOLS ),
176
+ client = (client , self .THRIFT_CLIENTS ),
152
177
)
153
178
154
179
# Allow host and port to be None, which may be easier for
@@ -162,6 +187,7 @@ def __init__(self,
162
187
163
188
self ._transport_factory = self .THRIFT_TRANSPORTS [transport ]
164
189
self ._protocol_factory = self .THRIFT_PROTOCOLS [protocol ]
190
+ self ._client_factory = self .THRIFT_CLIENTS [client ]
165
191
166
192
self .client_kwargs = {
167
193
'service' : Hbase ,
@@ -196,7 +222,7 @@ async def open(self) -> None:
196
222
return # _refresh_thrift_client opened the transport
197
223
198
224
logger .debug (f"Opening Thrift transport to { self .host } :{ self .port } " )
199
- self .client = await self .THRIFT_CLIENT_FACTORY (** self .client_kwargs )
225
+ self .client = await self ._client_factory (** self .client_kwargs )
200
226
201
227
def close (self ) -> None :
202
228
"""
0 commit comments