Thanks. Now I see whats up. This is what we all use to get a Configuration:
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/HBaseConfiguration.html#create() It does what you do below manually. St.Ack On Fri, Mar 11, 2011 at 3:45 AM, King JKing <[email protected]> wrote: > That is mark in //CHANGE CODE ---- //END CHANGE CODE > HTable ht = new HTable(config, "T1"); > byte[] row = Bytes.toBytes(1); > > Get get = new Get(row); > Result result = ht.get(get); > System.out.println(Bytes. > toString(result.getValue("F1".getBytes(), "C1".getBytes()))); > > try { > Thread.sleep(60000); > } catch (InterruptedException ex) { > ex.printStackTrace(); > } > * > //CHANGE CODE > config = new Configuration(false); > Path hbase = new Path("conf/hbase-site.xml"); > config.addResource(hbase); > **ht = new HTable(config, "T1");* > *//END CHANGE CODE* > get = new Get(row); > result = ht.get(get); > > System.out.println(Bytes.toString(result.getValue("F1".getBytes(), > "C1".getBytes()))); > > > On Fri, Mar 11, 2011 at 11:19 AM, Stack <[email protected]> wrote: > >> What did you change (Its hard looking at code to see what line is >> different; better to post a diff). >> St.Ack >> >> On Thu, Mar 10, 2011 at 6:09 PM, King JKing <[email protected]> wrote: >> > After change code to >> > HTable ht = new HTable(config, "T1"); >> > byte[] row = Bytes.toBytes(1); >> > >> > Get get = new Get(row); >> > Result result = ht.get(get); >> > System.out.println(Bytes. >> > toString(result.getValue("F1".getBytes(), "C1".getBytes()))); >> > >> > try { >> > Thread.sleep(60000); >> > } catch (InterruptedException ex) { >> > ex.printStackTrace(); >> > } >> > >> > *ht = new HTable(config, "T1");* >> > get = new Get(row); >> > result = ht.get(get); >> > >> > System.out.println(Bytes.toString(result.getValue("F1".getBytes(), >> > "C1".getBytes()))); >> > >> > I got the error: >> > >> > 11/03/11 08:57:05 WARN zookeeper.ZKUtil: hconnection-0x12ea29ecc580005 >> > Unable to get children of node /hbase/rs >> > 11/03/11 08:57:05 ERROR zookeeper.ZooKeeperWatcher: >> > hconnection-0x12ea29ecc580005 Received unexpected KeeperException, >> > re-throwing exception >> > org.apache.zookeeper.KeeperException$ConnectionLossException: >> > KeeperErrorCode = ConnectionLoss for /hbase/rs >> > at >> > org.apache.zookeeper.KeeperException.create(KeeperException.java:90) >> > at >> > org.apache.zookeeper.KeeperException.create(KeeperException.java:42) >> > at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:780) >> > at >> > >> org.apache.hadoop.hbase.zookeeper.ZKUtil.getNumberOfChildren(ZKUtil.java:495) >> > at >> > org.apache.hadoop.hbase.client.HTable.getCurrentNrHRS(HTable.java:207) >> > at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:182) >> > at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:145) >> > at >> > com.vng.comment.core.storage.TestHBase.testGet4(TestHBase.java:218) >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > at >> > >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) >> > at >> > >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> > at java.lang.reflect.Method.invoke(Method.java:616) >> > at junit.framework.TestCase.runTest(TestCase.java:168) >> > at junit.framework.TestCase.runBare(TestCase.java:134) >> > at junit.framework.TestResult$1.protect(TestResult.java:110) >> > at junit.framework.TestResult.runProtected(TestResult.java:128) >> > >> > After change code to >> > >> > HTable ht = new HTable(config, "T1"); >> > byte[] row = Bytes.toBytes(1); >> > >> > Get get = new Get(row); >> > Result result = ht.get(get); >> > System.out.println(Bytes. >> > toString(result.getValue("F1".getBytes(), "C1".getBytes()))); >> > >> > try { >> > Thread.sleep(60000); >> > } catch (InterruptedException ex) { >> > ex.printStackTrace(); >> > } >> > * >> > config = new Configuration(false); >> > Path hbase = new Path("conf/hbase-site.xml"); >> > config.addResource(hbase); >> > **ht = new HTable(config, "T1");* >> > >> > get = new Get(row); >> > result = ht.get(get); >> > >> > System.out.println(Bytes.toString(result.getValue("F1".getBytes(), >> > "C1".getBytes()))); >> > >> > This code run well. >> > >> > >> > On Fri, Mar 11, 2011 at 9:02 AM, King JKing <[email protected]> wrote: >> > >> >> Here is stacktrace: >> >> >> >> 11/03/11 08:56:44 WARN zookeeper.ClientCnxn: Exception closing session >> >> 0x12ea29ecc580005 to sun.nio.ch.SelectionKeyImpl@1175422 >> >> java.io.IOException: Read error rc = -1 java.nio.DirectByteBuffer[pos=0 >> >> lim=4 cap=4] >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.doIO(ClientCnxn.java:701) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:945) >> >> 11/03/11 08:56:45 INFO zookeeper.ClientCnxn: Attempting connection to >> >> server /10.30.12.182:2181 >> >> 11/03/11 08:56:45 WARN zookeeper.ClientCnxn: Exception closing session >> >> 0x12ea29ecc580005 to sun.nio.ch.SelectionKeyImpl@1b1fbf4 >> >> java.net.ConnectException: Connection refused >> >> at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) >> >> at >> >> sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:592) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:933) >> >> 11/03/11 08:56:45 WARN zookeeper.ClientCnxn: Ignoring exception during >> >> shutdown input >> >> java.nio.channels.ClosedChannelException >> >> at >> >> sun.nio.ch.SocketChannelImpl.shutdownInput(SocketChannelImpl.java:656) >> >> at >> sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:378) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:999) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:970) >> >> 11/03/11 08:56:45 WARN zookeeper.ClientCnxn: Ignoring exception during >> >> shutdown output >> >> java.nio.channels.ClosedChannelException >> >> at >> >> sun.nio.ch.SocketChannelImpl.shutdownOutput(SocketChannelImpl.java:667) >> >> at >> sun.nio.ch.SocketAdaptor.shutdownOutput(SocketAdaptor.java:386) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:1004) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:970) >> >> 11/03/11 08:56:47 INFO zookeeper.ClientCnxn: Attempting connection to >> >> server /10.30.12.182:2181 >> >> 11/03/11 08:56:47 WARN zookeeper.ClientCnxn: Exception closing session >> >> 0x12ea29ecc580005 to sun.nio.ch.SelectionKeyImpl@6fa9fc >> >> java.net.ConnectException: Connection refused >> >> at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) >> >> at >> >> sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:592) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:933) >> >> 11/03/11 08:56:47 WARN zookeeper.ClientCnxn: Ignoring exception during >> >> shutdown input >> >> java.nio.channels.ClosedChannelException >> >> at >> >> sun.nio.ch.SocketChannelImpl.shutdownInput(SocketChannelImpl.java:656) >> >> at >> sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:378) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:999) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:970) >> >> 11/03/11 08:56:47 WARN zookeeper.ClientCnxn: Ignoring exception during >> >> shutdown output >> >> java.nio.channels.ClosedChannelException >> >> at >> >> sun.nio.ch.SocketChannelImpl.shutdownOutput(SocketChannelImpl.java:667) >> >> at >> sun.nio.ch.SocketAdaptor.shutdownOutput(SocketAdaptor.java:386) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:1004) >> >> at >> >> org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:970) >> >> >> >> >> >> >> >> On Thu, Mar 10, 2011 at 9:02 PM, BlueDavy Lin <[email protected]> >> wrote: >> >> >> >>> When u new Get(row) first,HBase client cache the connection to the >> >>> appropriate region server,after u restart HBase(I think u run >> >>> standalone?),when u do Get(row) again,HBase client still use the >> >>> cached connection to do this,so throw the Exception. >> >>> >> >>> But it seems should not throws the exception a lot of times,can u post >> >>> the exception stack? >> >>> >> >>> 2011/3/10 King JKing <[email protected]>: >> >>> > Dear all, >> >>> > >> >>> > When I stop and start HBase server, HTable >> >>> (org.apache.hadoop.hbase.client) >> >>> > throw exception. >> >>> > Here is my code test: >> >>> > HTable ht = new HTable(config, "T1"); >> >>> > byte[] row = Bytes.toBytes(1); >> >>> > >> >>> > Get get = new Get(row); >> >>> > Result result = ht.get(get); >> >>> > >> >>> > System.out.println(Bytes.toString(result.getValue("F1".getBytes(), >> >>> > "C1".getBytes()))); >> >>> > >> >>> > try { >> >>> > Thread.sleep(60000); >> >>> > } catch (InterruptedException ex) { >> >>> > ex.printStackTrace(); >> >>> > } >> >>> > >> >>> > get = new Get(row); >> >>> > result = ht.get(get); >> >>> > >> >>> > System.out.println(Bytes.toString(result.getValue("F1".getBytes(), >> >>> > "C1".getBytes()))); >> >>> > >> >>> > First I start HBase and run my code. After that I stop and start >> HBase. >> >>> And >> >>> > exception "Exception closing session to sun.nio.ch.SelectionKeyImpl" >> >>> throws >> >>> > a lot of times. >> >>> > >> >>> > Could you help me to fix this problem? >> >>> > Thank a lot for support. >> >>> > >> >>> >> >>> >> >>> >> >>> -- >> >>> ============================= >> >>> | BlueDavy | >> >>> | http://www.bluedavy.com | >> >>> ============================= >> >>> >> >> >> >> >> > >> >
