Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Big data's zookeeper of Ecology (carding of knowledge points)

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1.zookeeper introduction

(1) introduction to zookeeper:

Zookeeper is a distributed, open source distributed application coordination service, which is an open source implementation of Google's chubby.

It provides simple and primitive functions, based on which distributed applications can implement higher services, such as distributed synchronization, configuration management, and cluster management.

Naming management, queue management. It is designed to be easy to program, using the file system directory tree as the data model. The server runs on java and provides client API of java and C.

Zookeeper is the manager of the cluster, monitoring the status of each node in the cluster and performing one-step reasonable operation according to the feedback provided by the node. Eventually, an easy-to-use interface

And the system with stable function and efficient performance is provided to users.

Official website address:

Http://ZooKeeper.apache.org/

Quick start address on the official website:

Http://ZooKeeper.apache.org/doc/trunk/ZooKeeperStarted.html

API address of the official website:

Http://ZooKeeper.apache.org/doc/r3.4.10/api/index.html

Related functions of 2.zookeeper

(1) File system:

The namespace of ZooKeeper is the file system applied by ZooKeeper, which is very similar to the file system of linux. It is also a tree, so you can make sure that each path is unique.

Operations on namespaces must all be absolute path operations. Unlike the Linux file system, the Linux file system has the difference between directories and files, while ZooKeeper is called znode

A znode node can contain child znode as well as data.

Znode is both a folder and a file concept, so in ZooKeeper, it is neither a file text nor a folder, it is called znode, and each znode has a unique path.

You can both store data and create sub-znode. But znode is only suitable for storing very small data, no more than 1m, preferably less than 1K.

Features of zookeeper's file system:

Zk's file system is the same as Linux's file system directory structure, starting with "" /

The access path of zk has only absolute path and no relative path.

There is no concept of file and directory in zk, only znode node. Znode has both file function and directory function.

(2) znode introduction:

There are two types of znode: temporary (deleted when broken) and persistent (retained when broken). But znode has four forms of node representation:

Persistent persists the znode node. Once the znode node is created, the stored data will not disappear actively, unless the client actively deletePersistent_sequential automatically increases the sequentially numbered znode node. For example, ClientA goes to zk service to create a znode named / zk/conf, which specifies

After this type of node, zk will create / zk/conf0000000000, and ClientB will create / zk/conf0000000001.

ClientC is to create / zk/conf0000000002, and any Client to create this znode in the future will get a better result than the current zk namespace.

Znode with large znode number + 1, that is to say, any Client to create a znode ensures that the znode is incremented and is

The only one. (atomicity principle) Ephemral temporary znode node. When client connects to zkservice, a session is established, and then the zk connection instance is used to create this type of znode.

Once the client closes the connection to the zk, the server clears the session, and then the znode nodes established by the session are all from the namespace

disappear. Ephemral_ sequential temporary automatic numbering setting, the znode node number will automatically increase, but will disappear as the session disappears.

Related features of zookeeper's znode:

The sequence identity is set when the znode is created, a value is appended to the znode name, and the sequence number is a monotonously increasing counter maintained by the parent node. (whether or not a numbered node is created, it is incremented sequentially)

A node of type EPHEMERAL cannot have child nodes

Classification of znode of zk: temporary node (EPHEMERAL), permanent node (persistent), numbered node (Persistent_sequential), temporary numbered node (Ephemral_ sequential)

For zk, the data stored in its znode cannot exceed 1m, and it is best not to exceed 1KB. If the amount of data is relatively large, it is difficult to ensure the consistency of the data.

For zk, several copies of data are stored on several nodes.

Snooping Mechanism of 3.zookeeper

(1) introduction to the monitoring mechanism:

The client registers to listen to the directory node it cares about, and zookeeper notifies the client when the directory node changes (data change, node deletion, subdirectory node addition and deletion).

The listening mechanism ensures that any change in any data saved by zookeeper can quickly respond to the application that listens to the node. The working mechanism of the listener is actually a special meeting on the client side.

Create a listener thread and wait on a local port for an event from the zk cluster.

(2) trigger of monitoring

The creation of Znode-nodeCreated

Znode deleted-nodeDelete

Data change of Znode-nodedatachanged

Changes in child nodes of Znode-nodeChildrenchange

Note: monitoring only works once. (you can use loop monitoring to monitor all the time.)

(3) the working principle of the monitoring mechanism.

Explanation: the Watcher mechanism of ZooKeeper mainly includes three parts: client thread, client WatcherManager and Zookeeper server. The client is calling the zookeeper server

When registering, the Watcher object is stored in the client's WatcherManager. When the zookeeper server triggers the watcher event, it sends a notification to the client

The client thread fetches the corresponding Watcher object from the WatcherManager to execute the callback logic.

(4) Monitoring settings:

Corresponding trigger:

Ls-- trigger-create, delete (child node)

Get-- trigger-set

Exists-- trigger-create, delete (current node)

4. Characteristics of Zookeeper

Ultimate consistency: no matter which server client connects to, it shows him the same view, which is the most important and specific feature of zookeeper.

Reliability: with simple, robust, good performance, if message M is received by one server, it will be accepted by all servers.

Real-time: ZooKeeper ensures that the client will get the update information of the server or the information of server failure within a time interval. However, due to network delay and other reasons

ZooKeeper cannot guarantee that both clients will get the newly updated data at the same time. If you need the latest data, you should call the sync () interface before reading the data.

Waiting is irrelevant: slow or invalid client must not interfere with fast client requests so that each client can wait effectively.

Atomicity: updates can only succeed or fail, with no intermediate state.

Ordering: including global ordering and partial ordering: global ordering means that if message an is published before message b on a server, message a will be published before message b on all Server

Partial order means that if a message b is published by the same sender after message a, a must rank before b.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report