HBase multithreading to build htable problems

Source: Internet
Author: User
Keywords Java manager nbsp; null

Recently in writing wormhole HBase plugin, you need to implement HBase reader and hbase writer respectively, when the test will be the following error:

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= 60020java.util.concurrent.executionexception:java.io.ioexception:call to test89.hadoop/10.1.77.89:60020 failed on Local exception:java.io.InterruptedIOException:Interruped while waiting for 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 Com.dp.nebula.wormhole.plugins.common.HBaseClient.flush (hbaseclient.java:121) at Com.dp.nebula.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.concurrent.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:Call to test89.hadoop/10.1.77.89:60020 failed on the local exception: java.io.InterruptedIOException:Interruped WHile waiting for 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 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 morecaused by: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.2013-07-08 09:30:03,579 [pool-2-thread-6] Com.dp.nebula.wormhole.engine.core.WriterThread.call (writerthread.java:56) ERROR core. Writerthread-exception occurs in writer thread!com.dp.nebula.wormhole.common.wormholeexception:java.io.ioexception : Org.apache.hadoop.hbase.client.hconnectionmanager$hconnectionimplementation@b7c96a9 closed 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.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: ORG.APACHE.HADOOP.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 Com.dp.nebula.wormhole.plugins.common.HBaseClient.flush (hbaseclient.java:121) at COM.Dp.nebula.wormhole.plugins.writer.hbasewriter.HBaseWriter.commit (hbasewriter.java:112) ... 7 more

Wormhole reader and writer will start a threadpoolexecutor, error is at the writer end of the flush phase, that is, 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 incorporated, It's not good.
Then I saw the source code of htable and Hadmin.

Public htable (revisit 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 decoupled default?} Long KeepAliveTime = Conf.getlong (" Hbase.htable.threads.keepalivetime ", 60); ((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 (revisit 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, The Last Call Connection.inccount () adds 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; }

When Htable close, the list<put> is first flushcommits, and the connection method of Writerbuffer is processed at once, and then into close Connection logic, which is also reference count, minus 1, and when it is 0 or expired connection, the close connection is executed and removed from the hbase_instances.

Close step:

1. Close Hmasterinterface

2. Close a string of hregioninterface

3. Close Zookeeper Watcher

Hconnectionimplementation connection = hbase_instances. Get (Connectionkey); if (connection!= null) {Connection.deccount (); if (Connection.iszeroreference () | | staleconnection) {HBASE_ Instances.remove (Connectionkey); Connection.close (Stopproxy); else if (stopproxy) {connection.stopproxyonclose (stopproxy);}} else {log.error ("Connection not found in the list, can ' t delete it" + "(Connection key=" +connectionkey+ "). May is the key was flushes? ");}


Hbaseadmin interior is also the same, is also reference a hconnection, can think and htable is shared hconnection

To analyze the error message "java.io.ioexception:org.apache.hadoop.hbase.client.hconnectionmanager$ HCONNECTIONIMPLEMENTATION@B7C96A9 closed ", should be the client reference count number of questions, and sure enough in my hbaseclient code in the initialization link will be a new singleton Hbaseclient, Inside New a hbaseadmin (thread sharing), at each thread startup will be a new Threadloca htable object

Private Htable gethtable () throws IOException {htable htable = Threadlocalhtable.get (); if (htable = null) {htable = new Htable (conf, tablename); Htable.setautoflush (AutoFlush); Htable.setwritebuffersize (writebuffersize); Threadlocalhtable.set (htable); return htable; }

But my close method has a problem with the hbaseadmin close a lot of times (each thread close once)

public synchronized void Close () throws IOException {htable table = Threadlocalhtable.get (); if (table!= null) { Table.close (); Table = null; Threadlocalhtable.remove (); } if (admin!= null) {Admin.close ();}}

Assuming that there is a scenario with 10 writer threads, then reference count is 11 (10 htable and one hbaseadmin), the first 5 thread close is OK, and the 6th thread is close htable first, Then found that the reference number is 0, it closes the hconnection, and then close admin is invalid, but the remaining 4 threads at this time may be performing flush operation, hconnection since has been broken, there must be no way flush finish ah, throw abnormal out

public void Flush () throws IOException {if (Getputbuffer (). Size () &gt; 0) {gethtable (). Put (Getputbuffer ()); Clearputbuffer (); } }

After you know the cause of the error, decisively after close hbaseadmin, point it to null so that it does not cause the problem of repeated shutdown

if (admin!= null) {admin.close (); admin = null;}


This problem bothers me for a few days, the Internet and can not find any information, and then saw the HBase source code only to find and solve the problem, it seems really encounter problems must understand the underlying code.

Related Article

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.