Hbase java创建表时,调试一直卡住

时间:2025-03-23 09:43:55

java代码


HbaseTest

public class HbaseTest {

    /**
     *      配置
     * */
    static Configuration conf = null;
    static{
        conf = ();
    }


    /**
     *      create a table
     * @throws IOException 
     * @throws ZooKeeperConnectionException 
     * @throws MasterNotRunningException 
     * */
    public void createTable(String tableName,String [] familys) {


        /**
         *   0.9X edition 
         * */
//      HBaseAdmin admin = new HBaseAdmin(conf);
//      HTableDescriptor descriptor = new HTableDescriptor();
        /**
         *       edition
         * */
        Connection connection;
        Admin admin = null;
        try {
            connection = (conf);
            admin = ();
        } catch (IOException e) {
            ();

        }


        /**
         *   新的写法
         * */
        HTableDescriptor table = new HTableDescriptor((tableName));
        for(String family:familys){
            HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(family);
            (hColumnDescriptor);
        }

        try {
            (table);

            ("table is already created!\n");
            /**
             *      关闭admin
             * */
            ();
        } catch (IOException e) {
            ();
        }


    }
}

TestCase

public class TestCase {

    HbaseTest hbase = new HbaseTest();

    @Test
    public void testCreateTable() throws MasterNotRunningException, ZooKeeperConnectionException, IOException{

        String [] fs = {"personal","public","name"};
        ("tttzz", fs);

    }
}

问题

     在执行的时候一直卡在了`(table)`然后去查找资料,看到了一个解决,就是HDFS的`safemode`开着,但是查看自己的安全模式确实关闭的。
hadoop dfsadmin -safemode get

显示Safe mode is OFF然后懵逼了。


解决

然后突然想到我的配置文件里面用的是hostname而不是ip地址,所以执行的时候无法确定ip地址,需要改host文件或者改