Zookeeper quota管理

Zookeeper的quota机制可以设置节点个数及空间大小

语法

setquota -n|-b val path    # 设置节点quota信息
listquota path             # 获取节点quota信息
deletequota                # 删除节点quota信息

注:-n 表示最大子节点个数(包括节点本身)

        -b  表示该节点空间大小(byte)

 

设置节点quota

举例

[zk: localhost:2181(CONNECTED) 1] create /quota quota        # 创建节点
Created /quota
[zk: localhost:2181(CONNECTED) 4] listquota /quota
absolute path is /zookeeper/quota/quota/zookeeper_limits     # 获取节点quota信息,提示不存在
quota for /quota does not exist.
  • 限制子节点个数
[zk: localhost:2181(CONNECTED) 5] setquota -n 3 /quota       # 设置最大子节点个数为3
[zk: localhost:2181(CONNECTED) 6] listquota /quota
absolute path is /zookeeper/quota/quota/zookeeper_limits
Output quota for /quota count=3,bytes=-1                     # -1表示无限制
Output stat for /quota count=1,bytes=5

接下来我们测试一下,创建多个子节点

[zk: localhost:2181(CONNECTED) 7] create /quota/child1
Created /quota/child1
[zk: localhost:2181(CONNECTED) 8] create /quota/child2
Created /quota/child2
[zk: localhost:2181(CONNECTED) 9] create /quota/child3
Created /quota/child3
[zk: localhost:2181(CONNECTED) 10] create /quota/child4
Created /quota/child4

结果发现好像并没有什么作用,其实看一下日志即可发现,日志中会有警告信息,但是并不影响创建节点

从日志中可以发现,当我们创建第三个子节点child3时,便开始警告,count=4,这是因为quota节点本身也算一个。

  • 限制节点空间大小

[zk: localhost:2181(CONNECTED) 11] setquota -b 100 /quota
org.apache.commons.cli.AlreadySelectedException: The option 'b' was specified but an option from this group has already been selected: 'n'

嗯,提示已经存在了quota信息 -n,难道是因为我们之前设置的-n原因?换个节点

[zk: localhost:2181(CONNECTED) 13] create /quota1
Created /quota1
[zk: localhost:2181(CONNECTED) 14] setquota -b 100000 /quota1
org.apache.commons.cli.AlreadySelectedException: The option 'b' was specified but an option from this group has already been selected: 'n'

额…… 依然不行……

删除quota信息

[zk: localhost:2181(CONNECTED) 2] listquota /quota
absolute path is /zookeeper/quota/quota/zookeeper_limits
Output quota for /quota count=3,bytes=-1
Output stat for /quota count=5,bytes=5
[zk: localhost:2181(CONNECTED) 3] delquota /quota
[zk: localhost:2181(CONNECTED) 4] redo 2
absolute path is /zookeeper/quota/quota/zookeeper_limits
quota for /quota does not exist.

 

 

你可能感兴趣的:(zookeeper,quota,节点,Zookeeper学习笔记)