ToCSLDateAugust10,1984FromMikeKupferLocationPARCSubjectInternalstructureofAlpineLocksOrganizationCSLXEROXReleaseas[Indigo]Release52>Doc>LockInternals.pressCamefrom[Indigo]Release52>Doc>LockInternals.tiogaLasteditedbyKupfer,August11,19842:37:26pmPDTAbstractTheAlpineLockManagercontrolsacomplicatedwebofvariantrecords.ThismemodescribesthevariantrecordstructureandgivesanexampletakenfromarunningAlpineserver.Itmaybenecessarytoreadthememoonce,lookattheexample,andthenreadthememoagain.IntroductionTheAlpinefileservice,asdesigned,supportsatomictransactionsthatspanmultipleservers.Thisdocumentbrieflyexplainsthehigh-levelinterfacetoAlpinelocks,anditexplainsthecomplicateddatastructurethateachAlpineserver'sLockManagermaintains.LockinterfaceAlpinenamesalockwithaLockID(definedinAlpineInternal.mesa).Unlike,say,atransactionID,aLockIDalwaysreferstoexactlyoneobject,suchasafileorapage,evenacrosseventssuchasservercrashes.AclientoftheLockinterfaceissomeothermoduleinAlpine,actingonbehalfofatransaction.ThisclientmayrequestthatthelockmanagerSetalockinagivenmode.Ifthereisalreadyaconflictinglockset,theclientmayspecifywhetheritwishestowaituntilthelockisavailable,orwhetheritwishestobeinformedimmediatelythatsomeoneelsehasthelock.Alockmaybeheldbymorethanonetransaction,andatransactionmayholdmorethanonelock.Giventhelock,thetransactionmayReleaseitwhenitnolongerneedsit.Thetransactionmanageralsohasthepowertoabortatransactionandtakeallofitslocksaway,usuallysothatthelockscanbegiventoothertransactions.WhattheLockManagerneedsSupposeatransactionrequeststhelockMyLock.TheLockManagermustquicklyfindthislockinapotentiallylargejungleofotherlocks,determineifanyonepï_/îâqï_/î8pï_/î-äqï_/î2Àî7~î9»pï[Sîâqï[Sî8îZpï[Sî-äqï[Sî89pïWwîâqî;ïWwïWwîÀîrî/îèî$npïWwî-ä qïWwî89rïOæîqsïINîâîetïINî¢ð1sïG§îâîBtïG§î¢ð1sïEÿîâîwïEÿî¢tîAïEÿïEÿî4îwî"�î$õî(’î-¼î0<sïB°îâtïB°î¢î›î,î!Õî'ýî-·î/ î7\î:�î–ï<î¢î î“î!uï5uîâ qï2%î¤î»î�î*î!Hî#6î)‰î/Yî4 î;Ôî>âï0~îâîfîéîî#†î'öî-Xî/à î6.î;ßî=˜ï.×îâî½î{î×î5îš î&Mî)Xî/î1ïî5&î9²î>¡ï-/îâî¨ vï)àîâîjqï&‘î¤î-îtî î�î!»wî"çï&‘ï&‘î#Ûqï&‘î(#î-Ÿî/Qî=5ï$êîâî”îº î²î-îSî"oî&Ðî*¡î,Kî0äî3‹î7øî;%î<Ïî=õî@Zï#Cîâîî¸îîîYî"‘î$Fî(Yî.î/”î3[î5î7�î;î@²ï!›îâî’îNîkî7î"2î&\î(€î,Öî.­î/ó î8î;=î?ïôîâîÛîÍîQînwî",ïôïôî#qïôî$¼î& î)'î*ùî,Gî0î5î6¿î:mî;üî@ôïMîâ î î’îîXî!î$î(¤î-ëî/;î3Žî55î8(î;hî=Àî@²ï¥îâ îîîîVîÇî"<î$î&î,( î4î7î<Øî?©ïþîâî?îîšî‘î“î�î!šî#“î'$î*Hî,ò î4Dî6ùî8 î?ïWîâîî¦îÌîxïÛî¤îÍî(îtîÏ î$Çwî'ÆïÛïÛî(ÄqïÛî,¬î-ýî1®î3î5î9@î=î?Fï4îâ îîÈî¼î!Yî#áî(7î* î-Ôî/& î6Jî9)îbî@Cï�îâî_î5îçî«îyî!Ùî%Vî'áî)Òî-†î/5î2Ô vï=îâî¬î î’îmqï îî¤î]îº îêî%wî( wî+7ï îï îî,Œqî07ï îï îî1ÿî5 î8¼î>¶ï Gîâîªî‚î îîî…î˜ î%Qî(¡î,¸î.Zî1âî5¡î< î=VÿxTVm$CSLNotebookTopic2elsehasMyLock,anddeterminewhetherthetwotransactionscanbothhaveMyLockatthesametime.Ifthereisaconflictandtherequestingtransactionwishestowait,theLockManagermustplacetherequestinaqueue,waitingforthelock'seventualavailability.Supposethatatransactioncompletes(eithercommitsoraborts).TheLockManagermustfindallofthelocksownedbythetransactionandfreethem.Ifanothertransactioniswaitingforoneoftheselocks,theLockManagershouldgivethelocktothissecondtransaction.Finally,considerthemaintenanceworkthattheLockManagermustdo.Itshouldbeabletodetectacircularchainofrequests(deadlock),anditshouldbeabletoscanwaitingrequeststofindcasesoflivelock(akastarvation).Itshouldbeabletoperformthesetasksquicklyandwithlittleoverhead,sothatproblemsarecorrectedquicklyandwithlittleperformanceloss.TheSolutionTheAlpineLockManagerusesasingledatastructuretomeetthesevariedneeds.Thisdatastructureconsistsofmanyvariantrecords,allofwhicharetiedtogetherbyassortedREFlinksintocircularandsimplesingly-linkedlists.LockInternal.ObjectThevariantrecordthattheAlpineLockManagerusesisdefinedinLockInternal.mesa.ALockObjectalwayscontainsarequestListREFandabodyrecord.ThetwomainvariantsofaLockObject--requestandheader--aredistinguishedbyvaryingthebody.Weshallrefertothesetwovariantsas"requestobjects"and"headerobjects,"respectively.TherequestListREFlinksobjectsassociatedwithonelockintoacircularlist,aswewillexplainbelow.HeaderObjectRecallthatanAlpineLockIDuniquelyidentifiesoneobjectthatistobelocked(eg.,apageorafile).Whenatransactionrequestsalock,theLockManagerentersarequestobjectforthetransactiononacircularlistassociatedwiththedesiredLockID.ThiscircularlististiedtogetherwiththerequestListREF,asstatedabove.Aheaderobjectalsositsinthecircularlist,anditidentifieswhichlockisbeingrequested.TheLockManagerreferstoheaderobjectsviaahashtable,usingthelockIDasthehashkey.Thenextfieldisusedbythehashpackagetoconnectheaderobjectsthathashtothesamelocation.RequestObjectArequestobjectalwayscontainsatransactionhandle,atransListREF,andmodeinformation.Thetransactionhandletellswhattransactiontherequestobjectisassociatedwith.WewilldescribethetransListREFbelow.Themodetellswhatlockingmodehasbeenrequested.Therestofarequestobjectisyetanothervariantrecord,consistingofeitheragranted,awaiting,oratransHeadervariant.uïfåî"Žî&oî.tïfåîEÉqï_,îâîzwîÐï_,ï_,î%qï_,î�î&î"‰î'¹î)ùî,‡ î3èî6Uî9rwî<šï_,ï_,î=ïqï]…îâîlî¾î-îî†îî _î!{î&Wî)î+R î1ò î8àî=,î>Ìï[Ýîâî5î¥î^î¹î!@î#“î(Zî)ûî+î/‡î4Nî6~î8Ñî<™ïZ6îâ ïW»î¤îZîYî³ î"àî)}î.î3Éî5½î;˜î>¡ïVîâîÑîbîyî’îtî!ýî%£î*<î,aî.ê î6î8ïî;åî@œïTlîâîë îæîOî!!î#]î&î'¾î+Eî/î1wî4òî:¶î?0ïRÅîâîAî:îéîŠî ïPIî¤îÖîwîÿ î',î*Ñî-Èî0Oî3õî9ãî=sî@¦ïN¢îâî{î‰î îlî˜îßî$òî(Åî*›î0 î7Kî: î;”î@-ïLúîâîÚîˆî—îiî Áî"oî%\î(Îî*†î/šî2� î:<î;²î@-ïKSîâîôîºî*îÌî Aî%8î(î+;î.„î4çî6Ãî9ªî?ÊïI¬îâîáîÀîwî’î" î*ÇvïF]îâî»qïC î¤î«îaîî#î&,î'…î+ î.Õî4Âî6 î:7î=ðïAfîâî×î î/î î%$î&ùî*àî/˜î4àî6ìî8Âî<ìî?[ï?¿îâîFîApîŽï?¿ï?¿îbqï?¿îYî!ªî$‚î)wî,/î0” î8¸uï9!îâqï5Ñî¤îîOî:î"£î%žî*¿î.Øî59î8Íî:Ôî@pï4*îâî‰î;wî Þï4*ï4*î!ñqî%Uï4*ï4*î%úî)ßî/hwî0·ï4*ï4*î1; pï4*î7Çqï4*î:·î=”wî>ãï4*ï4*î?“qï2ƒîâî›îºî­îrî#Ùî%Ùî'Jî+î/Æwî1„ï2ƒï2ƒî2 qï2ƒî6kwî9jï2ƒï2ƒî:&qî> ï2ƒï2ƒî>†î?Êï0Ûîâ î>î9î!î €î$×î'aî*›î-ëî/™î3!î5Ìî:ìî<™ï/4îâî‡î•î#î# î,î/N pî6·ï/4ï/4î7‹qï/4î9Ùî=�ï-�îâ îNîiîîî æî"î'î)›î+Iî-pî0î4ïvï*>îâîÀqï&îî¤îËî‡îewîØï&îï&îîËqï&îî#þî)¨ î/ˆî2"î6(î8äî:>î;Úî=¸ï%GîâîÛîúî7îðîî¹î Çî!ç î(Øî.'î/Fî2�î4âî8Uî>ï# îâî=îBî‹îùîŠ î%¶î'íî)Hî.nî0Ü î7yî:Åî=Uï!øîâîÓîèîØîî vî#3î(‘î+¦î. pî5 ï!øï!øî5àqî7Sï!øï!øî8*î9Òî=Äï Qîâî’î<îwîgîéî ºî#=î(Uî+î-èî/b î5wî9¨î<Äî>Sïªîâ ï.î¤îˆîîäî!Æî#�î(î,¾î/î0>î3‡î7Tî; wî=vï.ï.î=Ùqï‡îâî¹îBî¨îlwîmï‡ï‡î,qï‡î ¬î$î%›î)î+%î-®î1î6î8Wî=—ïßîâîîMî‰î8î—î!vï�îâî#qïAî¤îîÜîáî 2î%�wî&–ïAïAî' î-|qî1VïAïAî2wî34ïAïAî3¤pïAî8Öqî;ïAïAî;åwî>ˆïAïAî?žqïšîâ î½îÐ î"î&Éî)æî-~ î4µî7Oî<_î@²ïòîâ îlî�îDî î$Žî' pî,Íïòïòî-¡qïòî/µî4Øî7Íî;Àî>Áï Kîâî¤îiîÌî î$î&Úî)jî+î,*î0íî4õî6Pî8‡î=�ï ¤îâîŠ îßî˜î…wî ®ï ¤ï ¤î!_qî% ï ¤ï ¤î%êwî'ï ¤ï ¤î'ûqî+Qï ¤ï ¤î,-î-ñwî/ï ¤ï ¤î/‹ qï ¤î6ÌÝTVm$‹CSLNotebookTopic3waitingvariantWhenatransactionmustwaitforalock,theLockManagercreatesa"waiting"variantforthetransaction.Allofthe"waiting"requestobjectsaretiedinasingly-linked,non-circularlistthroughthetransListREF.Thislistisused,forexample,bytheLockWatchdogtofindlockrequeststhathavetimedout.grantedvariantWhentheLockManagergrantsarequest,itmakesa"granted"variantforthetransaction.Thisobjectsitsinacicularlistcontainingallgrantedrequestsforthetransaction.ThelistitselfisboundtogetherviathetransListREF.transHeadervariantInadditiontothetransaction'sgrantedrequests,thetransList-threadedcircularlistcontainsatransHeader.Thisobjectidentifiesthetransactionandcontainsacountofthe(granted)requestobjectsinthelist.AnExampleTheaccompanyingdiagram(filedin[Indigo]Release52>Doc>LockExample.griffin)wasderivedbytracingpointersonarunningAlpineserver(Monitor.alpine).Itshowsthelockobjectsfortwotransactions,numbers402and1002.Therearefourlocksinvolved,asshownbythefourheaderobjects:A,B,C,andD.ThetransactionsAtransaction'slocksareassociatedwithitsworker(s),so"self,"intheupperleftcorner,isaWorker.Handlefortransaction402.Itpointstothecircularlistofallthelocksthat402hasbeengranted.BecausetherequestListREFispresentinallLockobjectsbutdoesn'thaveausefulfunctioninatransHeader,itisNILinthetransHeader.ThetransHeaderfor1002isatthebottomofthediagram,inthemiddle.Transaction402hasbeengrantedallfourlocks(A,B,C,andD).Transaction1002hasbeengrantedonelock(D),andiswaitingforanother(C).Transaction1002iswaitingbecauseitisrequestingamodethatisincompatiblewiththemodethat402haslockedCwith.ThelocksLockAhasbeengrantedtoonetransaction(402).Itistheonlylockinitshashbucket,soits"next"fieldisNIL.LockBhasbeengrantedto402.B'sandC'slockID'shashtothesamevalue,soBislinkedtoCvia"next".LockChasbeengrantedto402,and1002iswaitingforit.The"waiting"requestobjectfor1002isthelastoneintheLockManager'slistofwaitingobjects.uïfåî"Žî&oî.tïfåîEÉwï_:îâî£qï[ëî¤î´îÖ îÊî!*î$î&Rî'tî*½î-î0Šî6Hî:Èî;êïZCîâîËîTî î!pî$î&î(Àî/Aî4bî9Kî;ëî>úî@ôïXœîâ î¥ î£î"(î'§î*Mpî09ïXœïXœî1 qî2€ïXœïXœî4mî7Îî:Sî<î?áïVõîâî³î¯îî‹î#î$Èî'¶î*¯î0î2Öî6î: wïS¥îâîÅqïPVî¤î¼îî˜î!^î%vî&Ÿî+Ìî-"î1Zî2„î8åî=�î?¾ïN¯îâ îÒîùîî ‰î"Dî#zî'÷î*A î1î3î8î=uî?¾ïMîâ îºî’îÏî,î ˜î$óî*Vî,”î.ópî4˜ïMïMî5lqî6ßïMïMwïI¸îâ î“qïFiî¤îrîàîŽîì î$Äî)Ãî/tî1Òî=)ïDÂîâîKîÚî0 î!&î$lî(± î.Ïî1Z î8‚î;eî@ôïCîâî¹îrîÑîÄî!™î&6î'äî*Cuï<|îâî…qï9-î¤îø î*vî6Jî@pï7†îâð2î0åî4”î:�î=Œï5Þîâî0î7îbîšî!!î%.î0bî1Úî5èî8Iî;Cî?áï47îâîŠ î_î î!žî$Rî(íî,ëî/;î2<î5µî;¤î=Ïï2�îâîÞî=îAîÈîßî!Ãî#‡î%aî(vï/@îâî» qï+ñî¤îM îAîÛî!K î'Ôî+ î- î3”î5uî9Ôî;Ÿî>ï*JîâîbîîŒwîÂï*Jï*Jî" qï*Jî"lî$µ î+¼î/Eî0Çî4öî6°î9î>î@eï(¢îâîâîRîßî½îcîèî"Uî(Qî-£î0 pî75ï(¢ï(¢î8 qï(¢î:î;Œî@pï&ûîâîÌîCîÚîUî î#Mî$pî(ƒî-÷î/žî0 î8×î:'pî;�ï&ûï&ûîî?¾ï%Tîâ îÜîá î"Òî%=î(°î*Iî,î.œî3’î5yî8î=ãî?¾ï#¬îâï!1î¤ îî¯î%î!ƒî&„î(uî+zî.øî1Wî3î4÷î7¯î:© ïŠîâîDîÖîOîkî 3î#Iî&Sî)'î*¯î/Ÿî1ùî7 î:© ïâîâî/î¡î{î¤îî s î')î(Yî,6î/ î0~ î8Àî;âî>Hï;îâî°îFî»î î¢vïìîâî»qïœî¤îAîîî„îî"!î#ðî&¼ î-Ùî2}î4î5¡î8!î;\î>uî@Cïõîâîîóî·î‘îî"2pî#žïõïõî$†qî%©ïõïõïzî¤î!îŒîî^î!^î# î&~î(Æî+~î-Üî3Uî6‘î8?î:Ÿî>ïÒîâî¦îî}î¶îeîçî$ï Wî¤îIîòî�îî"<î$î''î*î-tî/î4î6hî8êî;êï °îâîµîÌîîLî¶î!î#“î&=î'éî*Gî-Ãî4dî6 î8Wî=)ÿ`TVm$ŽCSLNotebookTopic4LockDhasbeengrantedtoboth402and1002.uïfåî"Žî&oî.tïfåîEÉqï_/î¤î!îÄî9î–î!–î#Eî&�î)î+Î5TVm$.ÿ TIMESROMANþŸÿ TIMESROMANþŸÿ TIMESROMANþYÿ HELVETICAþŸÿ HELVETICAþæÿLOGOü´ÿ TIMESROMANþŸÿ TIMESROMANþæ³ Á¶j/�EDlÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.[]<>users>kupfer.pa>Alpine>LockInternals.tioga%Saturday, August 11, 1984 3:00 pm PDT