HBase multithreading to build htable problems

Source: Internet
Author: User
Tags commit flush thread

HBase plugin, which recently wrote Wormhole, needs to implement HBase reader and hbase writer respectively, and the error will be the following when testing:

2013-07-08 09:30:02,568 [pool-2-thread-1] org.apache.hadoop.hbase.client.hconnectionmanager$ Hconnectionimplementation.processbatchcallback (hconnectionmanager.java:1631) WARN client. Hconnectionmanager$hconnectionimplementation-failed all from Region=t1,
1373246892580.877bb26da1e4aed541915870fa924224, Hostname=test89.hadoop, port=60020. Java.util.concurrent.ExecutionException:java.io.IOException:Call to test89.hadoop/10.1.77.89:60020 failed in local exception:java.io.InterruptedIOException:Interruped while waiting to IO on channel java.nio.channels.socketchannel[ Connected local=/10.1.77.84:51032 remote=test89.hadoop/10.1.77.89:60020].  
    59999 Millis Timeout left. At Java.util.concurrent.futuretask$sync.innerget (futuretask.java:222) at Java.util.concurrent.FutureTask.get ( futuretask.java:83) at org.apache.hadoop.hbase.client.hconnectionmanager$ Hconnectionimplementation.processbatchcallback (hconnectionmanager.java:1601) at Org.apache.hadoop.hbase.client.HConneCtionmanager$hconnectionimplementation.processbatch (hconnectionmanager.java:1453) at Org.apache.hadoop.hbase.client.HTable.flushCommits (htable.java:936) at Org.apache.hadoop.hbase.client.HTable.put (htable.java:783) at the Com.dp.nebula.wormhole.plugins.common.HBaseClient.flush (hbaseclient.java:121) at COM.DP.N Ebula.wormhole.plugins.writer.hbasewriter.HBaseWriter.commit (hbasewriter.java:112) at Com.dp.nebula.wormhole.engine.core.WriterThread.call (writerthread.java:52) at Com.dp.nebula.wormhole.engine.core.WriterThread.call (writerthread.java:1) at java.util.concurrent.futuretask$ Sync.innerrun (futuretask.java:303) at Java.util.concurrent.FutureTask.run (futuretask.java:138) at java.util.co Ncurrent. Threadpoolexecutor$worker.runtask (threadpoolexecutor.java:895) at java.util.concurrent.threadpoolexecutor$ Worker.run (threadpoolexecutor.java:918) at Java.lang.Thread.run (thread.java:662) caused by:java.io.ioexception:c All to Test89. hadoop/10.1.77.89:60020 failed on the local exception:java.io.InterruptedIOException:Interruped while waiting for IO on cha Nnel java.nio.channels.socketchannel[connected local=/10.1.77.84:51032 remote=test89.hadoop/10.1.77.89:60020].  
    59999 Millis Timeout left. At Org.apache.hadoop.hbase.ipc.HBaseClient.wrapException (hbaseclient.java:1030) at Org.apache.hadoop.hbase.ipc.HBaseClient.call (hbaseclient.java:999) at Org.apache.hadoop.hbase.ipc.securerpcengine$invoker.invoke (securerpcengine.java:104) at com.sun.proxy.$ Proxy5.multi (Unknown Source) at org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation$3$1. Call (hconnectionmanager.java:1430) at org.apache.hadoop.hbase.client.hconnectionmanager$ Hconnectionimplementation$3$1.call (hconnectionmanager.java:1428) at Org.apache.hadoop.hbase.client.ServerCallable.withoutRetries (servercallable.java:215) at org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation$3.caLL (hconnectionmanager.java:1437) at org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation$ 3.call (hconnectionmanager.java:1425) ... 5 more caused by:java.io.InterruptedIOException:Interruped while waiting for IO on channel Java.nio.channels.SocketCha Nnel[connected local=/10.1.77.84:51032 remote=test89.hadoop/10.1.77.89:60020].  
59999 Millis Timeout left. 2013-07-08 09:30:03,579 [pool-2-thread-6] Com.dp.nebula.wormhole.engine.core.WriterThread.call (Writerthread.java :) ERROR core.  
Writerthread-exception occurs in writer thread! Com.dp.nebula.wormhole.common.WormholeException:java.io.IOException: <span style= "color: #ff0000;" >org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation@b7c96a9 closed</span> at Com.dp.nebula.wormhole.plugins.writer.hbasewriter.HBaseWriter.commit (hbasewriter.java:114) at Com.dp.nebula.wormhole.engine.core.WriterThread.call (writerthread.java:52) at Com.dp.nebula.wormhole.Engine.core.WriterThread.call (writerthread.java:1) at Java.util.concurrent.futuretask$sync.innerrun ( futuretask.java:303) at Java.util.concurrent.FutureTask.run (futuretask.java:138) at Java.util.concurrent.Threa Dpoolexecutor$worker.runtask (threadpoolexecutor.java:895) at Java.util.concurrent.threadpoolexecutor$worker.run ( threadpoolexecutor.java:918) at Java.lang.Thread.run (thread.java:662) caused by:java.io.ioexception:org.apache.h ADOOP.HBASE.CLIENT.HCONNECTIONMANAGER$HCONNECTIONIMPLEMENTATION@B7C96A9 closed at Org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation.locateregion ( hconnectionmanager.java:877) at org.apache.hadoop.hbase.client.hconnectionmanager$ Hconnectionimplementation.locateregion (hconnectionmanager.java:857) at Org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation.processbatchcallback ( hconnectionmanager.java:1568) at Org.apache.hadoop.hbase.client.hconnectionmanager$hconNectionimplementation.processbatch (hconnectionmanager.java:1453) at Org.apache.hadoop.hbase.client.HTable.flushCommits (htable.java:936) at Org.apache.hadoop.hbase.client.HTable.put (htable.java:783) at the Com.dp.nebula.wormhole.plugins.common.HBaseClient.flush (hbaseclient.java:121) at COM.DP.N Ebula.wormhole.plugins.writer.hbasewriter.HBaseWriter.commit (hbasewriter.java:112) ... 7 more

The

Wormhole reader and writer each have a threadpoolexecutor, and the error is the flush phase of the writer end, the last batch insert operation. Because my reader is every thread a htable instance no problem, and writer is sharing a singleton hbaseclient, Then use threadlocal to ensure that each thread has a local htable object, there may be errors, the simplest way is to put the writer end without Singleton hbaseclient, the problem should be solved, but did not understand root cause, It's not cool.
then read the source code of Htable and Hadmin to have a clue

Public htable (Configuration conf, final byte [] tablename)  
  throws IOException {this.tablename  
    = tablename;  
    This.cleanuppoolonclose = This.cleanupconnectiononclose = true;  
    if (conf = = null) {  
      this.connection = null;  
      return;  
    }  
    This.connection = hconnectionmanager.getconnection (conf);  
    this.configuration = conf;  
    int maxthreads = Conf.getint ("Hbase.htable.threads.max", integer.max_value);  
    if (MaxThreads = = 0) {  
      maxthreads = 1;//Is there a better default?  
    }  
    Long KeepAliveTime = Conf.getlong ("Hbase.htable.threads.keepalivetime");  
    ((Threadpoolexecutor) this.pool). Allowcorethreadtimeout (true);  
    This.finishsetup ();  
  }

Each htable instance has a Hconnection object that is responsible for establishing links with zookeeper and hbase cluster, such as the cache of cluster located in Region,locations, When region is moved, it is managed by Hconnectionmanager

public static Hconnection getconnection (Configuration conf)  
throws Zookeeperconnectionexception {  
  Hconnectionkey Connectionkey = new Hconnectionkey (conf);  
  Synchronized (hbase_instances) {  
    hconnectionimplementation connection = Hbase_instances.get (Connectionkey);  
    if (connection = = null) {  
      connection = new Hconnectionimplementation (conf, true);  
      Hbase_instances.put (Connectionkey, connection);  
    }  
    Connection.inccount ();  
    return connection  
  }  
}

The static variables of the LRU MAP => hbase_instances inside the Hconnectionmanager are cache,key as Hconnectionkey and contain the username and specified properties ( From the sent in the Conf extract), value is hconnection specific implementation hconnectionimplementation, because the incoming conf are the same, so all point to the same hconnectionimplementation, Finally, Connection.inccount () is invoked to add the client reference count to 1

public void Close () throws IOException {  
  if (this.closed) {return  
    ;  
  }  
  Flushcommits ();  
  if (cleanuppoolonclose) {  
    this.pool.shutdown ();  
  }  
  if (cleanupconnectiononclose) {  
    if (this.connection!= null) {  
      this.connection.close ();  
    }  
  }  
  This.closed = true;  
}

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/database/extra/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.