-1

假设我在减速器代码中的输入键/值中检测到某些内容,应该实际运行什么代码以使减速器不再继续,输出处发出的任何记录都将写入输出文件,并且作业停止,不再进一步减少发生?

4

2 回答 2

1

可能是多个 reducer 必须在您的 hadoop 集群上运行的情况。因此,即使您在输入中检测到错误并尝试停止它,您也不确定状态是否一致(即一旦收到错误的输入就不会处理任何记录),因为多个记录可能由多个减速器并行处理。

所以我认为停止工作不是一个好主意。

于 2013-04-04T19:04:32.533 回答
1

停止工作可能不是一个好主意。但是,如果您需要它,一种方法是创建您自己的异常类,可能扩展其中一个InterruptedExceptionor IOException,并在您想要退出的条件出现时抛出该异常。

您的异常类可能如下:

Class QuitReducerException extends InterruptedException {

      //Parameterless Constructor
      public QuitReducerException() {}

      //Constructor that accepts a message
      public QuitReducerException(String message)
      {
         super(message);
      }
}

在您的 reduce 方法中,您可以按如下方式使用它:

@Override
 protected void reduce(Text key, Iterable values, Context context) throws IOException,InterruptedException {
      ...
      if(<condition to quit happen>){
          throw new QuitReducerException("Quitting reducer due to some specified reason");// You may add details of the reason you are quitting and this will be available in the job logs (in stderr)
      }
      ...
  }


PS:这不能确保当前 reducer 发出的输出会被提交到输出文件。此外,任何其他未完成的减速器都不会提交文件。虽然已经完成的 reducer 已经提交了他们的输出。

于 2013-04-04T19:08:03.177 回答