Try making the HBaseConfiguration once only (Create it in a Constructor or pass it in from the main).
ZooKeeper has an upper bound on the number of connections from any one IP (30 by default IIRC) to protect against DoS. HBase HTable internally will create a new connection each time if the HBaseConfiguration is new each time; otherwise, the HBase Connection object is shared amongst HTables. St.Ack On Wed, Sep 9, 2009 at 6:07 PM, elsif <[email protected]> wrote: > Hello. We are trying to use Hbase in a threaded application and are > encountering an issue with the ZooKeeper connection being lost: > > org.apache.hadoop.hbase.client.NoServerForRegionException: Timed out > trying to locate root region > > The following sample program returns 10 results and 10 of the above > errors. Code was compiled against the 0.20.0 svn fork and the > pre-compiled Hadoop 0.20.0 release. > > import java.io.IOException; > > import org.apache.hadoop.hbase.HBaseConfiguration; > import org.apache.hadoop.hbase.KeyValue; > import org.apache.hadoop.hbase.client.HTable; > import org.apache.hadoop.hbase.client.Get; > import org.apache.hadoop.hbase.client.Result; > import org.apache.hadoop.hbase.util.Bytes; > > // create 'fc_test', {NAME => 'json', VERSIONS => 1}, {NAME => 'data', > VERSIONS =>1} > // put 'fc_test', 'testing123', 'json:', "[1,2,3]" > > public class TableTest extends Thread { > public void run() { > try { > String key = "testing123"; > HBaseConfiguration conf = new HBaseConfiguration(); > HTable table = new HTable(conf, "fc_test"); > Get get = new Get(Bytes.toBytes(key)); > get.addFamily(Bytes.toBytes("json")); > Result result = table.get(get); > KeyValue[] kvs = result.raw(); > > System.out.println(Bytes.toString(kvs[0].getValue())); > } catch (Exception e) { > System.out.println(e.toString()); > } > > try { > Thread.currentThread().sleep(1000); > } catch (Exception e) { > } > > } > > public static void main(String args[]) throws IOException { > Thread t = null; > int i; > > for (i = 0; i< 20; i++) { > t = new TableTest(); > t.start(); > } > > // wait for last thread > try { > t.join(); > } catch (InterruptedException e) { > } > } > } > > > > #!/bin/bash > > export > CLASSPATH=.:/opt/hbase/conf:/opt/hbase/build/hbase-0.20.0.jar:/opt/hbase/lib/AgileJSON-2009-03-30.jar:/opt/hbase/lib/commons-cli-2.0-SNAPSHOT.jar:/opt/hbase/lib/commons-el-from-jetty-5.1.4.jar:/opt/hbase/lib/commons-httpclient-3.0.1.jar:/opt/hbase/lib/commons-logging-1.0.4.jar:/opt/hbase/lib/commons-logging-api-1.0.4.jar:/opt/hbase/lib/commons-math-1.1.jar:/opt/hbase/lib/hadoop-0.20.0-plus4681-core.jar:/opt/hbase/lib/hadoop-0.20.0-test.jar:/opt/hbase/lib/hadoop-gpl-compression-0.1.0-dev.jar:/opt/hbase/lib/jasper-compiler-5.5.12.jar:/opt/hbase/lib/jasper-runtime-5.5.12.jar:/opt/hbase/lib/jetty-6.1.14.jar:/opt/hbase/lib/jetty-util-6.1.14.jar:/opt/hbase/lib/jruby-complete-1.2.0.jar:/opt/hbase/lib/json.jar:/opt/hbase/lib/junit-3.8.1.jar:/opt/hbase/lib/libthrift-r771587.jar:/opt/hbase/lib/log4j-1.2.15.jar:/opt/hbase/lib/lucene-core-2.2.0.jar:/opt/hbase/lib/servlet-api-2.5-6.1.14.jar:/opt/hbase/lib/xmlenc-0.52.jar:/opt/hbase/lib/zookeeper-r785019-hbase-1329.jar > > javac -classpath ${CLASSPATH} TableTest.java > > java -classpath ${CLASSPATH} TableTest 2>err.log > >
