Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JCConf 2016 zookeeper

Shihyu Ho
October 18, 2016

JCConf 2016 zookeeper

Shihyu Ho

October 18, 2016
Tweet

More Decks by Shihyu Ho

Other Decks in Programming

Transcript

  1. About me ▸ 何適宇 <Matt> ▸ [email protected] ▸ https://github.com/methodho ▸

    https://www.facebook.com/evermatt ▸ 松凌科技 <http://www.softleader.com.tw/>
  2. ⼤大綱 ▸ ZooKeeper 介紹 ▸ 使⽤用 ZooKeeper 前的⽅方法 ▸ Java

    programming to ZooKeeper ▸ o.a.z.ZooKeeper (3.4.9) ▸ o.a.c.f.r.l.LeaderLatch (2.11.0)
  3. ▸ 啟動server ▸ /bin/zkServer.sh start ▸ 連結到 zookeeper server ▸

    /bin/zkCli.sh [-server localhost:2181] ▸ 關閉server ▸ /bin/zkServer.sh stop ZOOKEEPER CLI
  4. ▸ 新增 znode ▸ create [-s] [-e] path data ▸

    刪除 znode ▸ delete path ▸ rmr path ZOOKEEPER CLI
  5. ▸ 列列出 znode 下的 children ▸ ls path [watch] ▸

    ls2 path [watch] ▸ 讀寫 znode data (byte[]) ▸ set path data [watch] ▸ get path [watch] ZOOKEEPER CLI
  6. BEFORE ZOOKEEPER ▸ 由ap⾃自⼰己控制 ▸ hardcode ▸ properties ▸ passes

    argument ... ▸ cons? AP1 (run = false) AP3 (run = false) AP2 (run = true)
  7. IMPLEMENTING LEADER ELECTION Start (1) Connect to zookeeper server (2)

    Create parent if not exist (3) Create -e -s node z Node j found End (6) You are leader (7) Watch for node j Y N (5) Find node j , where j is the largest seq and j < z (4) Get and sort all children Node j deleted
  8. IMPLEMENTING LEADER ELECTION Start (1) Connect to zookeeper server (2)

    Create parent if not exist (3) Create -e -s node z Node j found End (6) You are leader (7) Watch for node j Y N (5) Find node j , where j is the largest seq and j < z (4) Get and sort all children Node j deleted
  9. PROGRAMMING TO ZOOKEEPER (4) Get and sort all children (5)

    Find node j , where j is the largest seq and j < z
  10. ADAPTING INTO SCHEDULE FRAMEWORK ADAPTING INTO SCHEDULE FRAMEWORK @Scheduled methods

    @EnableScheduling ScheduledAnnotation BeanPostProcessor Find & register TaskScheduler [default implementation] ThreadPoolTaskScheduler To be invoked by java.util.concurrent.Scheduled ExecutorService ScheduledMethodRunnable(bean, method) Register
  11. ADAPTING INTO SCHEDULE FRAMEWORK ADAPTING INTO SCHEDULE FRAMEWORK TaskScheduler decorator

    Original TaskScheduler [default implementation] ThreadPoolTaskScheduler ZooKeeper Server
  12. LEADER ELECTION Zookeeper Server / /SOME-PATH /ZNODE_1 CLIENT_1 80% /ZNODE_2

    CLIENT_2 10% /ZNODE_3 CLIENT_3 55% 看看誰的系統資源 使⽤用率最低的就去 執⾏行行吧