Meetup on Apache Zookeeper

30
Apache Zookeeper Anshul Patel

Transcript of Meetup on Apache Zookeeper

Page 1: Meetup on Apache Zookeeper

Apache Zookeeper Anshul Patel

Page 2: Meetup on Apache Zookeeper

What is distributed system ?

• A distributed systems provides single coherent view of collection of independent computing machines.

• Multiple software components on multiple computers, which run as a single system.

• It can be locally or geographically connected.

Page 3: Meetup on Apache Zookeeper

Characteristics of Distributed System

• Concurrency• Fault Tolerance• Scalability• Transparency• Heterogeneity

Page 4: Meetup on Apache Zookeeper

Delusion of Distributed System

• Reliable Network• Zero Latency• Infinite Bandwidth• Secure Network• Topology Doesn’t change• Homogeneous Network• There is one administrator

Page 5: Meetup on Apache Zookeeper

Introducing Zookeeper

• Zookeeper provides coordination between distributed process via shared hierarchical namespace.

Page 6: Meetup on Apache Zookeeper

Why Zookeeper ?

• Naming Service• Locking• Synchronization• Configuration Management• Leader Election

Page 7: Meetup on Apache Zookeeper

Zookeeper Architecture

Page 8: Meetup on Apache Zookeeper

Zookeeper Architecture

• Zookeeper follows client server architecture• Collection of Zookeeper servers is called an ensemble• At given time, a Zookeeper client is connected to one

Zookeeper server• Client read requests are catered by connected Zookeeper

server• Client write requests are forwarded to Zookeeper leader.• Write is considered successful, if quorum is achieved.

Page 9: Meetup on Apache Zookeeper

Zookeeper Architecture

• Client updates are sequentially consistent• Updates are atomic• Updates are reliable• Timeliness

Page 10: Meetup on Apache Zookeeper

ZAB Protocol

• Zookeeper Atomic Broadcast• Propagates state changes from leader to followers• Guarantees the state change

Page 11: Meetup on Apache Zookeeper

Znodes

• Organized similar to standard Unix and Linux file system• Similar to files and directories• Both directory and leaf znode holds data • Stores data <= 1MB

Page 12: Meetup on Apache Zookeeper

Znode - Hierarchical Namespace

Page 13: Meetup on Apache Zookeeper

Time in Zookeeper

• Zxid : Every change to ZK state receives a stamp in form of zxid

• Version Number : Change to Znode will cause change in Version

• Ticks : Ticks define timing of events • Real Time : To put timestamp of stat structure and znode

modification

Page 14: Meetup on Apache Zookeeper

Znode Stat Structure

• Czxid : Change that caused Znode to be created• Mzxid : Change that last modified Znode• Pzxid : Change that last modified children of the Znode• Ctime : Millisecond from epoch, when this Znode was created• Mtime : Millisecond from epoch, when this Znode was last

modified• Version : Number of changes to data of Znode• Cversion : Number of changes to children of Znode• Aversion : Number of changes to ACL of Znode• EphemeralOwner : SessionId of owner of this Znode • DataLength : Length of data field• Numchildren : Number of children

Page 15: Meetup on Apache Zookeeper

Zookeeper Operations

create Creates Znode

delete Deletes Znode

exists Does Znode exist?

getACL Get ACL permissions

setACL Set ACL permissions

Page 16: Meetup on Apache Zookeeper

Zookeeper Operations

getChildren Gets the childrens of Znode

getData Gets Data of Znode

setData Sets Data of Znode

Sync Syncs the client View

Page 17: Meetup on Apache Zookeeper

Types of Znodes

• Ephemeral Znode : Deleted with termination of client session, also can’t have any child znode.

• Persistent Znode : Can have child znode, It is explicitly required to delete it.

• Sequential Znode : Append a monotonicly increasing counter to the end of path. It is unique to parent znode.

Page 18: Meetup on Apache Zookeeper

Znode Watchers

• One time triggers• Sent to client which sets the watch• Maintained locally at zookeeper• Client won’t receive watches after getting disconnected• Two lists of watches

– Data watches : create(),setData(), delete()– Child watches : create(), delete()

Page 19: Meetup on Apache Zookeeper

Zookeeper ACL

• ACL Permission– Create– Read– Write– Delete– Admin

Page 20: Meetup on Apache Zookeeper

Zookeeper ACL

• ACL Scheme– World– Auth– Digest– Host– IP

Page 21: Meetup on Apache Zookeeper

Zookeeper Recipes/Higher Order Functions/Apache Curator

• Naming Service• Service Discovery• Configuration Management• Locks• 2-phase commit• Leader Election• Barriers• Queues

Page 22: Meetup on Apache Zookeeper

Netflix/Soabase Exhibitor

• Zookeeper server is fail fast• Zookeeper is self-healing, (i.e. crashed/failed server if

brought online, will automatically join the cluster)• Instance Monitoring• Log Cleanup• Backup/Restore• Cluster-wide configuration• Rolling Ensemble Change• Rich REST API

Page 23: Meetup on Apache Zookeeper

Backup/Exhibitor

• Online Backup - Use Netflix Exhibitor• Offline Backup - Bring down the old ensemble cluster and

copy the zookeeper data directory to the new ensemble cluster

Page 24: Meetup on Apache Zookeeper

Zookeeper Monitoring

• 4 Letter Words• JMX

Page 25: Meetup on Apache Zookeeper

Zookeeper Monitoring - 4 Letter Words

conf srst

cons srvr

dump stat

envi dirs (3.5.1)

ruok mntr

Page 26: Meetup on Apache Zookeeper

Zookeeper Monitoring - JMX

• Mbeans

Quorum ServerCnxn

Leader LocalPeer

Follower LeaderElection

DataTree

Page 27: Meetup on Apache Zookeeper

Data Directory Cleanup

• autopurge.snapRetainCount : Maintains n number of recent snapshots along with transaction log

• autopurge.purgeInterval : Time Interval at which purge event will trigger

Page 28: Meetup on Apache Zookeeper

Zookeeper Future Releases - 3.5.X

• Dynamic Reconfiguration w/o Rolling restarts• Separate Dynamic configuration file• Adding/Removing Servers• Modifying server parameters• Rebalance Client Connections• Backward Compatible• Modifying Server Roles[Obersver/Participants]

Page 29: Meetup on Apache Zookeeper

Zookeeper in Real World

• Apache Kafka• Apache Storm• Apache HBase• Apache Solr• Apache Mesos• Apache Hive

Page 30: Meetup on Apache Zookeeper

Questions ?

Thank You