2017-10-29 90 views
0

我必須實現一個map-reduce作業循環。每次迭代將根據前一次迭代終止或繼續。要做出的選擇是基於「在減速器輸出中出現一個詞」。Reducer可以在Hadoop mapreduce中傳遞給驅動程序的消息嗎?

當然,我可以用我的驅動程序檢查整個輸出txt文件。但它只是一個單詞,並且通過整個文件將會矯枉過正。我正在考慮是否有任何方法來建立減速器和驅動程序之間的通信,一旦它檢測到這個詞,減速器可以通知驅動程序?由於要傳輸的消息很少。

+2

Mapreduce支持「計數器」的概念。或者,您可能想嘗試使用Spark,以便將您正在構建到工作流而非循環中的「DAG任務」 –

回答

-1

您的解決方案將不是一個乾淨的解決方案,難以維護。

有多種方法可以實現您的要求。

1. Reducer as soon as it finds a word writes to a HDFS location (opens file on hdfs predefine filedir and writes there) 
2. client keeps polling the predefined filedir/output dir of the job. If the output dir is found and there is no filedir it means word wasnt there. 
3. Use Zookeper 

最佳的解決方案是,只有當這個詞被發現從映射器發出, 否則不會發出任何東西。這將加快你的工作,併產生一個單一的減速機。現在您可以安全地檢查作業的輸出是否有任何文件輸出。使用惰性初始化,如果沒有行到reducer沒有輸出文件將被創建

相關問題