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
AU$24.99 AU$36.99
Paperback
AU$45.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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.

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 : 9781784398323

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 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
AU$249.99 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 AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 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 AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 91.98
YARN Essentials
AU$45.99
Apache ZooKeeper Essentials
AU$45.99
Total AU$ 91.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.