2

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

Community
  • 1
  • 1
Hafiz Muhammad Shafiq
  • 8,168
  • 12
  • 63
  • 121

2 Answers2

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
John Leach
  • 518
  • 1
  • 3
  • 9
1

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!!!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Farooque
  • 3,616
  • 2
  • 29
  • 41
  • If I modify table via hbase shell there is no problem. then why there is problem in java api – Hafiz Muhammad Shafiq Aug 12 '16 at 06:38
  • @Shafiq: when modify through hbase shell then also disable is required. Even when we truncate the table then also disable is required..I don't why in your case it is not required?? – Farooque Aug 12 '16 at 09:29