我正在尝试使用PHP的0.12 Thrift服务器连接到Hive Server 2,遵循标准示例,但每次我使用$ client-> execute()发送查询时,它都会挂起。
下面是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();
我认为这可能是由于Hive Server 2期望进行SASL身份验证,但strace显示它在身份验证后卡住了,甚至用以下方法设置hive-site.xml也不会改变挂起:
<property><name>hive.server2.authentication</name><value>NOSASL</value></property>
以下是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
过了一会儿(参见上面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
...
答案 0 :(得分:0)
我们遇到了同样的问题,我找到了这个补丁,Thrift中的问题仍然存在: https://issues.apache.org/jira/browse/THRIFT-2611 看起来在你的情况下revents = POLLIN,与上面的问题不同。对我们来说也是如此。当我们做了&#34; lsof - &#34;时,fd处于状态CLOSE_WAIT。 (即Thrift服务器正在关闭连接)