无法使用java创建hbase [英] Not able to create hbase using java

查看:185
本文介绍了无法使用java创建hbase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的 java 的代码在hbase中创建一个表,但不知何故它不工作。我检查了所有服务都正常运行,即 HMaster Regionserver Zookeeper 。下面是我写的代码

  import java.io.IOException; 
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class CreateSchema
{
public static void main(String [] args)throws IOException
{

try
{
HBaseConfiguration conf = new HBaseConfiguration(new Configuration());
HBaseAdmin hbase = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor(sample);
HColumnDescriptor meta = new HColumnDescriptor(samplecolumn1.getBytes());
HColumnDescriptor prefix = new HColumnDescriptor(samplecolumn2.getBytes());
desc.addFamily(meta);
desc.addFamily(前缀);
System.out.println(创建表);
hbase.createTable(desc);
System.out.println(完成);

catch(Exception e)
{
System.out.println(Error Ocuured);
}

}
}

这里是一个zookeeper日志。


2015-01-15 07:46:01,594 - INFO
[NIOServerCxn.Factory:0.0.0.0 /0.0.0.0:2181:NIOServer``CnxnFactory@197]
- 从/127.0.0.1:60599接受套接字连接2015-01-15 07:46:01,595 - WARN
[NIOServerCxn.Factory: 0.0.0.0/0.0.0.0:2181:ZooKeeperServer@822] -
来自旧客户端的连接请求/127.0.0.1:60599;如果服务器处于ro模式,将丢弃
2015-01-15 07:46:01,595 - INFO
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer @ 868] -
客户端尝试在/127.0.0.1:60599建立新会话
2015-01-15 07:46:01,619 - INFO [SyncThread:0:ZooKeeperServer @ 617] -
建立会话0x14aec781bb9000b协商超时40000
给客户端/127.0.0.1:60599 2015-01-15 07:46:37,151 - INFO
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory @ 197] -
从/10.0.2.15:58102接受套接字连接2015-01-15
07:46:37,152 - WARN
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:捕获
结束流异常EndOfStreamException:无法从客户端sessionid 0x0读取
附加数据,可能客户端已在org.apache.zookeeper中关闭了
套接字
。 server.NIOServerCnxn.doIO(NIOServerCnxn.java:228)
位于org.apache.zookeeper.server.NIOServerCnxnFac tory.run(NIOServerCnxnFactory.java:208)
at java.lang.Thread.run(Thread.java:745)2015-01-15 07:46:37,153 - INFO
[NIOServerCxn.Factory: 0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1007] -
客户端关闭套接字连接/10.0.2.15:58102(没有为客户端建立会话

在运行Hbase java程序后,没有任何反应。

  java CreateSchema 

创建表

请让我知道可能是什么问题。

解决方案

这可能发生的原因之一是您的 hbase-site.xml 是在类路径中不可用。



运行时:

  HBaseConfiguration conf = new HBaseConfiguration(new组态()); 

根据hbase-site.xml创建HbaseConfiguration。



PS:我在日食中运行你的代码,它运行良好。表格示例创建时没有任何错误。

I have written a simple code for creating a table in hbase but somehow it is not working. I checked that all services are working fie i.e. HMaster, Regionserver and Zookeeper. Below is a code that i wrote

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;
public class CreateSchema
{
public static void main(String[] args) throws IOException
{

try
{
   HBaseConfiguration conf = new HBaseConfiguration(new Configuration());
   HBaseAdmin hbase = new HBaseAdmin(conf);
   HTableDescriptor desc = new HTableDescriptor("sample");
   HColumnDescriptor meta = new HColumnDescriptor("samplecolumn1".getBytes());
   HColumnDescriptor prefix = new HColumnDescriptor("samplecolumn2".getBytes());
   desc.addFamily(meta);
   desc.addFamily(prefix);
   System.out.println("Creating table");
   hbase.createTable(desc);
   System.out.println("Done");
    }
    catch(Exception e)
    {
    System.out.println("Error Ocuured");
    }

     }
    }

Here is a zookeeper log.

2015-01-15 07:46:01,594 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServer``CnxnFactory@197] - Accepted socket connection from /127.0.0.1:60599 2015-01-15 07:46:01,595 - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@822] - Connection request from old client /127.0.0.1:60599; will be dropped if server is in r-o mode 2015-01-15 07:46:01,595 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@868] - Client attempting to establish new session at /127.0.0.1:60599 2015-01-15 07:46:01,619 - INFO [SyncThread:0:ZooKeeperServer@617] - Established session 0x14aec781bb9000b with negotiated timeout 40000 for client /127.0.0.1:60599 2015-01-15 07:46:37,151 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /10.0.2.15:58102 2015-01-15 07:46:37,152 - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@357] - caught end of stream exception EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has closed socket at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228) at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208) at java.lang.Thread.run(Thread.java:745) 2015-01-15 07:46:37,153 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1007] - Closed socket connection for client /10.0.2.15:58102 (no session established for client)

After running Hbase java programm nothing happens.

java CreateSchema

Creating table

Please let me know what could be the issue.

解决方案

One of the reason this might occur is your hbase-site.xml is not available in the classpath.

When you run:

HBaseConfiguration conf = new HBaseConfiguration(new Configuration());

HbaseConfiguration based the hbase-site.xml is created.

PS: I ran your code as such in my eclipse and it worked fine. The table sample got created without any error.

这篇关于无法使用java创建hbase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆