O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required


Book Description

Building distributed applications is difficult enough without having to coordinate the actions that make them work. This practical guide shows how Apache ZooKeeper helps you manage distributed systems, so you can focus mainly on application logic. Even with ZooKeeper, implementing coordination tasks is not trivial, but this book provides good practices to give you a head start, and points out caveats that developers and administrators alike need to watch for along the way.

In three separate sections, ZooKeeper contributors Flavio Junqueira and Benjamin Reed introduce the principles of distributed systems, provide ZooKeeper programming techniques, and include the information you need to administer this service.

  • Learn how ZooKeeper solves common coordination tasks
  • Explore the ZooKeeper API’s Java and C implementations and how they differ
  • Use methods to track and react to ZooKeeper state changes
  • Handle failures of the network, application processes, and ZooKeeper itself
  • Learn about ZooKeeper’s trickier aspects dealing with concurrency, ordering, and configuration
  • Use the Curator high-level interface for connection management
  • Become familiar with ZooKeeper internals and administration tools

Table of Contents

  1. Preface
    1. Audience
    2. Contents of This Book
    3. Conventions Used in this Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  2. I. ZooKeeper Concepts and Basics
  3. 1. Introduction
    1. The ZooKeeper Mission
      1. How the World Survived without ZooKeeper
      2. What ZooKeeper Doesn’t Do
      3. The Apache Project
      4. Building Distributed Systems with ZooKeeper
    2. Example: Master–Worker Application
      1. Master Failures
      2. Worker Failures
      3. Communication Failures
      4. Summary of Tasks
    3. Why Is Distributed Coordination Hard?
    4. ZooKeeper Is a Success, with Caveats
  4. 2. Getting to Grips with ZooKeeper
    1. ZooKeeper Basics
      1. API Overview
      2. Different Modes for Znodes
      3. Watches and Notifications
      4. Versions
    2. ZooKeeper Architecture
      1. ZooKeeper Quorums
      2. Sessions
    3. Getting Started with ZooKeeper
      1. First ZooKeeper Session
      2. States and the Lifetime of a Session
      3. ZooKeeper with Quorums
      4. Implementing a Primitive: Locks with ZooKeeper
    4. Implementation of a Master–Worker Example
      1. The Master Role
      2. Workers, Tasks, and Assignments
      3. The Worker Role
      4. The Client Role
    5. Takeaway Messages
  5. II. Programming with ZooKeeper
  6. 3. Getting Started with the ZooKeeper API
    1. Setting the ZooKeeper CLASSPATH
    2. Creating a ZooKeeper Session
      1. Implementing a Watcher
      2. Running the Watcher Example
    3. Getting Mastership
      1. Getting Mastership Asynchronously
      2. Setting Up Metadata
    4. Registering Workers
    5. Queuing Tasks
    6. The Admin Client
    7. Takeaway Messages
  7. 4. Dealing with State Change
    1. One-Time Triggers
      1. Wait, Can I Miss Events with One-Time Triggers?
    2. Getting More Concrete: How to Set Watches
    3. A Common Pattern
    4. The Master–Worker Example
      1. Mastership Changes
      2. Master Waits for Changes to the List of Workers
      3. Master Waits for New Tasks to Assign
      4. Worker Waits for New Task Assignments
      5. Client Waits for Task Execution Result
    5. An Alternative Way: Multiop
    6. Watches as a Replacement for Explicit Cache Management
    7. Ordering Guarantees
      1. Order of Writes
      2. Order of Reads
      3. Order of Notifications
    8. The Herd Effect and the Scalability of Watches
    9. Takeaway Messages
  8. 5. Dealing with Failure
    1. Recoverable Failures
      1. The Exists Watch and the Disconnected Event
    2. Unrecoverable Failures
    3. Leader Election and External Resources
    4. Takeaway Messages
  9. 6. ZooKeeper Caveat Emptor
    1. Using ACLs
      1. Built-In Authentication Schemes
      2. SASL and Kerberos
      3. Adding New Schemes
    2. Session Recovery
    3. Version Is Reset When Znode Is Re-Created
    4. The sync Call
    5. Ordering Guarantees
      1. Order in the Presence of Connection Loss
      2. Order with the Synchronous API and Multiple Threads
      3. Order When Mixing Synchronous and Asynchronous Calls
    6. Data and Child Limits
    7. Embedding the ZooKeeper Server
    8. Takeaway Messages
  10. 7. The C Client
    1. Setting Up the Development Environment
    2. Starting a Session
    3. Bootstrapping the Master
    4. Taking Leadership
    5. Assigning Tasks
    6. Single-Threaded versus Multithreaded Clients
    7. Takeaway Messages
  11. 8. Curator: A High-Level API for ZooKeeper
    1. The Curator Client
    2. Fluent API
    3. Listeners
    4. State Changes in Curator
    5. A Couple of Edge Cases
    6. Recipes
      1. Leader Latch
      2. Leader Selector
      3. Children Cache
    7. Takeaway Messages
  12. III. Administering ZooKeeper
  13. 9. ZooKeeper Internals
    1. Requests, Transactions, and Identifiers
    2. Leader Elections
    3. Zab: Broadcasting State Updates
    4. Observers
    5. The Skeleton of a Server
      1. Standalone Servers
      2. Leader Servers
      3. Follower and Observer Servers
    6. Local Storage
      1. Logs and Disk Use
      2. Snapshots
    7. Servers and Sessions
    8. Servers and Watches
    9. Clients
    10. Serialization
    11. Takeaway Messages
  14. 10. Running ZooKeeper
    1. Configuring a ZooKeeper Server
      1. Basic Configuration
      2. Storage Configuration
      3. Network Configuration
      4. Cluster Configuration
      5. Authentication and Authorization Options
      6. Unsafe Options
      7. Logging
      8. Dedicating Resources
    2. Configuring a ZooKeeper Ensemble
      1. The Majority Rules
      2. Configurable Quorums
      3. Observers
    3. Reconfiguration
      1. Managing Client Connect Strings
    4. Quotas
    5. Multitenancy
    6. File System Layout and Formats
      1. Transaction Logs
      2. Snapshots
      3. Epoch Files
      4. Using Stored ZooKeeper Data
    7. Four-Letter Words
    8. Monitoring with JMX
      1. Connecting Remotely
    9. Tools
    10. Takeaway Messages
  15. Index