2
我已經在hadoop集羣上設置了一個HBase集羣,其中在所有節點中禁用了IPv6。HBase與MapReduce
一切都運行良好;我能夠運行Java客戶端使用標準的認沽訪問HBase的,掃描,獲取,...
我寫了一個地圖,減少程序訪問HBase的,但我得到了以下錯誤:
Exception in thread "main" java.lang.NullPointerException
at org.apache.hadoop.net.DNS.reverseDns(DNS.java:72)
at org.apache.hadoop.hbase.mapreduce.TableInputFormatBase.reverseDNS(TableInp...
at org.apache.hadoop.hbase.mapreduce.TableInputFormatBase.reverseDNS(TableInp...
這是我的/ etc/hosts文件中的所有節點文件:
127.0.0.1 localhost.localdomain localhost
192.168.0.252 master.hadoop.com master
192.168.0.251 slave.hadoop.com slave
,這是我的map-reduce客戶端程序:
import java.io.IOException;
import java.util.StringTokenizer;
import java.net.InetAddress;
import org.apache.hadoop.net.DNS.*;
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;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.fs.Path;
public class HBaseAndMapReduceExample {
public static class MyMapper extends TableMapper<ImmutableBytesWritable, Put> {
public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException, InterruptedException {
// this example is just copying the data from the source table...
context.write(row, resultToPut(row,value));
}
private static Put resultToPut(ImmutableBytesWritable key, Result result) throws IOException {
Put put = new Put(key.get());
for (KeyValue kv : result.raw()) {
put.add(kv);
}
return put;
}
}
public static void main(String[] args) throws Exception {
Configuration config = HBaseConfiguration.create();
Job job = new Job(config,"HBaseAndMapReduceExample");
job.setJarByClass(HBaseAndMapReduceExample.class); // class that contains mapper
Scan scan = new Scan();
scan.setCaching(500); // 1 is the default in Scan, which will be bad for MapReduce jobs
scan.setCacheBlocks(false); // don't set to true for MR jobs
// set other scan attrs
TableMapReduceUtil.initTableMapperJob(
"testtable", // input table
scan, // Scan instance to control CF and attribute selection
MyMapper.class, // mapper class
null, // mapper output key
null, // mapper output value
job);
TableMapReduceUtil.initTableReducerJob(
"testtable2", // output table
null, // reducer class
job);
job.setNumReduceTasks(0);
boolean b = job.waitForCompletion(true);
if (!b) {
throw new IOException("error with job!");
}
}
}
能否請您指定的Hadoop(0.22,0.23,1.0等)和HBase的的版本(0.90,0.92,94)你使用? –
更詳細的堆棧跟蹤將會有所幫助。首先檢查您的網絡設置對'http:// hbase.apache.org/configuration.html#os'。您可能會發現這篇文章也很有用:'http:// sujee.net/tech/articles/hadoop/hadoop-dns /' –
感謝您的回覆,我使用hadoop 1.0,主機名和/ etc/hosts也是ssh信任關係沒問題,我可以使用它的名字來ping/ssh節點。 HBase代碼和mapreduce程序都可以正常工作,除非將前面的示例中顯示的mapreduce與hbase組合在一起,那麼只會出現問題。 我現在已經注意到,這個問題並不總是存在,有時候它有時不起作用,當它工作時,它會給出一個錯誤,但它通常會執行執行嗎? – mksoi