ZKEssentials读书笔记(六) - 18965050/ZookeeperEssentials GitHub Wiki


  • Curator组件
  • Curator ZooKeeper Client
  • Curator框架
  • Curator ZooKeeper Recipes

Curator组件

Curator组件包括:

  • client: 对ZooKeeper Java client API的封装.是低阶(low-level)的API
  • framework: 高阶(high-level)的API
  • recipes: 各种ZooKeeper能实现的处方
  • extensions: curator recipe只实现了通用的recipes, 其他的可通过extension来实现

curator-stack

Curator Client

curator client提供了如下的特性:

  • 连接管理
  • 重试功能
  • 测试ZK Server

CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy)

  • connectString: 连接字符串
  • sessionTimeoutMs: 会话超时
  • connectionTimeoutMs: 连接超时
  • watcher: watcher配置
  • retryPolicy: 重试策略.包括
    • BoundedExponentialBackoffRetry: 每次retry都会等待一个递增的时间间隔,直到达到retry次数或时间间隔达到设定值
    • ExponentialBackoffRetry:每次retry都会等待一个递增的时间间隔,直到达到retry次数
    • RetryNTimes: retry N次
    • RetryOneTime: 只retry一次
    • RetryUntilElapsed: retry直到达到设定的时间值

Curator框架

curator框架提供如下功能:

  • 自动连接管理
  • 简单灵活API
  • 丰富的Recipes

Curator Recpies

  • leader election:curator提供了两种选举方式.
    • leader latch: 随机选举
    • leader selector: 根据请求server的顺序选举
  • lock: curator提供了多张锁实现
    • Shared re-entrant lock: 共享可重入锁
    • Shared lock: 共享锁
    • Shared re-entrant read/write lock: 共享可重入读写锁
    • Shared semaphore: 共享信号量
    • Multishared lock: 多共享锁(将所有锁作为一个锁整体看待,一个acquire操作可获取所有锁).
  • barrier: curator提供了屏障(barrier)和双头屏障(double barrier)
  • Counters: 计数器
  • cache: 包括路径缓存(path-cache),节点缓存(node-cache)和数缓存(tree-cache)
  • queues: 包括
    • Distributed queue: 简单的FIFO分布式队列
    • Distributed ID queue: 是Distributed queue的一种特殊形态, 允许标识符关联到队列元素
    • Distributed priority queue
    • Distributed delay queue
    • Simple distributed queue

Curator工具

curator提供了很多实用的工具,用于:

  • testing server
  • testing cluster
  • ZKPaths
  • EnsurePath:确保znode节点实用前被创建
  • BlockingQueueConsumer
  • Reaper: 删除没有子目录和数据的节点

Curator扩展

curator extension包含其他的recipes.命名规则为: curator-x-name 目前已有的扩展包括:

  • 服务发现
  • 服务发现server: REST风格的服务发现用于非Java语言
  • Curator RPC proxy
  • ZKClient bridge

Exhibitor