【发布时间】:2014-06-09 16:48:59
【问题描述】:
当我尝试通过 java 代码创建表时,我收到以下错误消息。通过 Hbase shell 执行此操作时没有问题。我正在使用伪分布式集群。
线程“主”org.apache.hadoop.hbase.MasterNotRunningException 中的异常:
查看日志文件:
2014-06-09 22:11:36,213 INFO org.apache.zookeeper.server.NIOServerCnxnFactory:接受来自 /0:0:0:0:0:0:0:1:60805 的套接字连接 2014-06-09 22:11:36,217 警告 org.apache.zookeeper.server.ZooKeeperServer:来自旧客户端的连接请求 /0:0:0:0:0:0:0:1:60805;如果服务器处于 r-o 模式,将被丢弃 2014-06-09 22:11:36,217 INFO org.apache.zookeeper.server.ZooKeeperServer:客户端尝试在 /0:0:0:0:0:0:0:1:60805 建立新会话 2014-06-09 22:11:36,219 信息 org.apache.zookeeper.server.ZooKeeperServer:已建立会话 0x146817ea6ff0003,客户端协商超时 40000 /0:0:0:0:0:0:0:1:60805 2014-06-09 22:12:15,768 WARN org.apache.zookeeper.server.NIOServerCnxn:捕获流异常结束 EndOfStreamException:无法从客户端 sessionid 0x146817ea6ff0003 读取附加数据,可能客户端已关闭套接字 在 org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:220) 在 org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208) 在 java.lang.Thread.run(Thread.java:722) 2014-06-09 22:12:15,778 INFO org.apache.zookeeper.server.NIOServerCnxn:已关闭客户端 /0:0:0:0:0:0:0:1:60805 的套接字连接,其 sessionid 为 0x146817ea6ff0003
package client;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
// ^^ PutExample
import util.HBaseHelper;
// vv PutExample
import java.io.IOException;
public class PutExample {
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create(); // co PutExample-1-CreateConf Create the required configuration.
System.out.println("Start...");
// ^^ PutExample
HBaseHelper helper = HBaseHelper.getHelper(conf);
helper.dropTable("mytable");
helper.createTable("mytable", "colfam1");
// vv PutExample
HTable table = new HTable(conf, "mytable"); // co PutExample-2-NewTable Instantiate a new client.
Put put = new Put(Bytes.toBytes("row1")); // co PutExample-3-NewPut Create put with specific row.
put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"),
Bytes.toBytes("val1")); // co PutExample-4-AddCol1 Add a column, whose name is "colfam1:qual1", to the put.
put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual2"),
Bytes.toBytes("val2")); // co PutExample-4-AddCol2 Add another column, whose name is "colfam1:qual2", to the put.
table.put(put); // co PutExample-5-DoPut Store row with column into the HBase table.
System.out.println("End...");
}
}
// ^^ PutExample
【问题讨论】: