xinxuaw231 发表于 2016-12-12 10:13:11

Hadoop中map reduce和client共享数据源的方式

  需求:
  hadoop执行mr job的时候需要在map reduce 以及client三处相互共享数据比如在map某阶段设置一个标记位让reduce知道。
  方案:
  1.由于Configuration在client提交之后修改就无效了,因此不能基于Configuration来实现,那么可以通过三份数据源来实习比如db file等
  2.基于hdfs
  实现:
  基于hdfs写文件实现,核心代码如下:
  client read操作:

Path flagPath = new Path("/hadoop/flag");
if (hdfs.exists(flagPath)) {
hdfs.delete(flagPath, true);
}
.......your biz.........
boolean isCircleEnd = false;
if (hdfs.exists(flagPath)) {
FSDataInputStream fdis = hdfs.open(flagPath);
isCircleEnd = fdis.readBoolean();
fdis.close();
}
  其他写操作:

FSDataOutputStream fdos = FileSystem
.get(context.getConfiguration()).create(
new Path("/hadoop/flag"));
fdos.writeBoolean(true);
fdos.flush();
fdos.close();
页: [1]
查看完整版本: Hadoop中map reduce和client共享数据源的方式