Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Apache ZooKeeper Essentials
Apache ZooKeeper Essentials

Apache ZooKeeper Essentials: A fast-paced guide to using Apache ZooKeeper to coordinate services in distributed systems

eBook
₹799.99 ₹1965.99
Paperback
₹2457.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Apache ZooKeeper Essentials

Chapter 2. Understanding the Inner Workings of Apache ZooKeeper

In the previous chapter, we learned about the general definition of a distributed system and why implementing coordination among components of such a system is hard. We learned how Apache ZooKeeper solves this problem, followed by how to install and configure it. In this chapter, we will read more about the internals and architecture of ZooKeeper. As such, we will cover the following topics here in this second chapter:

  • The architecture of the ZooKeeper service
  • The data model behind ZooKeeper
  • The operations supported by the ZooKeeper data model
  • Probing the inner workings of ZooKeeper

A top-down view of the ZooKeeper service

As you are aware, Apache ZooKeeper is a coordination service for distributed applications. It aims to solve the tough problems associated with the coordination of components in a distributed application. It does this by exposing a simple yet powerful interface of primitives. Applications can be designed on these primitives implemented through ZooKeeper APIs to solve the problems of distributed synchronization, cluster configuration management, group membership, and so on.

ZooKeeper is, in itself, a replicated and distributed application, with the intention to be run as a service, similar to the way we run DNS or any other centralized service. A view of the ZooKeeper service is shown in the following diagram:

A top-down view of the ZooKeeper service

A ZooKeeper service and how clients connect to the service

From the preceding diagram (the image is referenced from http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html), you will see the replicated set of servers on which the ZooKeeper service...

The ZooKeeper data model

As defined by the ZooKeeper wiki, ZooKeeper allows distributed processes to coordinate with each other through a shared hierarchical namespace of data registers. The namespace looks quite similar to a Unix filesystem. The data registers are known as znodes in the ZooKeeper nomenclature. You can see examples of znodes in the following image:

The ZooKeeper data model

A ZooKeeper's hierarchical namespace

Here, you can see that znodes are organized hierarchically, much like a tree, as a standard filesystem. Some important points to take note of are as follows:

  • The root node has one child znode called /zoo, which in turn has three znodes.
  • Every znode in the ZooKeeper tree is identified by a path, and the path elements are separated by /.
  • The znodes are called data registers because they can store data. Thus, a znode can have children as well as data associated with it. It's analogous to having a filesystem that allows a file to also be a path.

The data in a znode is typically stored in...

The ZooKeeper operations

ZooKeeper's data model and its API support the following nine basic operations:

Operation

Description

create

Creates a znode in a specified path of the ZooKeeper namespace

delete

Deletes a znode from a specified path of the ZooKeeper namespace

exists

Checks if a znode exists in the path

getChildren

Gets a list of children of a znode

getData

Gets the data associated with a znode

setData

Sets/writes data into the data field of a znode

getACL

Gets the ACL of a znode

setACL

Sets the ACL in a znode

sync

Synchronizes a client's view of a znode with ZooKeeper

Let's look at the ZooKeeper operations mentioned in the preceding table using ZooKeeper Java shell:

  1. Create a znode called root with ThisIsTheRootNode as its data:
    [zk: localhost(CONNECTED) 0] create /root "ThisIsTheRootNode"
    Created /root
    
  2. Get the content of the just created znode root:
    [zk: localhost(CONNECTED) 1] get /root
    "ThisIsTheRootNode"
    ...

Watches and ZooKeeper operations

The write operations in ZooKeeper are atomic and durable. There is the guarantee of a successful write operation if it has been written to persistent storage on a majority of ZooKeeper's servers. However, the eventual consistency model of ZooKeeper permits reads to log the latest state of the ZooKeeper service, and the sync operation allows a client to be up-to-date with the most recent state of the ZooKeeper service.

The read operations in znodes, such as exists, getChildren, and getData, allow watches to be set on them. On the other hand, the watches triggered by znode's write operations, such as create, delete, and setData ACL operations do not participate in watches.

The following are the types of watch events that might occur during a znode state change:

  • NodeChildrenChanged: A znode's child is created or deleted
  • NodeCreated: A znode is created in a ZooKeeper path
  • NodeDataChanged: The data associated with a znode is updated
  • NodeDeleted: A znode...

The ZooKeeper access control lists

ZooKeeper's data model provides a mechanism to control the access to znodes using ACL. While creating a znode, the ACLs determine the permissions with respect to the various operations that you can perform on the znodes. The ZooKeeper ACL model is similar to the Unix/Linux file permissions in terms of permitting or preventing operations being done on a znode by setting/unsetting permission bits. However, the ZooKeeper node doesn't have the concept of ownership, which is present in the Unix/Linux filesystem. ACLs are determined on the basis of the authentication mechanism of the client and the ZooKeeper service.

ZooKeeper provides the following built-in authentication mechanisms based on ACLs:

  • World: This represents anyone who is connecting to the ZooKeeper service
  • Auth: This represents any authenticated user, but doesn't use any ID
  • Digest: This represents the username and password way of authentication
  • IP address: This represents authentication...

The ZooKeeper stat structure

Every znode in ZooKeeper's namespace has a stat structure associated with it, which is analogous to the stat structure of files in a Unix/Linux filesystem. The fields in the stat structure of a znode are shown as follows with their respective meanings:

  • cZxid: This is the transaction ID of the change that caused this znode to be created.
  • mZxid: This is the transaction ID of the change that last modified this znode.
  • pZxid: This is the transaction ID for a znode change that pertains to adding or removing children.
  • ctime: This denotes the creation time of a znode in milliseconds from epoch.
  • mtime: This denotes the last modification time of a znode in milliseconds from epoch.
  • dataVersion: This denotes the number of changes made to the data of this znode.
  • cversion: This denotes the number of changes made to the children of this znode.
  • aclVersion: This denotes the number of changes made to the ACL of this znode.
  • ephemeralOwner: This is the session ID of the znode&apos...

A top-down view of the ZooKeeper service


As you are aware, Apache ZooKeeper is a coordination service for distributed applications. It aims to solve the tough problems associated with the coordination of components in a distributed application. It does this by exposing a simple yet powerful interface of primitives. Applications can be designed on these primitives implemented through ZooKeeper APIs to solve the problems of distributed synchronization, cluster configuration management, group membership, and so on.

ZooKeeper is, in itself, a replicated and distributed application, with the intention to be run as a service, similar to the way we run DNS or any other centralized service. A view of the ZooKeeper service is shown in the following diagram:

A ZooKeeper service and how clients connect to the service

From the preceding diagram (the image is referenced from http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html), you will see the replicated set of servers on which the ZooKeeper service...

The ZooKeeper data model


As defined by the ZooKeeper wiki, ZooKeeper allows distributed processes to coordinate with each other through a shared hierarchical namespace of data registers. The namespace looks quite similar to a Unix filesystem. The data registers are known as znodes in the ZooKeeper nomenclature. You can see examples of znodes in the following image:

A ZooKeeper's hierarchical namespace

Here, you can see that znodes are organized hierarchically, much like a tree, as a standard filesystem. Some important points to take note of are as follows:

  • The root node has one child znode called /zoo, which in turn has three znodes.

  • Every znode in the ZooKeeper tree is identified by a path, and the path elements are separated by /.

  • The znodes are called data registers because they can store data. Thus, a znode can have children as well as data associated with it. It's analogous to having a filesystem that allows a file to also be a path.

The data in a znode is typically stored in a byte format...

Left arrow icon Right arrow icon

Description

Whether you are a novice to ZooKeeper or already have some experience, you will be able to master the concepts of ZooKeeper and its usage with ease. This book assumes you to have some prior knowledge of distributed systems and high-level programming knowledge of C, Java, or Python, but no experience with Apache ZooKeeper is required.

Who is this book for?

Whether you are a novice to ZooKeeper or already have some experience, you will be able to master the concepts of ZooKeeper and its usage with ease.
Estimated delivery fee Deliver to India

Premium delivery 5 - 8 business days

₹630.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 28, 2015
Length: 168 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391324

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to India

Premium delivery 5 - 8 business days

₹630.95
(Includes tracking information)

Product Details

Publication date : Jan 28, 2015
Length: 168 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391324

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 4,915.98
YARN Essentials
₹2457.99
Apache ZooKeeper Essentials
₹2457.99
Total 4,915.98 Stars icon

Table of Contents

8 Chapters
1. A Crash Course in Apache ZooKeeper Chevron down icon Chevron up icon
2. Understanding the Inner Workings of Apache ZooKeeper Chevron down icon Chevron up icon
3. Programming with Apache ZooKeeper Chevron down icon Chevron up icon
4. Performing Common Distributed System Tasks Chevron down icon Chevron up icon
5. Administering Apache ZooKeeper Chevron down icon Chevron up icon
6. Decorating ZooKeeper with Apache Curator Chevron down icon Chevron up icon
7. ZooKeeper in Action Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(4 Ratings)
5 star 50%
4 star 25%
3 star 25%
2 star 0%
1 star 0%
Oliver Draese Jan 08, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good book to start ZK based development. Everything you need to know about ZK and surrounding APIs.
Amazon Verified review Amazon
The GuN Man Feb 03, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a very nice book for a starter who is exploring Zookeeper. It gets you up and running in few hours of skimming through the pages with so much simplicity. Being new to ZK, I started reading O'Reilly book and it seemed pretty dry and soon lost interest. But, when I started with this book, ZK seemed soo much simpler and got a more practical overview of ZK after reading first few pages. So, I continued reading till the end.Now that I've read this book, the O'Reilly book started making much more sense and I use it as a quick reference.I sort of agree with the @Anon's review in that, the O'reilly book is more authoritative and can be used as a reference. However, if you are new to the subject, read "Apache ZooKeeper Essentials" first.
Amazon Verified review Amazon
Dick Dowdell Oct 03, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
It's a decent book, but pretty thin on programming techniques and examples. Not a lot more than the ZooKeeper Programming section on the Hadoop Web site.
Amazon Verified review Amazon
Anon Feb 27, 2015
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Overall I think this is a worthy book. It is well written without a lot of filler. However the O'Reilly book is much better and more authoritative. Reading this one I was struck with déjà vu repeatedly since it reads like a summary of existing materials.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela