简体   繁体   English

Hive Server 2的PHP thrift客户端挂起

[英]PHP thrift client for Hive Server 2 hangs

I am trying to connect to Hive Server 2 with 0.12 Thrift server from PHP following the standard example, but every time I send a query with $client->execute() it just hangs. 我试图使用PHP的0.12 Thrift服务器连接到Hive Server 2,遵循标准示例,但每次我使用$ client-> execute()发送查询时它都会挂起。

Below is the php code (domain name was edited for anonymity) of test.php: 以下是test.php的php代码(域名是为匿名编辑的):

<?php
$GLOBALS['THRIFT_ROOT'] = '/hadoop/libraries/php-thrift-sql/php';
require_once $GLOBALS['THRIFT_ROOT'] . '/TException.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/fb303/FacebookService.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_metastore/metastore/ThriftHiveMetastore.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/../src/Thrift/Type/TType.php';
require_once dirname(__FILE__) . '/ThriftHiveClientEx.php';

$transport = new TSocket('xxxx.com', 10000);
$transport->setSendTimeout(600 * 1000);
$transport->setRecvTimeout(600 * 1000);
$client = new ThriftHiveClientEx(new TBinaryProtocol($transport));
$client->open();
$client->execute('SHOW DATABASES');
var_dump($client->fetchAll());
$client->close();

I thought that it might be due to Hive Server 2 expecting SASL authentication, but strace shows that it get stuck after the authentication and even setting the hive-site.xml with the following doesn't change the hanging: 我认为这可能是由于Hive Server 2期望进行SASL身份验证,但是strace显示它在身份验证后卡住了,甚至用以下方法设置hive-site.xml也不会改变挂起:
<property><name>hive.server2.authentication</name><value>NOSASL</value></property>

Here is what strace shows (ip address was edited for anonymity): 这是strace显示的内容(ip地址是为匿名编辑的):

$ strace php test.php
...
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3
fcntl(3, F_GETFD)                       = 0x1 (flags FD_CLOEXEC)
fstat(3, {st_mode=S_IFREG|0644, st_size=254, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b9a30d0d000
read(3, "127.0.0.1   localhost localhost."..., 4096) = 254
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x2b9a30d0d000, 4096)            = 0
gettimeofday({1425502381, 530272}, NULL) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl(3, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
connect(3, {sa_family=AF_INET, sin_port=htons(10000), sin_addr=inet_addr("10.xx.xx.xx")}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 600000) = 1 ([{fd=3, revents=POLLOUT}])
getsockopt(3, SOL_SOCKET, SO_ERROR, [247701518558429184], [4]) = 0
fcntl(3, F_SETFL, O_RDWR)               = 0
sendto(3, "\200\1\0\1", 4, MSG_DONTWAIT, NULL, 0) = 4
sendto(3, "\0\0\0\7", 4, MSG_DONTWAIT, NULL, 0) = 4
sendto(3, "execute", 7, MSG_DONTWAIT, NULL, 0) = 7
sendto(3, "\0\0\0\0", 4, MSG_DONTWAIT, NULL, 0) = 4
sendto(3, "\v", 1, MSG_DONTWAIT, NULL, 0) = 1
sendto(3, "\0\1", 2, MSG_DONTWAIT, NULL, 0) = 2
sendto(3, "\0\0\0\16", 4, MSG_DONTWAIT, NULL, 0) = 4
sendto(3, "SHOW DATABASES", 14, MSG_DONTWAIT, NULL, 0) = 14
sendto(3, "\0", 1, MSG_DONTWAIT, NULL, 0) = 1
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 600000) = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\4\0\0\0\23Invalid status -128", 8192, MSG_DONTWAIT, NULL, NULL) = 24
mmap(NULL, 67375104, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b9a314e0000
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 600000 

and after a while (see receive timeout settings in test.php above) it times out with 过了一会儿(参见上面test.php中的接收超时设置),它超时了

poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 600000) = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "", 8192, MSG_DONTWAIT, NULL, NULL) = 0
munmap(0x2af661ac2000, 266240)          = 0
munmap(0x2af661b44000, 266240)          = 0
close(2)                                = 0
...

We had the same problem, I found this patch, with the issue in Thrift still open: https://issues.apache.org/jira/browse/THRIFT-2611 Looks like in your case revents=POLLIN, unlike in the issue above. 我们遇到了同样的问题,我找到了这个补丁,Thrift中的问题仍然存在: https//issues.apache.org/jira/browse/THRIFT-2611看起来像你的情况revents = POLLIN,与上面的问题不同。 Same was true for us. 对我们来说也是如此。 When we did "lsof - ", the fd was in state CLOSE_WAIT. 当我们做“lsof - ”时,fd处于CLOSE_WAIT状态。 (ie Thrift server was closing the connection) (即Thrift服务器正在关闭连接)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM