简体   繁体   中英

Hbase Java API - createTable Method works, but doesnt finish

I am currently trying to use the Java API to connect to hbase and create a new table. It does seem to work, but the admin.createTable() Method does not finish. So "Done!" is never printed, and the programm never ends. Please see the code below.

        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "xxx.xxx.xxx.xxx");
        config.set("hbase.zookeeper.property.clientport", "2181");

        String tableName = "actors";
        Connection connection;
        try {
            connection = ConnectionFactory.createConnection(config);
            Admin admin = connection.getAdmin();
            Table table = connection.getTable(TableName.valueOf(tableName));
            HTableDescriptor htable = new HTableDescriptor(TableName.valueOf(tableName)); 
            htable.addFamily( new HColumnDescriptor("movies"));
            System.out.println( "Creating Table..." );
            admin.createTable( htable );
            System.out.println("Done!");
            table.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

No exception is thrown. If I open a hbase shell, the table actors with column family movies was created. I am running out of ideas here of what I could be doing wrong.

To Identify the exact cause do the following.

  • Enable debug logs in log4j.properties where this program is running.

  • Include this line inside your try block

org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(conf);

This will identify if there is any preliminary issues connecting to hbase and throw errors if any.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM