簡體   English   中英

通過Java代碼獲取MasterNotRunningException

[英]Getting MasterNotRunningException via java code

當我嘗試通過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:0:1:60805 2014-06-09 22:接受的套接字連接11:36,217 WARN org.apache.zookeeper.server.ZooKeeperServer:來自舊客戶端的連接請求/ 0:0:0:0:0:0:0:0:1:60805; 如果服務器處於ro模式將被刪除2014-06-09 22:11:36,217信息org.apache.zookeeper.server.ZooKeeperServer:客戶端嘗試在/ 0:0:0:0:0:0上建立新會話: 0:1:60805 2014-06-09 22:11:36,219 INFO org.apache.zookeeper.server.ZooKeeperServer:已建立會話0x146817ea6ff0003,客戶端/ 0:0:0:0:0:0:0:0的協商超時40000 1:60805 2014-06-09 22:12:15,768警告org.apache.zookeeper.server.NIOServerCnxn:捕獲到流末尾EndOfStreamException:無法從客戶端sessionid 0x146817ea6ff0003讀取其他數據,可能是客戶端已關閉org.apache上的套接字2014年org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)的.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:220)2014年java.lang.Thread.run(Thread.java:722) -06-09 22:12:15,778 INFO org.apache.zookeeper.server.NIOServerCnxn:客戶端/ 0:0:0:0:0:0:0:1:60805的會話ID為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

您可以使用HBase admin來做到這一點,它會為您正常工作。 下面給出了使用HBaseAdmin創建表和列系列的代碼。

    Configuration configuration = HBaseConfiguration.create();
    configuration.set("hbase.master", host + ":" + port);// host and port of hbase master.
    configuration.set("hbase.zookeeper.quorum", zookeeper-hostname);// ip where zookeeper is running.
    configuration.set("hbase.zookeeper.property.clientPort", zookeeper-port);// port on ehich zookeeper is runnig.
    HBaseAdmin admin = new HBaseAdmin(configuration);

    if (admin.isTableEnabled("mytable"))
    {
        admin.disableTable("mytable");
    }

    admin.deleteTable("tableName");

    HTableDescriptor tableDescriptor = new HTableDescriptor("mytable");

    HColumnDescriptor hColumnDescriptor = new HColumnDescriptor("colfam1");

    tableDescriptor.addFamily(hColumnDescriptor);

    admin.createTable(tableDescriptor);

然后,您可以將數據放入hbase表中。

您現有的看跌期權代碼將正常運行。

希望它對您有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM