简体   繁体   中英

Hbase Java API TableNotDisabledException

I have configured Apache hbase 0.94.14 on my local system. I have to communicate with hbase via java API. I have written simple code to add a new column family in existing hbase table.

Code for Java class

         // Instantiating configuration class.
        Configuration conf = HBaseConfiguration.create();
        // Instantiating HBaseAdmin class.
        HBaseAdmin admin = new HBaseAdmin(conf);

        // Instantiating columnDescriptor class
        HColumnDescriptor columnDescriptor =new
        HColumnDescriptor("contactDetails");
        // Adding column family
        admin.addColumn("local_webpage", columnDescriptor);
        System.out.println("column added");

When I run this code, following exception occured.

16/08/11 14:07:37 INFO zookeeper.ClientCnxn: EventThread shut down
Exception in thread "main" org.apache.hadoop.hbase.TableNotDisabledException: org.apache.hadoop.hbase.TableNotDisabledException: local_webpage
    at org.apache.hadoop.hbase.master.HMaster.checkTableModifiable(HMaster.java:1525)
    at org.apache.hadoop.hbase.master.handler.TableEventHandler.<init>(TableEventHandler.java:72)
    at org.apache.hadoop.hbase.master.handler.TableAddFamilyHandler.<init>(TableAddFamilyHandler.java:41)
    at org.apache.hadoop.hbase.master.HMaster.addColumn(HMaster.java:1402)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Server.call(WritableRpcEngine.java:323)
    at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:1426)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.apache.hadoop.hbase.RemoteExceptionHandler.decodeRemoteException(RemoteExceptionHandler.java:96)
    at org.apache.hadoop.hbase.client.HBaseAdmin.addColumn(HBaseAdmin.java:1071)
    at org.apache.hadoop.hbase.client.HBaseAdmin.addColumn(HBaseAdmin.java:1054)
    at hbaseclient.HbaseClient.main(HbaseClient.java:44)
/home/user/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1

If I add column family via hbase shell, no problem occur. Where is the problem. Table is being created via Apache Nutch 2.3.1

You have to disable the table before you can add a family to it.

HBaseAdmin#disableTable()...

I think that is your only issue to get around the exception.

Since you are modifying the table, first you disable the table then modify the table.

The new code sample may be as below:

// Instantiating configuration class.
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class.
HBaseAdmin admin = new HBaseAdmin(conf);
// Disabling the table 
admin.disableTable("local_webpage");
// Instantiating columnDescriptor class with "contactDetails" as column family name
HColumnDescriptor columnDescriptor = new HColumnDescriptor("contactDetails");
// Adding column family
admin.addColumnFamily("local_webpage", columnDescriptor);
System.out.println("column family added");

I hope this help you!!!

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