Beruflich Dokumente
Kultur Dokumente
MultiversionconcurrencycontrolWikipedia
Multiversionconcurrencycontrol
FromWikipedia,thefreeencyclopedia
Multiversionconcurrencycontrol(MCCorMVCC),isaconcurrencycontrolmethodcommonlyusedby
databasemanagementsystemstoprovideconcurrentaccesstothedatabaseandinprogramminglanguagesto
implementtransactionalmemory.[1]
Ifsomeoneisreadingfromadatabaseatthesametimeassomeoneelseiswritingtoit,itispossiblethatthereader
willseeahalfwrittenorinconsistentpieceofdata.Thereareseveralwaysofsolvingthisproblem,knownas
concurrencycontrolmethods.Thesimplestwayistomakeallreaderswaituntilthewriterisdone,whichisknown
asalock.Thiscanbeveryslow,soMVCCtakesadifferentapproach:eachuserconnectedtothedatabaseseesa
snapshotofthedatabaseataparticularinstantintime.Anychangesmadebyawriterwillnotbeseenbyother
usersofthedatabaseuntilthechangeshavebeencompleted(or,indatabaseterms:untilthetransactionhasbeen
committed.)
WhenanMVCCdatabaseneedstoupdateanitemofdata,itwillnotoverwritetheolddatawithnewdata,but
insteadmarkstheolddataasobsoleteandaddsthenewerversionelsewhere.Thustherearemultipleversions
stored,butonlyoneisthelatest.Thisallowsreaderstoaccessthedatathatwastherewhentheybeganreading,
evenifitwasmodifiedordeletedpartwaythroughbysomeoneelse.Italsoallowsthedatabasetoavoidthe
overheadoffillinginholesinmemoryordiskstructuresbutrequires(generally)thesystemtoperiodicallysweep
throughanddeletetheold,obsoletedataobjects.Foradocumentorienteddatabaseitalsoallowsthesystemto
optimizedocumentsbywritingentiredocumentsontocontiguoussectionsofdiskwhenupdated,theentire
documentcanberewrittenratherthanbitsandpiecescutoutormaintainedinalinked,noncontiguousdatabase
structure.
MVCCprovidespointintimeconsistentviews.ReadtransactionsunderMVCCtypicallyuseatimestampor
transactionIDtodeterminewhatstateoftheDBtoread,andreadtheseversionsofthedata.Readandwrite
transactionsarethusisolatedfromeachotherwithoutanyneedforlocking.Writescreateanewerversion,while
concurrentreadsaccesstheolderversion.
Contents
1 Implementation
2 Examples
2.1 Concurrentreadwrite
3 History
4 Versioncontrolsystems
5 Seealso
6 References
7 Furtherreading
Implementation
MVCCusestimestamps(TS),andincrementingtransactionIDs,toachievetransactionalconsistency.MVCC
ensuresatransaction(T)neverhastowaittoReadadatabaseobject(P)bymaintainingseveralversionsofthe
object.EachversionofobjectPhasbothaReadTimestamp(RTS)andaWriteTimestamp(WTS)whichletsa
https://en.wikipedia.org/wiki/Multiversion_concurrency_control
1/4
11/22/2016
MultiversionconcurrencycontrolWikipedia
particulartransactionTireadthemostrecentversionoftheobjectwhichprecedesthetransaction'sRead
TimestampRTS(Ti).
IftransactionTiwantstoWritetoobjectP,andthereisalsoanothertransactionTkhappeningtothesameobject,
theReadTimestampRTS(Ti)mustprecedetheReadTimestampRTS(Tk),i.e.,RTS(Ti)<RTS(Tk),forthe
objectWriteOperation(WTS)tosucceed.AWritecannotcompleteifthereareotheroutstandingtransactionswith
anearlierReadTimestamp(RTS)tothesameobject.Likestandinginlineatthestore,youcannotcompleteyour
checkouttransactionuntilthoseinfrontofyouhavecompletedtheirs.
Torestateeveryobject(P)hasaTimestamp(TS),howeveriftransactionTiwantstoWritetoanobject,andthe
transactionhasaTimestamp(TS)thatisearlierthantheobject'scurrentReadTimestamp,TS(Ti)<RTS(P),then
thetransactionisabortedandrestarted.(Ifyoutrytocutinline,tocheckoutearly,gotothebackofthatline.)
Otherwise,TicreatesanewversionofobjectPandsetstheread/writetimestampTSofthenewversiontothe
timestampofthetransactionTS=TS(Ti).[2]
Thedrawbacktothissystemisthecostofstoringmultipleversionsofobjectsinthedatabase.Ontheotherhand,
readsareneverblocked,whichcanbeimportantforworkloadsmostlyinvolvingreadingvaluesfromthedatabase.
MVCCisparticularlyadeptatimplementingtruesnapshotisolation,somethingwhichothermethodsof
concurrencycontrolfrequentlydoeitherincompletelyorwithhighperformancecosts.
Examples
Concurrentreadwrite
AtTime=1,thestateofadatabasecouldbe:
Time
Object1
"Foo"byT0
"Hello"byT1
Object2
"Bar"byT0
T0wroteObject1="Foo"andObject2="Bar".AfterthatT1wroteObject1="Hello"leavingObject2atits
originalvalue.ThenewvalueofObject1willsupersedethevalueat0foralltransactionsthatstartafterT1
commitsatwhichpointversion0ofObject1canbegarbagecollected.
IfalongrunningtransactionT2startsareadoperationofObject2andObject1afterT1committedandthereisa
concurrentupdatetransactionT3whichdeletesObject2andaddsObject3="FooBar",thedatabasestatewilllook
likeattime2:
Time
Object1
"Foo"byT0
"Hello"byT1
Object2
Object3
"Bar"byT0
(deleted)byT3 "FooBar"byT3
Thereisanewversionasoftime2ofObject2whichismarkedasdeletedandanewObject3.SinceT2andT3
runconcurrentlyT2seestheversionofthedatabasebefore2i.e.beforeT3committedwrites,assuchT2reads
Object2="Bar"andObject1="Hello".Thisishowmultiversionconcurrencycontrolallowssnapshotisolation
readswithoutanylocks.
https://en.wikipedia.org/wiki/Multiversion_concurrency_control
2/4
11/22/2016
MultiversionconcurrencycontrolWikipedia
History
Multiversionconcurrencycontrolisdescribedinsomedetailinthe1981paper"ConcurrencyControlin
DistributedDatabaseSystems"[3]byPhilBernsteinandNathanGoodman,thenemployedbytheComputer
CorporationofAmerica.BernsteinandGoodman'spapercitesa1978dissertation[4]byDavidP.Reedwhichquite
clearlydescribesMVCCandclaimsitasanoriginalwork.
Thefirstshipping,commercialdatabasesoftwareproductfeaturingMVCCwasDigital'sVAXRdb/ELN.The
secondwasInterBase,bothofwhicharestillactive,commercialproducts.
Versioncontrolsystems
Anyversioncontrolsystemthathastheinternalnotionofaversion(e.g.Subversion,Git,probablyalmostany
currentVCSwiththenotableexceptionofCVS)willprovideexplicitMVCC(youonlyeveraccessdatabyits
versionidentifier).
AmongtheVCSsthatdon'tprovideMVCCattherepositorylevel,moststillworkwiththenotionofaworking
copy,whichisafiletreecheckedoutfromtherepository,editedwithoutusingtheVCSitselfandcheckedinafter
theedit.ThisworkingcopyprovidesMVCCwhileitischeckedout.
Seealso
Clojure
ListofdatabasesusingMVCC
Readcopyupdate
Timestampbasedconcurrencycontrol
Vectorclock
References
1.refs(http://clojure.org/refs).Clojure.Retrievedon20130918.
2.Ramakrishnan,R.,&Gehrke,J.(2000).Databasemanagementsystems.Osborne/McGrawHill.
3.Bernstein,PhilipA.Goodman,Nathan(1981)."ConcurrencyControlinDistributedDatabaseSystems".ACM
ComputingSurveys.
4.Reed,DavidP.(September21,1978)."NamingandSynchronizationinaDecentralizedComputerSystem".MIT
dissertation.
Furtherreading
GerhardWeikum,GottfriedVossen,Transactionalinformationsystems:theory,algorithms,andthepractice
ofconcurrencycontrolandrecovery,MorganKaufmann,2002,ISBN1558605088
Retrievedfrom"https://en.wikipedia.org/w/index.php?
title=Multiversion_concurrency_control&oldid=746373805"
Categories: Concurrencycontrol Concurrencycontrolalgorithms Transactionprocessing
Thispagewaslastmodifiedon27October2016,at01:11.
https://en.wikipedia.org/wiki/Multiversion_concurrency_control
3/4
11/22/2016
MultiversionconcurrencycontrolWikipedia
TextisavailableundertheCreativeCommonsAttributionShareAlikeLicenseadditionaltermsmayapply.
Byusingthissite,youagreetotheTermsofUseandPrivacyPolicy.Wikipediaisaregisteredtrademark
oftheWikimediaFoundation,Inc.,anonprofitorganization.
https://en.wikipedia.org/wiki/Multiversion_concurrency_control
4/4