关于Oozie的input-events和done-flag,oozieinput-events


关于Oozie的input-events和done-flag


工作流的执行条件

当coordinator指定的一个workflow已经进入执行时间窗口时,oozie会首先检查所有的input-events是否都已“发生”(满足),检查主要是分两个方面:

当切仅当所有的input-events都已发生,工作流才会进入runing状态,否则, oozie会持续监视指定的文件或文件夹,一但它们创建出来,或者生成了done-flag文件,工作流会立即进入running状态。

关于done-flag

从应用的角度来看,如是监视的是文件或文件夹,在它们建立的那一刻,数据可能并未写入完整,此时立即执行action可能会丢失数据或出现错误,一个好的处理方法是等所有文件写出完成之后,写一个标志文件,能过这个标志文件来启动action,这就是 done-flag的作用!

以下是官方文档中对done-flag的说明:

  • If the done-flag is omitted the coordinator will wait for the presence of a _SUCCESS file in the directory (Note: MapReduce jobs create this on successful completion automatically).
  • If the done-flag is present but empty, then the existence of the directory itself indicates that the dataset is ready.
  • If the done-flag is present but non-empty, Oozie will check for the presence of the named file within the directory, and will be considered ready (done)

对于done-flag需要说明的是:

对于input event, 当它引用的dateset指定了done-flag,则oozie在执行action之前会“读”这个flag文件,以判断是否可以开始后续的动作。需要特别注意的是:input event不是一定要被某个action作为参数(配置属性)来引用,虽然大多数时候是这样的,如果一个input event没有被任何action引用,实际上它起到的是“输入检查”的作用,也就是在开始任何action之前,检查制定的文件或文件夹是否存在,如果指定了done flag文件,再检查done flag文件是否存在。

对于output event, 当它引用的dateset指定了done-flag, oozie并不会在执行action之后去“写”这个flag文件。

done-flag是一种非常巧妙的标记文件已就绪的做法,可以说是已经是大数据领域里最为常见的一种“模式”。典型的例子是MR在执行任务结束时生成的_SUCCESS文件。

生成done-flag是如此普遍的需要,以至于hdfs的cli直接提供了命令用于生成done-flag文件,以及是一个例子:

#Create a flag file named _SUCCESS under a certain input folder.
hdfs dfs -touchz "/puth/to/input/folder/_SUCCESS"

相关内容