Sei sulla pagina 1di 31

Apache

Zookeeper
What is Apache Zookeeper?

A highly-available service for coordinating processes of


distributed applications.
• Developed at Yahoo! Research
• Started as sub-project of Hadoop, now a top-level Apache project
• Open source distributed coordination service that helps you manage a large set of hosts.
• Zookeeper helps you to maintain configuration information, naming, group services for distributed
applications.
Distributed Application
Distributed Application(contd.)
• A distributed application can run on multiple systems in a network at a given time by coordinating among
themselves to complete a particular task in a fast and efficient manner.
• A group of systems in which a distributed application is running is called a Cluster and each machine running in a
cluster is called a Node.
• A distributed application has two parts, Server and Client application. Server applications are actually distributed
and have a common interface so that clients can connect to any server in the cluster and get the same result. Client
applications are the tools to interact with a distributed application.
Zookeeper in Hadoop Ecosystem

Pig Hive Sqoop


(Data Flow) (SQL) (Data Transfer)
(Coordination)
ZooKeeper

(Serialization)
MapReduce (Job Scheduling/Execution)

Avro
HBase (Column DB)

HDFS
Motivation for using Zookeeper
• In the past : a single program running on a single computer with a single CPU
• Today : applications consist of independent programs running on a changing set of computers
• Challenge : coordination of independent programs; developers had to deal with coordination logic and
the application logic same time.

Zookeeper is designed to relieve developers from


writing coordination logic code.
Zookeeper Architecture
ZooKeeper’s design principles
• API is wait-free
• No blocking primitives in ZooKeeper Blocking can be


implemented by a client No deadlocks

• Guarantees

• Client requests are processed in FIFO order Writes to


ZooKeeper are linearisable

• Clients receive notifications of changes before the changed data


becomes visible
ZooKeeper’s strategy to be fast and reliable
• ZooKeeper service is an ensemble of servers that use replication (high
availability)
• Data is cached on the client side:
Example: a client caches the ID of the current leader
instead of probing ZooKeeper every time.

• What if a new leader is elected?


• Potential solution : polling (not optimal) ZooKeeper is optimised for
read-dominant operations!
• Watch mechanism : clients can watch for an
update of a given data object
ZooKeeper terminology
• Client: user of the ZooKeeper service

• Server: process providing the ZooKeeper service

• znode : in-memory data node in ZooKeeper, organised in a hierarchical


namespace (the data tree)

• Update/write: any operation which modifies the state of the data tree

• Clients establish a session when connecting to ZooKeeper


ZooKeeper’s data model : filesystem
• znodes are organised in a hierarchical namespace

• znodes can be manipulated by clients through the ZooKeeper API

• znodes are referred to by UNIX style file system


paths
/ All znodes store data (file like) & can have
children (directory like).
/app1 /app2

/app1/p_1 /app1/p_2 /app1/p_3


znodes
• znodes are not designed for general data storage (usually require storage in the
order of kilobytes)
• znodes map to abstractions of the client application

Group membership protocol:


Client process pi creates znode p_i /app1 /app2
under /app1.
/app1 persists as long as the process
is running. /app1/p_1 /app1/p_2 /app1/p_3
znode flags
• Clients manipulate znodes by creating and deleting them
• Ephemeral flag: clients create znodes which are deleted at the end of the
client’s session
• Sequential flag: monotonically increasing counter appended to a znode’s
path; counter value of a new znode under a parent is always larger than
value of existing children

/app1_5
ephemeral (Greek): passing, short-lived
Create (/app1_5/p_, data, SEQUENTIAL)

/app1_5/p_1 /app1_5/p_2/app1_5/p_3
znodes & watch flag
• Clients can issue read operations on znodes with a watch flag

• Server notifies the client when the information on the znode has changed

• Watches are one-time triggers associated with a session (unregistered once triggered or
session closes)

• Watch notifications indicate the change, not the new data


Sessions
• A client connects to ZooKeeper and initiates a session

• Sessions have an associated timeout

• ZooKeeper considers a client faulty if it does not receive anything from its
session for more than that timeout

• Session ends: faulty client or explicitly ended by client


Implementation details
ZooKeeper data is replicated on each server that composes the service

replicated across all


servers
(in-memory)

updates first
logged to disk;
write-ahead log
write request requires
and snapshot
coordination between servers for recovery
ZooKeeper API
• String create(path, data, flags) No partial read/writes
• creates a znode with path name path, stores data in it and sets flags (no open, seek or
(ephemeral, sequential) close methods).

• void delete(path, version)


• deletes the anode if it is at the expected version

• Stat exists(path, watch)


• watch flag enables the client to set a watch on the znode

• (data, Stat) getData(path, watch)


• returns the data and meta-data of the znode

• Stat setData(path, data, version)


• writes data if the version number is the current version of the znode
• String[] getChildren(path, watch)
Example: configuration
• String create(path, data, flags)
Questions: • void delete(path, version)
1.How does a new worker query ZK • Stat exists(path, watch)
for a configuration? • (data, Stat) getData(path, watch)
2. How does an administrator change • Stat setData(path, data, version)
the configuration on the fly? • String[] getChildren(path, watch)
3. How do the workers read the new
configuration? /

[configuration stored in /app1/config] /app1 /app2


1.getData(/app1/config,true) app configuration
2.setData(/app1/config/config_data,-1)
[notify watching clients]
3. getData(/app1/config,true)

/app1/config /app1/progress
Example: group membership
• String create(path, data, flags)
Questions: • void delete(path, version)
1.How can all workers (slaves) of an • Stat exists(path, watch)
application register themselves on ZK? • (data, Stat) getData(path, watch)
2. How can a process find out about all • Stat setData(path, data, version)
active workers of an application? • String[] getChildren(path, watch)

/
[a znode is designated to store workers]
1.create(/app1/workers/
worker,data,EPHEMERAL)
2. getChildren(/app1/workers,true) /app1

/app1/workers

/app1/workers/worker1 /app1/workers/worker2
Example : simple locks •


String create(path, data, flags)
Void delete(path,version)
• Stat exists(path, watch)
• (data, Stat) getData(path, watch)
Question: • Stat setData(path, data, version)
1. How can all workers of an application • String[] getChildren(path, watch)
use a single resource through a lock?

create(/app1/lock1,…,EPHE.) /
/app1

yes
ok? use locked resource /app1/workers
/app1/lock1

/app1/workers/worker1 /app1/workers/worker2
getData(/app1/lock1,true)

all processes compete


36
at all times for the lock
Example: locking without herd effect
id=create(/app1/locks/lock_,SEQ.|EPHE.)

ids = getChildren(/app1/locks/,false)

/
yes
id=min(ids)? exit (use lock)

/app1
no
/app1/locks
exists(max_id<id,true)

/app1/locks/lock_1 /app1/locks/lock_2
wait for notification

Question:
1. How can all workers of an application use a single resource through
a lock?
37
Example: leader election • String create(path, data, flags)
• void delete(path, version)
• Stat exists(path, watch)
Question: • (data, Stat) getData(path, watch)
1. How can all workers of an application elect • Stat setData(path, data, version)
a leader among themselves? • String[] getChildren(path, watch)

getData(/app1/workers/leader,true)
/

ok? follow
yes /app1

create(/app1/workers/leader,IP,EPHE.)
/app1/workers

no
ok? lead /app1/workers/leader /app1/workers/worker1
yes

if the leader dies, elect again (“herd effect”)


38
ZooKeeper access control using ACLs
• ZooKeeper uses ACLs to control access to its znodes
• ACL Permissions
ZooKeeper supports the following permissions:
• CREATE: you can create a child node
• READ: you can get data from a node and list its children.
• WRITE: you can set data for a node
• DELETE: you can delete a child node
• ADMIN: you can set permissions
The ZKS - Session States and Lifetime
• Before executing any request, it is important that the client must establish a session with service
• All operations clients are sent to service are automatically associated with a session
• The client may connect to any server in the cluster. But it will connect to only a single server.
• The session provides "order guarantees". The requests in the session are executed in FIFO order
• The main states for a session are
• Connecting,
• Connected
• Close
• Not Connected.
Zookeeper Applications
Zookeeper Applications – Yahoo! Fetching Service

• Fetching Service is part of Yahoo!’s crawler infrastructure

• Setup : master commands page-fetching processes


• Master provides the fetchers with configuration
• Fetchers write back information of their status and health

• Main advantage of ZooKeeper:


• Recovery from master failures
• Guaranteed availability despite failures
Advantages
Limitations
Companies using Zookeeper

Instagram
Summary
• A distributed application is an application which can run on multiple systems in a network
• Apache Zookeeper is an open source distributed coordination service that helps you manage a large set of hosts
• It allows for mutual exclusion and cooperation between server processes
• Server, Client, Leader, Follower, Ensemble/Cluster, ZooKeeper WebUI are important zookeeper components
• Three types of Znodes are Persistence, Ephemeral and sequential
• ZDM watch is a one-time trigger which is sent to the client that set watch. It occurred when data from that watch changes
• Zookeeper uses ACLs to control access to its znodes
• Zookeeper uses : Managing the configuration, Naming services., selecting the leader, Queuing the messages, Managing
the notification system, Synchronization, Distributed Cluster Management, etc.
• Yahoo, Facebook, eBay, Twitter, Netflix are some known companies using zookeeper
• The main drawback of tool is that loss may occur if you are adding new Zookeeper Servers
Thank you
Presentation by

Anshumaan
Pratap Arunava Saha Ayush Gupta G. Tejarawind
42148 42155 42177
42139

Mayur Gangwal Tripti Sagar


42216 42339

Operations D

Potrebbero piacerti anche