I have written a simple java 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 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.