apache zookeeper · • zookeeper provides a very simple interface to a highly reliable and...

29
Apache ZooKeeper CMSC 491 Hadoop-Based Distributed Compu=ng Spring 2016 Adam Shook

Upload: others

Post on 29-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

ApacheZooKeeper

CMSC491Hadoop-BasedDistributedCompu=ng

Spring2016AdamShook

Page 2: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Whatisit?

•  ApacheZooKeeperisanefforttodevelopandmaintainanopen-sourceserverwhichenableshighlyreliabledistributedcoordina=on.–  Simple– Replicated– Ordered–  Fast

Page 3: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Provides

•  Configura=onInforma=on•  DistributedSynchroniza=on•  GroupServices

•  Eachoftheseservicesareusedinsomebydistributedapplica=ons

Page 4: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Interface

•  ZooKeeperprovidesaverysimpleinterfacetoahighlyreliableanddistributedservice

•  Powerfulabstrac=onscanbebuiltfromthisverysimpleinterface

•  CurrentlyinterfacesareinJavaandC– WanttoexpandtoPython,Perl,andREST.

Page 5: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

TheCore

•  Sharedhierarchicalnamespaceofdataregisters,calledznodes

•  Unlikefilesystems,providesclientswithhighthroughput,lowlatency,highlyavailable,andorderedaccesstoznodes

Page 6: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Quorum

Page 7: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Namespace

Page 8: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

znodes

•  Meta-informa=on:– Configura=on–  StatusInforma=on–  Loca=onInforma=on– Whateveryouwant(that’ssmall)

Page 9: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

znodes

•  Eachnodeactsasafileanddirectory•  1MBmaximumperznode•  Persistentvs.Ephemeral•  Sequen=alznodes•  Fullpaths– Anop=onal“chroot”suffixcanbeappendedtoconnec=onstring

–  “127.0.0.1:3000,127.0.0.1:3002/app/a”

Page 10: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Watchers

•  Tiedtoeachznode

•  One-=metrigger•  Senttotheclient•  Thedataforwhyitwassent

Page 11: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

That’sIt

•  Inanutshell•  Verybasicservice,fromwhichpowerfulabstrac=onscanbebuilt

•  Let’stalkabouthowgooditis!– Thatis,ifyoudon’thaveanyques=onsrightnow…•  Youcanask.Idon’tbite

–  Really»  Promise

Page 12: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

UseCase:Loca=onData•  Serversstoremachinehostnameasephemeralznodes

– /app1/machine1– /app1/machine87– /app1/machine4

•  Whenaserverisadded,createanewznode•  Whenaserverisremoved,znodeisdeleted•  Whenaserverfails,ZKwilldeletetheephemeralnode•  Allowsfordynamicthronlingofresources•  Clientscanchooseahostnamefromchildrenof/app1to

connectto– Setachildwatchon/app1,ifservergoesdownitwillreceiveno=fica=onandcanchooseanewserver

Page 13: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

UseCase:Status

•  UseZooKeeperasaheartbeatmechanism•  “Master”servicekeepsdatawatchesonznodes

•  Serverssetthedataoftheirnodeevery15seconds

•  IftheMasterdoesn’treceiveano=fica=onchangewithin20seconds,canassumethatserverhasfailedandkillitbeforebadthingshappen.

Page 14: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Performance

Page 15: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Performance

Page 16: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

CommandLineInterface

•  Interac=veusageofthenamespaceinashell–  create[path][data]– delete[path]–  get[path]–  set[path]–  ls[path]–  rmr[path]– Anumberofothercommands…

•  Tabcomple=on!

Page 17: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

API

•  Currentandstablev3.4.6(March2014)•  RequiresonlyalistofZKserverstoconnect•  IMO,goodbutmessyinterface•  RecommendbuildinganicewrapperAPIforgerng/serngPODtypesandhandlingexcep=ons

Page 18: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Recipes!

•  Wearegoingtotalkaboutthese:•  Configura=on•  DistributedLocks•  DistributedQueue

Page 19: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Configura=on

•  Configura=onisosendriventhroughkey/valuepairsstoredinafile– Cangetmessywhenconfigura=onisdynamic

•  Implementa=onisverystraightorward,asitiswhatZooKeeperwasdesignedfor

•  Eachfull-pathedznodeisthekeyandthedataassociatedwiththeznodeisthevalue

Page 20: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Variables

•  Sta=cVariables–  Thoseonesthatareprobablynevergoingtochange(notasmuchfun)

•  DynamicVariables– Changedbyhandviacommandlineorbytheapplica=onitself•  Trackstatusofprocesses•  Updatehistoricaldata

Page 21: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

UseofWatchers

•  Applica=onscanchangeconfigura=onontheflyforsomevariables

•  Wheneveravariablechanges,thosewatchinganodecanreceivethechangedvariableandmakethecorrectchanges

•  Veryusefulforlong-runningapplica=onsthatrequirethemostuptodateinforma=on

Page 22: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

DistributedLocks•  Ameanstohavedistributedprocessesretrievealockfor

someopera=on–  Thronledupda=ngofdatabase–  Yourusecasehere!

•  ExistsinZooKeeper'srecipesdirectoryandisdistributedwiththerelease--src/recipes/lock

Page 23: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Algorithm•  Defineaznodetoholdthelock,say“/dlock”1.  mypath=create(“/dlock/lock-”),withthesequence

andephemeralflagsset2.  children=getChildren(“/dlock”),nowatch3.  Ifmypathhaslowestnumbersuffixinchlidren,exit4.  Callexists()onnodefromchildrenwithnextlowest

sequencenumberwiththewatchflagset1.  i.e.,ifmypathis“/dlock/lock-6”andchildrencontains

3,4,6,7,callexistson“/dlock/lock-4”5.  Ifexistsisfalse,gotostep26.  Iftrue,waitforwatchtriggerbeforegoingtostep2

Page 24: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

DistributedQueues•  Ameanstoallowclientstoasynchronouslyaddelementstoa

queueandhaveasingleprocessorapplica=ondequeueandprocessthem.–  Ican’trememberthelast=meIneededaqueue– Maybeyouhaveafew

Page 25: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

Algorithm•  Designateaznodetoholdthequeue,say“/dqueue”•  Enqueue:create(“/dqueue/queue-”),withsequenceandephemeralflagsset.–  Returnsarealpathnode/dqueue/queue-X,whereXisamonotonicincreasingnumber

•  Dequeue:getChildren(“/dqueue”),watchsettotrue•  Processthesenodeswiththelowestnumberfirst–  NoneedtocallgetChildren()un=lthecurrentreceivedlistisexhausted

•  Ifnochildrenareinthequeue,waitforwatchno=fica=onbeforecheckingagain

Page 26: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

PriorityQueueExtension•  Twosimplemodifica=onstothisalgorithm!– Whenenqueuing,pathnamesendswithqueue-ZZ,whereZZisthepriorityoftheelement•  Lowerthenumber,higherthepriority

– Whendequeuing,ifthewatchno=fica=onistriggeredonthe“/dqueue”node,clientneedstocallgetChildren()againandresortbypriority.

Page 27: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

OtherRecipes

•  Groupmembership•  Barriers•  Two-phasedcommit•  LeaderElec=on

Page 28: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

ApacheCurator

•  "Curatornˈkyoor͝ˌātər:akeeperorcustodianofamuseumorothercollec=on-AZooKeeperKeeper.“

•  Contains:•  Recipes•  Framework•  U=li=es

•  Client•  Errors•  Extensions

Page 29: Apache ZooKeeper · • ZooKeeper provides a very simple interface to a highly reliable and distributed service • Powerful abstrac=ons can be built from this very simple interface

References

•  hnp://zookeeper.apache.org•  hnp://curator.apache.org