zookeeper 基本概念

The ZooKeeper Data Model

ZooKeeper has a hierarchal name space, much like a distributed file system. The only difference is that each node in the namespace can have data associated with it as well as children. It is like having a file system that allows a file to also be a directory. Paths to nodes are always expressed as canonical, absolute, slash-separated paths; there are no relative reference. Any unicode character can be used in a path subject to the following constraints:

  • The null character (\u0000) cannot be part of a path name. (This causes problems with the C binding.)
  • The following characters can‘t be used because they don‘t display well, or render in confusing ways: \u0001 - \u0019 and \u007F - \u009F.
  • The following characters are not allowed: \ud800 -uF8FFF, \uFFF0-uFFFF, \uXFFFE - \uXFFFF (where X is a digit 1 - E), \uF0000 - \uFFFFF.
  • The "." character can be used as part of another name, but "." and ".." cannot alone be used to indicate a node along a path, because ZooKeeper doesn‘t use relative paths. The following would be invalid: "/a/b/./c" or "/a/b/../c".
  • The token "zookeeper" is reserved.

ZNodes

Every node in a ZooKeeper tree is referred to as a znode. Znodes maintain a stat structure that includes version numbers for data changes, acl changes. The stat structure also has timestamps. The version number, together with the timestamp allow ZooKeeper to validate the cache and to coordinate updates. Each time a znode‘s data changes, the version number increases. For instance, whenever a client retrieves data, it also receives the version of the data. And when a client performs an update or a delete, it must supply the version of the data of the znode it is changing. If the version it supplies doesn‘t match the actual version of the data, the update will fail.

Ephemeral Nodes(临时的znode)

ZooKeeper also has the notion(概念) of ephemeral(暂时的) nodes. These znodes exists as long as the session that created the znode is active. When the session ends the znode is deleted. Because of this behavior ephemeral znodes are not allowed to have children.

Persistent Nodes(永久性的znode)

永久有效地节点,除非client显式的删除,否则一直存在

Sequence Nodes(顺序性的znode)

顺序节点,client申请创建该节点时,zk会自动在节点路径末尾添加递增序号

Access Control List (ACL)

访问控制列表

The data stored at each znode in a namespace is read and written atomically(原子的). Reads get all the data bytes associated with a znode and a write replaces all the data. Each node has an Access Control List (ACL) that restricts(限制) who can do what.


ZooKeeper access control using ACLs

ZooKeeper uses ACLs to control access to its znodes (the data nodes of a ZooKeeper data tree). The ACL implementation is quite similar to UNIX file access permissions: it employs permission bits to allow/disallow various operations against a node and the scope to which the bits apply. Unlike standard UNIX permissions, a ZooKeeper node is not limited by the three standard scopes for user (owner of the file), group, and world (other). ZooKeeper does not have a notion of an owner of a znode. Instead, an ACL specifies sets of ids and permissions that are associated with those ids.

Note also that an ACL pertains only to a specific znode. In particular it does not apply to children. For example, if /app is only readable by ip:172.16.16.1 and /app/status is world readable, anyone will be able to read /app/status; ACLs are not recursive(递归).

ZooKeeper supports pluggable authentication schemes. Ids are specified using the form scheme:id, where scheme is a the authentication scheme that the id corresponds to. For example, ip:172.16.16.1 is an id for a host with the address 172.16.16.1.

When a client connects to ZooKeeper and authenticates itself, ZooKeeper associates all the ids that correspond to a client with the clients connection. These ids are checked against the ACLs of znodes when a clients tries to access a node. ACLs are made up of pairs of (scheme:expression, perms). The format of the expression is specific to the scheme. For example, the pair (ip:19.22.0.0/16, READ) gives the READ permission to any clients with an IP address that starts with 19.22.

ACL Permissions

ZooKeeper supports the following permissions:

  • CREATE: you can create a child node
  • READ: you can get data from a node and list its children.
  • WRITE: you can set data for a node
  • DELETE: you can delete a child node
  • ADMIN: you can set permissions

The CREATE and DELETE permissions have been broken out of the WRITE permission for finer grained access controls. The cases for CREATE and DELETE are the following:

You want A to be able to do a set on a ZooKeeper node, but not be able to CREATE or DELETE children.

CREATE without DELETE: clients create requests by creating ZooKeeper nodes in a parent directory. You want all clients to be able to add, but only request processor can delete. (This is kind of like the APPEND permission for files.)

Also, the ADMIN permission is there since ZooKeeper doesn’t have a notion of file owner. In some sense the ADMIN permission designates the entity as the owner. ZooKeeper doesn’t support the LOOKUP permission (execute permission bit on directories to allow you to LOOKUP even though you can‘t list the directory). Everyone implicitly has LOOKUP permission. This allows you to stat a node, but nothing more. (The problem is, if you want to call zoo_exists() on a node that doesn‘t exist, there is no permission to check.)

ZooKeeper Stat Structure

如下查看znode的stat的信息,

[zk: localhost:2181(CONNECTED) 5] stat /zk_test
cZxid = 0x600000004
ctime = Mon Mar 16 17:51:58 CST 2015
mZxid = 0x600000004
mtime = Mon Mar 16 17:51:58 CST 2015
pZxid = 0x600000004
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0

The Stat structure for each znode in ZooKeeper is made up of the following fields:

czxid

The zxid of the change that caused this znode to be created.

mzxid

The zxid of the change that last modified this znode.

ctime

The time in milliseconds from epoch when this znode was created.

mtime

The time in milliseconds from epoch when this znode was last modified.

version

The number of changes to the data of this znode.

cversion

The number of changes to the children of this znode.

aversion

The number of changes to the ACL of this znode.

ephemeralOwner

The session id of the owner of this znode if the znode is an ephemeral node. If it is not an ephemeral node, it will be zero.

dataLength

The length of the data field of this znode.

numChildren

The number of children of this znode.

zxid

Every change to the ZooKeeper state receives a stamp in the form of a zxid (ZooKeeper Transaction Id). This exposes the total ordering of all changes to ZooKeeper. Each change will have a unique zxid and if zxid1 is smaller than zxid2 then zxid1 happened before zxid2.

====================================END====================================

时间: 2024-11-01 11:31:59

zookeeper 基本概念的相关文章

zookeeper基本概念和功能

2019/2/19 星期二 zookeeper基本概念和功能 zookeeper是hadoop生态圈里面重要的底层的框架,主要为上层的框架提供分布式协调服务的. hadoop-spof 问题及HA 解决思路引入集群协调服务框架的必要性 zookeeper 简介ZooKeeper 是一个分布式应用程序协调服务,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等.目前zookeeper 被广泛应用于hadoop 生态体系中各种框架的分布式协调,我们也可以利用zookeeper 来简化分布式应

1、ZooKeeper 基本概念、使用方法、实践场景

ZooKeeper 基本概念 ZooKeeper 是面向分布式应用的协调服务,其实现了树形结构的数据模型(与文件系统类似),并且提供了简洁的编程原语.ZooKeeper 能够作为基础,用于构建更高层级的分布式服务. ZooKeeper 是分布式的,具备高性能.高可用的特点. 如上架构图所示,ZooKeeper 集群中包括: Leader:提供 “读” & “写” 服务(Leader 由集群全部机器通过“Leader 选举”产生). Follower:集群中非 “Leader” 的其他节点. 集群

zookeeper基本概念及原理

zookeeper是一个分布式的,开源的分布式应用程序,该程序主要用于管理其他分布式应用程序.其他分布式应用程序可以基于zookeeper实现数据同步,配置维护和命名服务等等.zookeeper是Hadoop的一个子项目,由于在原有的分布式应用系统中,工程师不能很好的使用锁机制,或者基于消息的协调机制不适合在某些应用中使用,因此需要一种可靠的,可扩展的,分布式的,可配置的协调机制来统一系统的状态,Zookeeper的作用就在于此.本文简单介绍Zookeeper的相关名词概念,然后简单介绍其工作原

二:ZooKeeper术语概念

zookeeper的基本概念介绍Zookeeper的几个核心概念,这些概念贯穿于本书之后对ZooKeeper更深入的讲解,因此有必要预先了解这些概念. ●集群角色一:集群角色          通常在分布式系统中,构成一个集群的每一台机器都有自己的角色,最典型的集群模式就是Master/Slave模式(主备模式).在这种模式中,我们把能够处理所有写操作的机器称为Master机器,把所有通过异步复制方式获取最新数据,并提供读服务的机器称为Salve机器.        而在ZooKeeper中,这

ZooKeeper分布式过程协同技术详解1——ZooKeeper的概念和基础

简介 分布式系统和应用,不仅能提供更强的计算能力,还能为我们提供更好的容灾性和扩展性. ZooKeeper是Google的Chubby项目的开源实现,它曾经作为Hadoop的子项目,在大数据领域得到广泛应用 ZooKeeper以Fast Paxos算法为基础,同时为了解决活锁问题,对Fast Paxos算法进行了优化,因此也可以广泛用于大数据之外的其他分布式系统,为大型分布式系统提供可靠的协作处理功能. Apache ZooKeeper旨在减轻构建健壮的分布式系统的任务.ZooKeeper基于分

Zookeeper基础概念和原理

1.zookeeper概念介绍 在介绍ZooKeeper之前,先来介绍一下分布式协调技术,所谓分布式协调技术主要是用来解决分布式环境当中多个进程之间的同步控制,让他们有序的去访问某种共享资源,防止造成资源竞争(脑裂)的后果. 这里首先介绍下什么是分布式系统,所谓分布式系统就是在不同地域分布的多个服务器,共同组成的一个应用系统来为用户提供服务,在分布式系统中最重要的是进程的调度,这里假设有一个分布在三个地域的服务器组成的一个应用系统,在第一台机器上挂载了一个资源,然后这三个地域分布的应用进程都要竞

ZooKeeper 系列(一)—— ZooKeeper核心概念详解

一.Zookeeper简介 二.Zookeeper设计目标 三.核心概念 ????????3.1 集群角色 ????????3.2 会话 ????????3.3 数据节点 ????????3.4 节点信息 ????????3.5 Watcher ????????3.6 ACL 四.ZAB协议 ????????4.1 ZAB协议与数据一致性 ????????4.2 ZAB协议的内容 五.Zookeeper的典型应用场景 ????????5.1数据的发布/订阅 ????????5.2 命名服务 ??

Zookeeper简单概念介绍

过去,每个应用都是一个CPU.一个主机上的单一系统.然而今天,随着大数据和云计算时代的到来,不论什么相互独立的程序都可以运行在多个计算机上.然而面临的问题是,协调这些集群的系统比在单一主机上要复杂的多.因此对于开发人员来说.非常难在集中精力来关注他们的系统逻辑上,大部分的时间都花费在了协调这些集群系统上.Zookeeper的出现就攻克了这个问题,让开发人员可以集中精力在系统逻辑上,而免于协调这些集群计算机的运行情况.Zookeeper暴漏了一套简单的额API,可以让开发人员实现公共须要协调的任务

Paxos分布式一致性算法简介和Apache ZooKeeper的概念映射

Paxos是一个基于消息传递的一致性算法,近几年被广泛应用于分布式计算中,Google的Chubby,Apache的Zookeeper都是基于它的理论来实现的,Paxos还被认为是到目前为止唯一的分布式一致性算法,其它的算法都是Paxos的改进或简化.Paxos只有在一个可信的计算环境中才能成立,这个环境是不会被入侵所破坏的. 由Leslie Lamport发明了Paxos算法,他目前供职于微软研究院.1998年在ACM Transactions on Computer Systems的<The