<a href="http://hadoop.apache.org/zookeeper/">http://hadoop.apache.org/zookeeper/</a>
Watches are ordered with respect to other events, other watches, and
asynchronous replies. The ZooKeeper client libraries ensures that
everything is dispatched in order.
A client will see a watch event for a znode it is watching before seeing the new data that corresponds to that znode.
The order of watch events from ZooKeeper corresponds to the order of the updates as seen by the ZooKeeper service.
那麼Zookeeper能幫我們作什麼事情呢?簡單的例子:假設我們我們有個20個搜尋引擎的伺服器(每個負責總索引中的一部分的搜尋任務)和一個總伺服器(負責向這20個搜尋引擎的伺服器發出搜尋請求并合并結果集),一個備用的總伺服器(負責當總伺服器當機時替換總伺服器),一個web的cgi(向總伺服器發出搜尋請求).搜尋引擎的伺服器中的15個伺服器現在提供搜尋服務,5個伺服器正在生成索引.這20個搜尋引擎的伺服器經常要讓正在提供搜尋服務的伺服器停止提供服務開始生成索引,或生成索引的伺服器已經把索引生成完成可以搜尋提供服務了.使用Zookeeper可以保證總伺服器自動感覺有多少提供搜尋引擎的伺服器并向這些伺服器發出搜尋請求,備用的總伺服器當機時自動啟用備用的總伺服器,web的cgi能夠自動地獲知總伺服器的網絡位址變化.這些又如何做到呢?
提供搜尋引擎的伺服器都在Zookeeper中建立znode,zk.create("/search/nodes/node1",
"hostname".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateFlags.EPHEMERAL);
總伺服器可以從Zookeeper中擷取一個znode的子節點的清單,zk.getChildren("/search/nodes", true);
總伺服器周遊這些子節點,并擷取子節點的資料生成提供搜尋引擎的伺服器清單.
當總伺服器接收到子節點改變的事件資訊,重新傳回第二步.
總伺服器在Zookeeper中建立節點,zk.create("/search/master", "hostname".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateFlags.EPHEMERAL);
備用的總伺服器監控Zookeeper中的"/search/master"節點.當這個znode的節點資料改變時,把自己啟動變成總伺服器,并把自己的網絡位址資料放進這個節點.
web的cgi從Zookeeper中"/search/master"節點擷取總伺服器的網絡位址資料并向其發送搜尋請求.
web的cgi監控Zookeeper中的"/search/master"節點,當這個znode的節點資料改變時,從這個節點擷取總伺服器的網絡位址資料,并改變目前的總伺服器的網絡位址.
在我的測試中:一個Zookeeper的叢集中,3個Zookeeper節點.一個leader,兩個follower的情況下,停掉leader,然後兩個follower選舉出一個leader.擷取的資料不變.我想Zookeeper能夠幫助Hadoop做到:
Hadoop,使用Zookeeper的事件處理確定整個叢集隻有一個NameNode,存儲配置資訊等.
HBase,使用Zookeeper的事件處理確定整個叢集隻有一個HMaster,察覺HRegionServer聯機和當機,存儲通路控制清單等.
Zookeeper Doc:
<a href="http://wiki.apache.org/hadoop-data/attachments/ZooKeeper(2f)ZooKeeperPresentations/attachments/zookeeper.pdf">zookeeper.pdf</a>