2012-12-26 117 views
0

我已經設置了一切,就像hbase文檔所述。這裏是我的HBase-site.xml中無法從java連接到hbase

<configuration> 
    <property> 
     <name>hbase.rootdir</name> 
     <value>file:///users/urijvoskresenskij/hbase-0.94.3/hbase</value> 
    </property> 
    <property> 
     <name>hbase.zookeeper.property.dataDir</name> 
     <value>/users/urijvoskresenskij/hbase-0.94.3/zookeeper</value> 
    </property> 
</configuration> 

Java代碼:

import java.io.IOException; 

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.apache.hadoop.hbase.client.HBaseAdmin; 
import org.apache.hadoop.hbase.client.HTable; 
import org.apache.hadoop.hbase.client.Put; 
import org.apache.hadoop.hbase.util.Bytes; 

public class MainHBase { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) throws Exception { 
     Configuration config = HBaseConfiguration.create(); 
     config.set("hbase.zookeeper.quorum", "localhost"); 
     HBaseAdmin admin = new HBaseAdmin(config); 
     try { 
      HTable table = new HTable(config, "test-table"); 
      Put put = new Put(Bytes.toBytes("test-key")); 
      put.add(Bytes.toBytes("cf"), Bytes.toBytes("q"), Bytes.toBytes("value")); 
      table.put(put); 
     } finally { 
      admin.close(); 
     } 
} 

這裏是例外:

2012-12-26 11:08:07.980 java[10204:1c03] Unable to load realm info from SCDynamicStore 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:host.name=192.168.1.101 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0-ea 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.home=/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/jre 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/Users/urijvoskresenskij/Documents/workspace/Hbase/bin:/Users/urijvoskresenskij/hbase-0.94.3/lib/activation-1.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/asm-3.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/avro-1.5.3.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/avro-ipc-1.5.3.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-beanutils-1.7.0.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-beanutils-core-1.8.0.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-cli-1.2.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-codec-1.4.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-collections-3.2.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-configuration-1.6.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-digester-1.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-el-1.0.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-httpclient-3.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-io-2.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-lang-2.5.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-logging-1.1.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-math-2.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/commons-net-1.4.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/core-3.1.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/guava-11.0.2.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/hadoop-core-1.0.4.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/high-scale-lib-1.1.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/httpclient-4.1.2.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/httpcore-4.1.3.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jackson-core-asl-1.8.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jackson-jaxrs-1.8.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jackson-mapper-asl-1.8.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jackson-xc-1.8.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jamon-runtime-2.3.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jasper-compiler-5.5.23.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jasper-runtime-5.5.23.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jaxb-api-2.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jaxb-impl-2.2.3-1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jersey-core-1.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jersey-json-1.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jersey-server-1.8.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jettison-1.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jetty-6.1.26.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jetty-util-6.1.26.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jruby-complete-1.6.5.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jsp-2.1-6.1.14.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jsp-api-2.1-6.1.14.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/jsr305-1.3.9.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/junit-4.10-HBASE-1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/libthrift-0.8.0.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/log4j-1.2.16.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/metrics-core-2.1.2.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/netty-3.2.4.Final.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/protobuf-java-2.4.0a.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/servlet-api-2.5-6.1.14.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/slf4j-api-1.4.3.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/slf4j-log4j12-1.4.3.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/snappy-java-1.0.3.2.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/stax-api-1.0.1.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/velocity-1.7.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/xmlenc-0.52.jar:/Users/urijvoskresenskij/hbase-0.94.3/lib/zookeeper-3.4.3.jar:/Users/urijvoskresenskij/hbase-0.94.3/hbase-0.94.3-tests.jar:/Users/urijvoskresenskij/hbase-0.94.3/hbase-0.94.3.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.aop-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.asm-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.aspects-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.beans-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.context-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.context.support-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.core-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.expression-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.instrument-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.instrument.tomcat-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.jdbc-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.jms-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.orm-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.oxm-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.test-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.transaction-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.web-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.web.portlet-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.web.servlet-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/dist/org.springframework.web.struts-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Downloads/commons-logging-1.1.1/commons-logging-1.1.1.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.web-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.aop-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.asm-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.aspects-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.beans-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.context-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.context.support-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.core-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.expression-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.instrument-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.instrument.tomcat-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.jdbc-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.jms-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.orm-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.oxm-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.test-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.transaction-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.web.portlet-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.web.servlet-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Desktop/spring-framework-3.1.3.RELEASE/src/org.springframework.web.struts-sources-3.1.3.RELEASE.jar:/Users/urijvoskresenskij/Downloads/commons-logging-1.1.1/commons-logging-1.1.1-javadoc.jar:/Users/urijvoskresenskij/Downloads/commons-logging-1.1.1/commons-logging-1.1.1-sources.jar:/Users/urijvoskresenskij/Downloads/commons-logging-1.1.1/commons-logging-adapters-1.1.1.jar:/Users/urijvoskresenskij/Downloads/commons-logging-1.1.1/commons-logging-api-1.1.1.jar:/Users/urijvoskresenskij/Downloads/commons-logging-1.1.1/commons-logging-tests.jar 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/Users/urijvoskresenskij/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/var/folders/_q/z5blmlxs39d4pmmv1fj9mh500000gn/T/ 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA> 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:os.name=Mac OS X 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:os.arch=x86_64 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:os.version=10.7.5 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:user.name=urijvoskresenskij 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:user.home=/Users/urijvoskresenskij 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Client environment:user.dir=/Users/urijvoskresenskij/Documents/workspace/Hbase 
12/12/26 10:08:08 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection 
12/12/26 10:08:08 INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181 
12/12/26 10:08:08 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is [email protected] 
12/12/26 10:08:08 INFO client.ZooKeeperSaslClient: Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration. 
12/12/26 10:08:08 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session 
12/12/26 10:08:08 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x13bd4823ba20007, negotiated timeout = 40000 
12/12/26 10:08:08 WARN client.HConnectionManager$HConnectionImplementation: Encountered problems when prefetch META table: 
org.apache.hadoop.hbase.TableNotFoundException: Cannot find row in .META. for table: test-table, row=test-table,,99999999999999 
    at org.apache.hadoop.hbase.client.MetaScanner.metaScan(MetaScanner.java:164) 
    at org.apache.hadoop.hbase.client.MetaScanner.access$000(MetaScanner.java:54) 
    at org.apache.hadoop.hbase.client.MetaScanner$1.connect(MetaScanner.java:133) 
    at org.apache.hadoop.hbase.client.MetaScanner$1.connect(MetaScanner.java:130) 
    at org.apache.hadoop.hbase.client.HConnectionManager.execute(HConnectionManager.java:360) 
    at org.apache.hadoop.hbase.client.MetaScanner.metaScan(MetaScanner.java:130) 
    at org.apache.hadoop.hbase.client.MetaScanner.metaScan(MetaScanner.java:105) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.prefetchRegionCache(HConnectionManager.java:922) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:977) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:864) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:821) 
    at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:234) 
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:174) 
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:133) 
    at MainHBase.main(MainHBase.java:20) 
Exception in thread "main" org.apache.hadoop.hbase.TableNotFoundException: test-table 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:999) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:864) 
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:821) 
    at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:234) 
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:174) 
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:133) 
    at MainHBase.main(MainHBase.java:20) 

試過已谷歌,但沒能找到解決方案。我的操作系統是OS X.我嘗試創建的表格無法從hbase shell掃描。請幫忙:)

+0

的[HBase的找不到現有表]可能重複(http://stackoverflow.com/questions/10586246/hbase-cannot-find-an-existing-table) - TableNotFoundException的'相同根源:找不到行.META' – Gagravarr

+0

不,先生,這是一個不同的問題 – PAcan

回答

1

你有沒有創建「測試表」?表格必須在將數據放入之前存在。

Configuration conf = HBaseConfiguration.create(); 
HBaseAdmin hbase = new HBaseAdmin(conf); 
HTableDescriptor desc = new HTableDescriptor("test_table"); 
HColumnDescriptor cf = new HColumnDescriptor("cf".getBytes()); 
desc.addFamily(cf); 
hbase.createTable(desc); 
+1

非常感謝!也許你知道,如何正確地將數據放入它? – PAcan

+0

與您所示的相同,但不需要HBaseAdmin – Tariq