【发布时间】:2015-07-19 15:48:16
【问题描述】:
我正在尝试从 Hadoop MapReduce 映射器查询 GeoLite 数据库以解析 IP 地址的国家/地区。我尝试了两种方法:
1.使用File 仅适用于本地文件系统,我收到文件未找到异常
File database = new File("hdfs://localhost:9000/input/GeoLite2-City.mmdb"); // <<< HERE
DatabaseReader reader = new DatabaseReader.Builder(database).build();
2.使用流,但在运行时出现此错误
错误:Java 堆空间
Path pt = new Path("hdfs://localhost:9000/input/GeoLite2-City.mmdb");
FileSystem fs = FileSystem.get(new Configuration());
FSDataInputStream stream = fs.open(pt);
DatabaseReader reader = new DatabaseReader.Builder(stream).build();
InetAddress ipAddress = InetAddress.getByName(address.getHostAddress());
CityResponse response = null;
try {
response = reader.city(ipAddress);
} catch (GeoIp2Exception ex) {
ex.printStackTrace();
return;
}
我的问题:如何从 Hadoop 中的 mapper 查询 geolite 数据库?
【问题讨论】:
-
Error: Java Heap Space那么为什么不给映射器更多的堆空间呢?
标签: java hadoop geolocation hdfs