[] Zookeeper distributed solutions acquaintance

First, what is Zookeeper?

The official explanation on the document so zookeeper:

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them, which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these types of services are using some form of distributed applications. Each implementation they have a lot of work needs to be done to fix the inevitable errors and competitive conditions. Since it is difficult to achieve these types of services, applications, initially it will usually mean them, which makes them vulnerable in case of change and difficult to manage. Even if done correctly, these services can lead to different implementations manage complexity when deploying an application.

When first contacted Zookeeper and saw this large segment, then, to be honest I was forced to look ignorant, that's what I do not understand ah ...... then I went through a lot of information, and then did some summary , Zookeeper can be summed up with the following sentence:

zookeeper = + monitor file system notification mechanism.

1.1 File System

Zookeeper maintain a data structure similar to the file system:

Each subdirectory 00216 app1 are referred to as znode (directory node), and the file system, we can freely add, delete znode, increases at a znode, delete sub znode, the only difference is that znode can store data .

Zookeeper two types of nodes:

  • Persistence node

  • Temporary node

To be further broken down into four categories:

• PERSISTENT-持久化目录节点
复制代码

After the client disconnected zookeeper, the node is still present

• PERSISTENT_SEQUENTIAL-持久化顺序编号目录节点
复制代码

After zookeeper client is disconnected, the node is still present, but Zookeeper numbered sequentially to the node name

• EPHEMERAL-临时目录节点
复制代码

After the client disconnected zookeeper, the node is deleted

• EPHEMERAL_SEQUENTIAL-临时顺序编号目录节点
复制代码

After zookeeper client is disconnected, the node is deleted, but Zookeeper numbered sequentially to the node name

1.2 monitor notification mechanism

The client registers its concern to monitor directory node, when the node directory changes (change data is deleted, delete the subdirectory node increases), zookeeper will notify the client.

Second, what Zookeeper do?

Zookeeper is already more than a brief introduction of what looks like a file storage system and listening notification mechanism with what configuration center, registration center, cluster management, distributed coordination eight-pole beat ah, absolutely can not contact them.

Do not worry, we first look at a set of terms:

• Znode
每个节点称做一个ZNode。每个ZNode都可以通过其路径唯一标识,同时每个节点还可以存储少量数据。
节点可分为常规节点,临时节点和顺序节点

• Session
每个zk客户端与zk连接时会创建一个session,在设置的sessionTimeOut内,客户端会与zk进行心跳包的定时发送,从而感知每个客户端是否宕机,如果创建某个临时Znode的对应session销毁时,相应的临时节点也会被zk删除。

• Watcher
监听机制,监听某个Znode 当该znode发生变化时,会回调该watcher,但是这个watcher是一次性的,下次需要监听时还得再注册一次。

• 强一致性
分布式存储系统中对数据事务的描述,表示所有节点的数据将保持一致,Zookeeper能够保证集群部署时,各节点的数据保持一致。
复制代码

Carefully think about, seemingly can do a lot of things:

  • Since it can store information, but also to do the monitoring, it can be used as publish - subscribe system to use;

  • Connecting clients with zk is a session, you can use to listen for client Zookeeper state

  • Zookeeper create temporary node will be deleted when the session is closed, you can use to save some Zookeeper strong correlation with client data, automatically cleared after synchronization to the relevant node.

Due to space issues herein, this does not describe in detail how to achieve, the next one will be described.

Original works, please indicate the source. Learning materials: zookeeper.apache.org/

Reproduced in: https: //juejin.im/post/5cfe0076e51d45105e021294

Guess you like

Origin blog.csdn.net/weixin_34119545/article/details/91454821