分享

job.waitForCompletion(true)?0:1 无响应

苏晓黑 发表于 2015-10-15 14:52:56 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 5 25603
使用的是Hadoop2.7.1以及HBase0.98版本。分开做的测试都可以执行,但是当两者结合,运行到最后job.waitForCompletion(true)?0:1就一直没有响应,看日志文件也没有错误信息。现在想应该是配置文件需要适当的更改,但是不知道改哪里?
[mw_shl_code=actionscript3,true]

        public static class Map extends Mapper<LongWritable,Text,Text,IntWritable>{
                private IntWritable i = new IntWritable();
                public void map(LongWritable key,Text value,Context context)
                throws IOException,InterruptedException {
                        String s[] = value.toString().trim().split(" ");
                        for(String m : s){
                                context.write(new Text(m), i);
                        }
                }
        }
       
        public static class Reduce extends TableReducer<Text, IntWritable, NullWritable>{

                public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{
                        int sum = 0;
                        for(IntWritable i : values){
                                sum += i.get();
                        }
                        Put put = new Put(Bytes.toBytes(key.toString()));
                        put.add(Bytes.toBytes("content"), Bytes.toBytes("count"), Bytes.toBytes(String.valueOf(sum)));
                        context.write(NullWritable.get(), put);
                }
        }
       
        public static void createHBaseTable(String tableName) throws IOException{
                HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
                HColumnDescriptor col = new HColumnDescriptor("content");
                htd.addFamily(col);
//                Configuration config = new Configuration();
//                HBaseAdmin admin = new HBaseAdmin(config);
                HBaseAdmin admin = new HBaseAdmin(ExConfiguration.configuration);
                if(admin.tableExists(tableName)){
                        System.out.println("table exists, trying recreate table!");
                        admin.disableTable(tableName);
                        admin.deleteTable(tableName);
                }
                System.out.println("create new table " + tableName);
                admin.createTable(htd);
        }
       
        public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException{
                String tableName = "wordcount";
                Configuration conf = new Configuration();
                conf.set(TableOutputFormat.OUTPUT_TABLE, tableName);
                createHBaseTable(tableName);
                String input = args[0];
//                Job job = new Job(conf, "WordCount table with " + input);
                Job job = Job.getInstance(conf, "WordCount table with " + input);
                job.setJarByClass(WordCountHBase.class);
                job.setNumReduceTasks(3);
                job.setMapperClass(Map.class);
                job.setReducerClass(Reduce.class);
                job.setMapOutputKeyClass(Text.class);
                job.setMapOutputValueClass(IntWritable.class);
                job.setInputFormatClass(TextInputFormat.class);
                job.setOutputFormatClass(TableOutputFormat.class);
                FileInputFormat.addInputPath(job, new Path(input));
                System.exit(job.waitForCompletion(true)?0:1);
        }
[/mw_shl_code]

已有(5)人评论

跳转到指定楼层
苏晓黑 发表于 2015-10-15 14:55:44
在HBase Shell 中执行scan 'wordcount'也是查不到插入的数据。源数据格式就是“Hello World Bye World”
回复

使用道具 举报

bob007 发表于 2015-10-15 16:26:38
苏晓黑 发表于 2015-10-15 14:55
在HBase Shell 中执行scan 'wordcount'也是查不到插入的数据。源数据格式就是“Hello World Bye World”

就是提交不了呗,看看集群是否有问题
回复

使用道具 举报

苏晓黑 发表于 2015-10-15 16:42:16
bob007 发表于 2015-10-15 16:26
就是提交不了呗,看看集群是否有问题

已经找到原因了,正好在这里回复下。是在main方法中的conf要设置几个参数。[mw_shl_code=actionscript3,true]conf.set("mapred.job.tracker", "master:9001,slave:9001");   
            conf.set("hbase.zookeeper.quorum","master,slave");   
            conf.set("hbase.zookeeper.property.clientPort", "2181"); [/mw_shl_code]
回复

使用道具 举报

苏晓黑 发表于 2015-10-15 16:42:57
bob007 发表于 2015-10-15 16:26
就是提交不了呗,看看集群是否有问题

已经找到原因了,正好在这里回复下。是在main方法中的conf要设置几个参数。[mw_shl_code=actionscript3,true]conf.set("mapred.job.tracker", "master:9001,slave:9001");   
            conf.set("hbase.zookeeper.quorum","master,slave");   
            conf.set("hbase.zookeeper.property.clientPort", "2181"); [/mw_shl_code]
回复

使用道具 举报

bob007 发表于 2015-10-15 17:09:45
本帖最后由 bob007 于 2015-10-15 17:10 编辑

跟这个有点类似
hbase开发环境搭建及运行hbase小实例(HBase 0.98.3新api)
http://www.aboutyun.com/thread-8401-1-1.html



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条