gpt4 book ai didi

java - HBase Java 客户端不工作(MasterNotRunningException 异常)

转载 作者:可可西里 更新时间:2023-11-01 14:41:32 24 4
gpt4 key购买 nike

我正在尝试使用 Java 编写远程 HBase 客户端。这是供引用的代码:

package ttumdt.app.connector;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class HBaseClusterConnector {
private final String MASTER_IP = "10.138.168.185";
private final String ZOOKEEPER_PORT = "2181";

final String TRAFFIC_INFO_TABLE_NAME = "TrafficLog";
final String TRAFFIC_INFO_COLUMN_FAMILY = "TimeStampIMSI";

final String KEY_TRAFFIC_INFO_TABLE_BTS_ID = "BTS_ID";
final String KEY_TRAFFIC_INFO_TABLE_DATE = "DATE";
final String COLUMN_IMSI = "IMSI";
final String COLUMN_TIMESTAMP = "TIME_STAMP";

private final byte[] columnFamily = Bytes.toBytes(TRAFFIC_INFO_COLUMN_FAMILY);
private final byte[] qualifier= Bytes.toBytes(COLUMN_IMSI);

private Configuration conf = null;

public HBaseClusterConnector () throws MasterNotRunningException, ZooKeeperConnectionException {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum",MASTER_IP);
conf.set("hbase.zookeeper.property.clientPort",ZOOKEEPER_PORT);
HBaseAdmin.checkHBaseAvailable(conf);
}

/**
* This filter will return list of IMSIs for a given btsId and ime interval
* @param btsId : btsId for which the query has to run
* @param startTime : start time for which the query has to run
* @param endTime : end time for which the query has to run
* @return returns IMSIs as set of Strings
* @throws IOException
*/
public Set<String> getInfoPerBTSID(String btsId, String date,
String startTime, String endTime)
throws IOException {
Set<String> imsis = new HashSet<String>();

//ToDo : better exception handling
HTable table = new HTable(conf, TRAFFIC_INFO_TABLE_NAME);
Scan scan = new Scan();

scan.addColumn(columnFamily,qualifier);
scan.setFilter(prepFilter(btsId, date, startTime, endTime));

// filter to build where timestamp

Result result = null;
ResultScanner resultScanner = table.getScanner(scan);

while ((result = resultScanner.next())!= null) {
byte[] obtainedColumn = result.getValue(columnFamily,qualifier);
imsis.add(Bytes.toString(obtainedColumn));
}

resultScanner.close();

return imsis;
}

//ToDo : Figure out how valid is this filter code?? How comparison happens
// with eqaul or grater than equal etc


private Filter prepFilter (String btsId, String date,
String startTime, String endTime)
{
byte[] tableKey = Bytes.toBytes(KEY_TRAFFIC_INFO_TABLE_BTS_ID);
byte[] timeStamp = Bytes.toBytes(COLUMN_TIMESTAMP);

// filter to build -> where BTS_ID = <<btsId>> and Date = <<date>>
RowFilter keyFilter = new RowFilter(CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes(btsId+date)));

// filter to build -> where timeStamp >= startTime
SingleColumnValueFilter singleColumnValueFilterStartTime =
new SingleColumnValueFilter(columnFamily, timeStamp,
CompareFilter.CompareOp.GREATER_OR_EQUAL,Bytes.toBytes(startTime));

// filter to build -> where timeStamp <= endTime
SingleColumnValueFilter singleColumnValueFilterEndTime =
new SingleColumnValueFilter(columnFamily, timeStamp,
CompareFilter.CompareOp.LESS_OR_EQUAL,Bytes.toBytes(endTime));

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, Arrays
.asList((Filter) keyFilter,
singleColumnValueFilterStartTime, singleColumnValueFilterEndTime));
return filterList;
}


public static void main(String[] args) throws IOException {
HBaseClusterConnector flt = new HBaseClusterConnector();
Set<String> imsis= flt.getInfoPerBTSID("AMCD000784", "26082013","104092","104095");
System.out.println(imsis.toString());
}
}

我目前正在使用 Cloudera 快速启动 VM 对此进行测试。

问题是;如果我在 VM 上运行这段代码,它绝对可以正常工作。但如果从外部运行,它会失败并出现以下错误。而且我怀疑它与 VM 设置有关,而不是其他任何事情。请注意,我已经检查过我是否可以从主机连接到 VM 的节点管理器/作业跟踪器并且它工作得非常好。当我从我的主机操作系统运行代码而不是在 VM 上运行它时;我收到以下错误:

2013-10-15 18:16:04.185 java[652:1903] Unable to load realm info from SCDynamicStore
Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: Retried 1 times
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:138)
at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:1774)
at ttumdt.app.connector.HBaseClusterConnector.<init>(HBaseClusterConnector.java:47)
at ttumdt.app.connector.HBaseClusterConnector.main(HBaseClusterConnector.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1

请注意;主节点实际上正在运行。 zookeper 日志显示它已与主机操作系统建立连接:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

6:16:03.274 PM INFO org.apache.zookeeper.server.ZooKeeperServer

Client attempting to establish new session at /10.138.169.81:50567

6:16:03.314 PM INFO org.apache.zookeeper.server.ZooKeeperServer

Established session 0x141bc2487440004 with negotiated timeout 60000 for client /10.138.169.81:50567

6:16:03.964 PM INFO org.apache.zookeeper.server.PrepRequestProcessor

Processed session termination for sessionid: 0x141bc2487440004

6:16:03.996 PM INFO org.apache.zookeeper.server.NIOServerCnxn

Closed socket connection for client /10.138.169.81:50567 which had sessionid 0x141bc2487440004

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

但我在 Master 或 RegionServer 日志中看不到任何 Activity 的痕迹。

请注意我的主机操作系统是 Mac OSX 10.7.5

根据可用资源;这应该可以正常工作;尽管有些人认为简单的 HBase java 客户端永远无法工作。我糊涂了;并热切等待指点!请回复

最佳答案

在不同的端口上启动你的 hiveserver2 然后尝试连接

在不同端口上连接 hiveserver2 的命令(确保配置单元在路径中):

hive --service hiveserver2 --hiveconf hive.server2.thrift.port=13000

关于java - HBase Java 客户端不工作(MasterNotRunningException 异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19381853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com