分享

java连接Hbase时程序一直堵塞

acme615 发表于 2016-2-3 10:06:53 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 1 16790
[mw_shl_code=java,true]                Configuration HBASE_CONFIG = new Configuration();
                HBASE_CONFIG.set("hbase.master", "192.168.3.66:60000");
                HBASE_CONFIG.set("hbase.zookeeper.quorum", "192.168.3.66,192.168.3.67");
                HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
                Configuration conf = null;
                conf = HBaseConfiguration.create(HBASE_CONFIG);
               
                Connection connection = ConnectionFactory.createConnection(conf);
       
                Table table = connection.getTable(TableName.valueOf("t"));
               
                Get g = new Get(Bytes.toBytes("lishi"));
                g.addFamily(Bytes.toBytes("cf:age"));
               
                if(table.exists(g)){
                        System.out.println("exist");
                }else
                        System.out.println("none");[/mw_shl_code]

打印出来的日志如下:
[mw_shl_code=java,true]2016-02-03 09:35:09,024 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=192.168.3.66:2181,192.168.3.67:2181 sessionTimeout=90000 watcher=hconnection-0x1b1d8960x0, quorum=192.168.3.66:2181,192.168.3.67:2181, baseZNode=/hbase
2016-02-03 09:35:09,274 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(975)) - Opening socket connection to server 192.168.3.67/192.168.3.67:2181. Will not attempt to authenticate using SASL (unknown error)
2016-02-03 09:35:09,274 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(852)) - Socket connection established to 192.168.3.67/192.168.3.67:2181, initiating session
2016-02-03 09:35:09,289 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1235)) - Session establishment complete on server 192.168.3.67/192.168.3.67:2181, sessionid = 0x152a0c002ff0013, negotiated timeout = 90000[/mw_shl_code]

在Hbase服务器上看到已经建立的2181的端口连接,程序BUG追踪到table.exists时就停住了,一直在等待,请各位大神解惑

已有(1)人评论

跳转到指定楼层
easthome001 发表于 2016-2-3 12:26:30
package www.aboutyun.com.hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.util.Bytes;

public class OperateTable {
         public static void main(String[] args) throws IOException {
         
         Configuration conf = HBaseConfiguration.create();
         conf.set("hbase.zookeeper.quorum", "master");//使用eclipse时必须添加这个,否则无法定位
         conf.set("hbase.zookeeper.property.clientPort", "2181");
         HBaseAdmin admin = new HBaseAdmin(conf);// 新建一个数据库管理员//新api
         HTableDescriptor desc=new HTableDescriptor(TableName.valueOf("blog"));
         //HTableDescriptor desc = new HTableDescriptor("blog");
         desc.addFamily(new HColumnDescriptor("article"));
         desc.addFamily(new HColumnDescriptor("author"));
         admin.createTable(desc );
         admin.close();
         //admin.disableTable("blog");
         //admin.deleteTable("blog");
         //assertThat(admin.tableExists("blog"),is(false));
   }
}

按照上面方式
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条