doujia7094 2015-03-04 21:09
浏览 58

Hive Server 2的PHP thrift客户端挂起

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.

Below is the php code (domain name was edited for anonymity) of test.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:
<property><name>hive.server2.authentication</name><value>NOSASL</value></property>

Here is what strace shows (ip address was edited for anonymity):

$ 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

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
...
  • 写回答

1条回答 默认 最新

  • dqdjfb2325 2015-03-14 22:57
    关注

    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. Same was true for us. When we did "lsof - ", the fd was in state CLOSE_WAIT. (i.e. Thrift server was closing the connection)

    评论

报告相同问题?

悬赏问题

  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离