{"id":36650,"date":"2019-10-31T22:12:54","date_gmt":"2019-10-31T19:12:54","guid":{"rendered":"https:\/\/prohoster.info\/blog\/tranzaktsii-v-globalah-intersystems-iris\/"},"modified":"2019-10-31T22:12:54","modified_gmt":"2019-10-31T19:12:54","slug":"tranzaktsii-v-globalah-intersystems-iris","status":"publish","type":"post","link":"https:\/\/prohoster.info\/lv\/blog\/administrirovanie\/tranzaktsii-v-globalah-intersystems-iris","title":{"rendered":"Transakcijas glob\u0101los InterSystems IRIS","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><img decoding=\"async\" alt=\"Transakcijas glob\u0101los InterSystems IRIS\" src=\"\/wp-content\/uploads\/2019\/07\/ee4e58369616511dc213f94158b04e4f.jpg\" style=\"display:block;margin: 0 auto;\" \/>InterSystems IRIS DB atbalsta interesantus datu glab\u0101\u0161anas risin\u0101jumus \u2014 glob\u0101los. Paties\u012bb\u0101 tas ir daudzl\u012bme\u0146u atsl\u0113gu kopums ar da\u017e\u0101d\u0101m papildu iesp\u0113j\u0101m, piem\u0113ram, dar\u012bjumiem, \u0101tr\u0101m funkcij\u0101m datu koku apgait\u0113, blo\u0137\u0113\u0161anu un savu ObjectScript valodu.<\/p>\n<p>Pla\u0161\u0101k par glob\u0101liem rakstu cikl\u0101 \"Glob\u0101li \u2014 datu glab\u0101\u0161anas zobeni-k\u013cadences\":<\/p>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/intersystems\/blog\/263791\/\">Koki. 1. da\u013ca<\/a><\/noindex> <br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/intersystems\/blog\/264173\/\">Koki. 2. da\u013ca<\/a><\/noindex><br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/intersystems\/blog\/268465\/\">Retin\u0101ti mas\u012bvi. 3. da\u013ca<\/a><\/noindex><\/p>\n<p>Mani interes\u0113ja, k\u0101 tiek \u012bstenoti dar\u012bjumi glob\u0101los, k\u0101das ir to \u012bpatn\u012bbas. Jo t\u0101 ir piln\u012bgi cita datu glab\u0101\u0161anas strukt\u016bra nek\u0101 visiem ierast\u0101s tabulas. Kaut kas daudz zem\u0101ka l\u012bme\u0146a.<br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><br \/>\nK\u0101 zin\u0101ms, no rel\u0101ciju datu b\u0101zu teorijas laba dar\u012bjumu \u012bsteno\u0161ana j\u0101atbilst pras\u012bb\u0101m <noindex><a rel=\"nofollow\" href=\"https:\/\/ru.wikipedia.org\/wiki\/ACID\">ACID<\/a><\/noindex>:<\/p>\n<p><b>A \u2014 Atomiskums.<\/b> Visas izmai\u0146as, kas veiktas dar\u012bjuma laik\u0101, tiek ierakst\u012btas vai nekas netiek ierakst\u012bts.<\/p>\n<p><b>S \u2014 Saska\u0146ot\u012bba.<\/b> P\u0113c dar\u012bjuma pabeig\u0161anas datu b\u0101zes lo\u0123iskajam st\u0101voklim j\u0101b\u016bt iek\u0161\u0113ji konsekventam. Da\u013c\u0113ji \u0161\u012b pras\u012bba attiecas uz programm\u0113t\u0101ju, bet SQL datu b\u0101z\u0113m t\u0101 attiecas ar\u012b uz \u0101r\u0113j\u0101m atsl\u0113g\u0101m.<\/p>\n<p><b>I \u2014 Izol\u0101cija.<\/b> Vienlaikus notieko\u0161iem dar\u012bjumiem nedr\u012bkst ietekm\u0113t cits citu.<\/p>\n<p><b>D \u2014 Ilgtsp\u0113ja.<\/b> P\u0113c veiksm\u012bgas dar\u012bjuma pabeig\u0161anas probl\u0113m\u0101m apak\u0161\u0113j\u0101s l\u012bme\u0146os (piem\u0113ram, baro\u0161anas trauc\u0113jumi) nedr\u012bkst ietekm\u0113t ar dar\u012bjumu main\u012btajiem datiem.<\/p>\n<p>Glob\u0101li ir norel\u0101ciju datu strukt\u016bras. T\u0101s tika izstr\u0101d\u0101tas super \u0101trai darb\u012bbai uz \u013coti ierobe\u017eota dzel\u017eiem. Apskat\u012bsim dar\u012bjumu \u012bsteno\u0161anu glob\u0101los ar <noindex><a rel=\"nofollow\" href=\"https:\/\/hub.docker.com\/_\/intersystems-iris-data-platform\/plans\/222f869e-567c-4928-b572-eb6a29706fbd?tab=instructions\">ofici\u0101lo IRIS docker att\u0113lu<\/a><\/noindex>.<\/p>\n<p>Lai atbalst\u012btu dar\u012bjumus IRIS, tiek izmantotas komandas: <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.intersystems.com\/irislatest\/csp\/docbook\/DocBook.UI.Page.cls?KEY=RCOS_ctstart\">TSTART<\/a><\/noindex>, <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.intersystems.com\/irislatest\/csp\/docbook\/DocBook.UI.Page.cls?KEY=RCOS_ctcommit\">TCOMMIT<\/a><\/noindex>, <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.intersystems.com\/irislatest\/csp\/docbook\/DocBook.UI.Page.cls?KEY=RCOS_ctrollback\">TROLLBACK<\/a><\/noindex>.<\/p>\n<h2>1. Atomiskums<\/h2>\n<p>\nVisviegl\u0101k ir p\u0101rbaud\u012bt atomiskumu. P\u0101rbaud\u0101m datu b\u0101zes konsol\u0113.<\/p>\n<pre><code class=\"bash\">Kill ^a\nTSTART\nSet ^a(1) = 1\nSet ^a(2) = 2\nSet ^a(3) = 3\nTCOMMIT<\/code><\/pre>\n<p>\nP\u0113c tam izdar\u0101m secin\u0101jumu:<\/p>\n<pre><code class=\"bash\">Write ^a(1), \u201c \u201d, ^a(2), \u201c \u201d, ^a(3)<\/code><\/pre>\n<p>\nIeg\u016bsim:<\/p>\n<pre><code class=\"bash\">1 2 3<\/code><\/pre>\n<p>\nViss ir k\u0101rt\u012bb\u0101. Atomiskums ir saglab\u0101ts: visas izmai\u0146as ir ierakst\u012btas.<\/p>\n<p>Apgr\u016btin\u0101sim uzdevumu, ievie\u0161ot k\u013c\u016bdu un skat\u012bsim, k\u0101 saglab\u0101sies dar\u012bjums, da\u013c\u0113ji vai pavisam n\u0113.<\/p>\n<p>V\u0113lreiz p\u0101rbaud\u012bsim atomiskumu:<\/p>\n<pre><code class=\"bash\">Kill ^A\nTSTART\nSet ^a(1) = 1\nSet ^a(2) = 2\nSet ^a(3) = 3<\/code><\/pre>\n<p>\nP\u0113c tam piespied\u012bsim apst\u0101ties konteineram, palaid\u012bsim un paskat\u012bsimies. <\/p>\n<pre><code class=\"bash\">docker kill my-iris<\/code><\/pre>\n<p>\n\u0160\u012b komanda ir praktiski ekvivalenta piespiedu izsl\u0113g\u0161anai, jo t\u0101 nos\u016bta t\u016bl\u012bt\u0113ju procesa SIGKILL aptur\u0113\u0161anas sign\u0101lu.<\/p>\n<p>Vai dar\u012bjums varb\u016bt ir saglab\u0101jies da\u013c\u0113ji?<\/p>\n<pre><code class=\"bash\">WRITE ^a(1), ^a(2), ^a(3)\n^\n ^a(1)<\/code><\/pre>\n<p>\n \u2014 N\u0113, tas nav saglab\u0101jies.<\/p>\n<p>Izm\u0113\u0123in\u0101sim atjauno\u0161anas komandu:<\/p>\n<pre><code class=\"bash\">Kill ^A\nTSTART\nSet ^a(1) = 1\nSet ^a(2) = 2\nSet ^a(3) = 3\nTROLLBACK\n\nWRITE ^a(1), ^a(2), ^a(3)\n^\n ^a(1)<\/code><\/pre>\n<p>\nAr\u012b nekas nav saglab\u0101jies.<\/p>\n<h2>2. Saska\u0146ot\u012bba<\/h2>\n<p>\nT\u0101 k\u0101 globaliz\u0101cijas datub\u0101z\u0113s atsl\u0113gas tiek veidotas ar\u012b uz globaliz\u0101cij\u0101m (atg\u0101dinu, ka globaliz\u0101cija ir zem\u0101ka l\u012bme\u0146a datu glab\u0101\u0161anas strukt\u016bra nek\u0101 rel\u0101ciju tabula), lai izpild\u012btu saska\u0146ot\u012bbas pras\u012bbas, atsl\u0113gas izmai\u0146ai ir j\u0101b\u016bt iek\u013cautai taj\u0101 pa\u0161\u0101 dar\u012bjum\u0101 k\u0101 globaliz\u0101cijas izmai\u0146\u0101m.<\/p>\n<p>Piem\u0113ram, mums ir globaliz\u0101cija ^person, kur\u0101 m\u0113s glab\u0101jam personas un k\u0101 atsl\u0113gu izmantojam INN.<\/p>\n<pre><code class=\"bash\">^person(1234567, \u2018firstname\u2019) = \u2018Sergejs\u2019\n^person(1234567, \u2018lastname\u2019) = \u2018Kamenevs\u2019\n^person(1234567, \u2018phone\u2019) = \u2018+74995555555\n...<\/code><\/pre>\n<p>\nLai veiktu \u0101tru mekl\u0113\u0161anu p\u0113c uzv\u0101rda un v\u0101rda, m\u0113s izveidoj\u0101m atsl\u0113gu ^index.<\/p>\n<pre><code class=\"bash\">^index(\u2018Kamenevs\u2019, \u2018Sergejs\u2019, 1234567) = 1<\/code><\/pre>\n<p>\nLai datub\u0101ze b\u016btu saska\u0146ota, mums j\u0101ievieto persona \u0161\u0101di:<\/p>\n<pre><code class=\"bash\">TSTART\n^person(1234567, \u2018firstname\u2019) = \u2018Sergejs\u2019\n^person(1234567, \u2018lastname\u2019) = \u2018Kamenevs\u2019\n^person(1234567, \u2018phone\u2019) = \u2018+74995555555\n^index(\u2018Kamenevs\u2019, \u2018Sergejs\u2019, 1234567) = 1\nTCOMMIT<\/code><\/pre>\n<p>\nAtbilsto\u0161i, izdz\u0113\u0161ot, mums ar\u012b ir j\u0101izmanto dar\u012bjums:<\/p>\n<pre><code class=\"bash\">TSTART\nKill ^person(1234567)\nZKill ^index(\u2018Kamenevs\u2019, \u2018Sergejs\u2019, 1234567)\nTCOMMIT<\/code><\/pre>\n<p>\nCit\u0101di sakot, saska\u0146ot\u012bbas pras\u012bbu izpilde gultas piln\u012bb\u0101 uz programmat\u016bras izstr\u0101d\u0101t\u0101ja pleciem. Bet run\u0101jot par globaliz\u0101cij\u0101m, tas ir dabiski, \u0146emot v\u0113r\u0101 to zemo l\u012bme\u0146a dabu.<\/p>\n<h2>3. Izol\u0113t\u012bba<\/h2>\n<p>\n\u0160eit s\u0101kas sare\u017e\u0123\u012bjumi. Daudzi lietot\u0101ji vienlaikus str\u0101d\u0101 ar to pa\u0161u datub\u0101zi, maina tos pa\u0161us datus.<\/p>\n<p>Situ\u0101cija ir sal\u012bdzin\u0101ma ar to, ka daudzi lietot\u0101ji vienlaikus str\u0101d\u0101 pie viena un t\u0101 pa\u0161a koda repozit\u0101ra un m\u0113\u0123ina vienlaikus taj\u0101 veikt izmai\u0146as daudzos failos.<\/p>\n<p>Datub\u0101zei ir j\u0101risina viss \u0161is re\u0101laj\u0101 laik\u0101. \u0145emot v\u0113r\u0101, ka nopietn\u0101s komp\u0101nij\u0101s ir pat speci\u0101la persona, kas atbild par versiju kontroles (par zaru apvieno\u0161anu, konfliktu risin\u0101\u0161anu utt.), un datub\u0101zei tas viss j\u0101risina re\u0101laj\u0101 laik\u0101, k\u013c\u016bst ac\u012bmredzama uzdevuma sare\u017e\u0123\u012bt\u012bba un pareiz\u0101 datub\u0101zes un t\u0101s apkopes koda projekt\u0113\u0161ana.<\/p>\n<p>Datu b\u0101ze nevar saprast, k\u0101 lietot\u0101ji r\u012bkojas, lai nov\u0113rstu konfliktus, ja vi\u0146i str\u0101d\u0101 ar tiem pa\u0161iem datiem. T\u0101 var tikai atcelt vienu dar\u012bjumu, kas ir pretrun\u0101 ar citu, vai veikt tos sec\u012bgi.<\/p>\n<p>V\u0113l viena probl\u0113ma ir t\u0101, ka dar\u012bjuma izpildes laik\u0101 (pirms apstiprin\u0101\u0161anas) datu b\u0101zes st\u0101voklis var b\u016bt nesaska\u0146ots, t\u0101p\u0113c ir v\u0113lams, lai citiem dar\u012bjumiem neb\u016btu piek\u013cuves nesaska\u0146otajam datu b\u0101zes st\u0101voklim, ko rel\u0101ciju datu b\u0101z\u0113s var sasniegt daudziem veidiem: snapshotu izveide, vair\u0101ku versiju rindi\u0146as utt.<\/p>\n<p>Veicot dar\u012bjumus paral\u0113li, ir svar\u012bgi, lai tie netrauc\u0113tu viens otram. Tas ir izol\u0101cijas \u012bpa\u0161ums.<\/p>\n<p>SQL nosaka 4 izol\u0101cijas l\u012bme\u0146us:<\/p>\n<ul>\n<li>READ UNCOMMITTED<\/li>\n<li>READ COMMITTED<\/li>\n<li>REPEATABLE READ<\/li>\n<li>SERIALIZABLE<\/li>\n<\/ul>\n<p>\nApskat\u012bsim katru l\u012bmeni atsevi\u0161\u0137i. Izpildes izmaksas katram l\u012bmenim pieaug gandr\u012bz eksponenci\u0101li.<\/p>\n<p><b>READ UNCOMMITTED<\/b> \u2014 tas ir zem\u0101kais izol\u0101cijas l\u012bmenis, ta\u010du taj\u0101 pa\u0161\u0101 laik\u0101 ar\u012b vis\u0101tr\u0101kais. Dar\u012bjumi var las\u012bt izmai\u0146as, ko veiku\u0161i viens otru.<\/p>\n<p><b>READ COMMITTED<\/b> \u2014 tas ir n\u0101kamais izol\u0101cijas l\u012bmenis, kas ir kompromiss. Dar\u012bjumi nevar las\u012bt izmai\u0146as, ko veiku\u0161i viens otru l\u012bdz apstiprin\u0101\u0161anai, bet var las\u012bt jebkuras izmai\u0146as, kas veiktas p\u0113c apstiprin\u0101\u0161anas.<\/p>\n<p>Ja mums ir gar\u0161 dar\u012bjums T1, kur\u0101 laik\u0101 notiek apstiprin\u0101jumi dar\u012bjumos T2, T3 ... Tn, kas str\u0101d\u0101 ar tiem pa\u0161iem datiem k\u0101 T1, tad, veicot datu piepras\u012bjumus T1, m\u0113s katru reizi sa\u0146emsim at\u0161\u0137ir\u012bgu rezult\u0101tu. \u0160is fenomens tiek saukts par nep\u0101rtraukto las\u012bjumu.<\/p>\n<p><b>REPEATABLE READ<\/b> \u2014 \u0161aj\u0101 izol\u0101cijas l\u012bmen\u012b mums nav nep\u0101rtraukta las\u012bjuma fenomena, jo katram datu las\u012b\u0161anas piepras\u012bjumam tiek izveidots datu rezult\u0101tu att\u0113ls un, atk\u0101rtoti lietojot \u0161aj\u0101 pa\u0161\u0101 dar\u012bjum\u0101, tiek izmantoti dati no att\u0113la. Tom\u0113r \u0161aj\u0101 izol\u0101cijas l\u012bmen\u012b ir iesp\u0113jams las\u012bt fantomu datus. Tiek dom\u0101ts las\u012bt jaunas rindas, kas tika pievienotas paral\u0113li fiks\u0113tiem dar\u012bjumiem.<\/p>\n<p><b>SERIALIZABLE<\/b> \u2014 visaugst\u0101kais izol\u0101cijas l\u012bmenis. To raksturo tas, ka dati, kas tiek k\u0101d\u0101 veid\u0101 izmantoti dar\u012bjum\u0101 (las\u012b\u0161ana vai main\u012b\u0161ana), k\u013c\u016bst pieejami citiem dar\u012bjumiem tikai p\u0113c pirm\u0101 dar\u012bjuma pabeig\u0161anas.<\/p>\n<p>S\u0101ksim ar to, vai oper\u0101ciju izol\u0101cija dar\u012bjum\u0101 ir no galven\u0101 pl\u016bsm\u0101. Atv\u0113rsim 2 termin\u0101la logus.<\/p>\n<pre><code class=\"bash\">Kill ^t\n\nWrite ^t(1)\n2<\/code><\/pre>\n<pre><code class=\"bash\">\nTSTART\nSet ^t(1)=2<\/code><\/pre>\n<p>\nIzol\u0101cijas nav. Viena pl\u016bsma redz, ko dara otra, kas atv\u0113rusi dar\u012bjumu.<\/p>\n<p>Paskat\u012bsimies, vai da\u017e\u0101du pl\u016bsmu dar\u012bjumi redz to, kas notiek iek\u0161ien\u0113. <\/p>\n<p>Atv\u0113rsim 2 termin\u0101la logus un uzs\u0101ksim 2 dar\u012bjumus paral\u0113li.<\/p>\n<pre><code class=\"bash\">kill ^t\nTSTART\nWrite ^t(1)\n3<\/code><\/pre>\n<pre><code class=\"bash\">\nTSTART\nSet ^t(1)=3\n<\/code><\/pre>\n<p>\nParal\u0113lie dar\u012bjumi redz viens otra datus. T\u0101tad, m\u0113s sa\u0146\u0113m\u0101m visvienk\u0101r\u0161\u0101ko, bet ar\u012b vis\u0101tr\u0101ko izol\u0101cijas l\u012bmeni READ UNCOMMITED.<\/p>\n<p>Princip\u0101 to var\u0113ja gaid\u012bt glob\u0101lajiem main\u012bgajiem, kuros veiktsp\u0113ja vienm\u0113r bijusi priorit\u0101te. <\/p>\n<p>Ko dar\u012bt, ja mums nepiecie\u0161ams augst\u0101ks izol\u0101cijas l\u012bmenis darb\u012bb\u0101m ar glob\u0101lajiem main\u012bgajiem?<\/p>\n<p>\u0160eit j\u0101padom\u0101, k\u0101p\u0113c visp\u0101r ir nepiecie\u0161ami izol\u0101cijas l\u012bme\u0146i un k\u0101 tie darbojas.<\/p>\n<p>Augst\u0101kais izol\u0101cijas l\u012bmenis SERIALIZE noz\u012bm\u0113, ka paral\u0113li izpild\u012bto dar\u012bjumu rezult\u0101ts ir ekvivalents to sec\u012bgajai izpildei, kas garant\u0113 kol\u012bziju tr\u016bkumu.<\/p>\n<p>To m\u0113s varam sasniegt ar pareiz\u0101m blo\u0137\u0113\u0161an\u0101m ObjectScript, kur\u0101m ir daudz da\u017e\u0101du pielietojumu: var veikt parasto, inkrement\u0101lo, vair\u0101ku blo\u0137\u0113\u0161anu ar komandu <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.intersystems.com\/latest\/csp\/docbook\/DocBook.UI.Page.cls?KEY=RCOS_clock\">LOCK<\/a><\/noindex>.<\/p>\n<p>Zem\u0101ki izol\u0101cijas l\u012bme\u0146i ir kompromisi, kuriem m\u0113r\u0137is ir palielin\u0101t datu b\u0101zes darb\u012bbas \u0101trumu.<\/p>\n<p>Paskat\u012bsimies, k\u0101 m\u0113s varam sasniegt da\u017e\u0101dus izol\u0101cijas l\u012bme\u0146us ar blo\u0137\u0113\u0161an\u0101m.<\/p>\n<p>\u0160is operators \u013cauj ieg\u016bt ne tikai ekskluz\u012bvas blo\u0137\u0113\u0161anas, kas nepiecie\u0161amas datu izmai\u0146\u0101m, bet ar\u012b t\u0101 saukt\u0101s koplieto\u0161anas blo\u0137\u0113\u0161anas, kuras var veikt paral\u0113li vair\u0101ki pl\u016bsmu, kad t\u0101m vajag las\u012bt datus, kuriem nevajadz\u0113tu tikt main\u012btiem citu procesu laik\u0101 las\u012b\u0161anas proces\u0101.<\/p>\n<p>S\u012bk\u0101k par divf\u0101\u017eu blo\u0137\u0113\u0161anu krievu un ang\u013cu valod\u0101:<\/p>\n<p>\u2192 <noindex><a rel=\"nofollow\" href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%B2%D1%83%D1%85%D1%84%D0%B0%D0%B7%D0%BD%D0%B0%D1%8F_%D0%B1%D0%BB%D0%BE%D0%BA%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0\">Divf\u0101\u017eu blo\u0137\u0113\u0161ana<\/a><\/noindex><br \/>\n\u2192 <noindex><a rel=\"nofollow\" href=\"https:\/\/en.wikipedia.org\/wiki\/Two-phase_locking\">Two-phase locking<\/a><\/noindex><\/p>\n<p>Gr\u016bt\u012bba ir t\u0101da, ka dar\u012bjuma laik\u0101 datu b\u0101zes st\u0101voklis var b\u016bt nesak\u0101rtots, tom\u0113r \u0161ie nesak\u0101rtotie dati ir redzami citiem procesiem. K\u0101 to nov\u0113rst?<\/p>\n<p>M\u0113s izveidosim ar blo\u0137\u0113\u0161an\u0101m t\u0101das redzam\u012bbas logus, kuros datu b\u0101zes st\u0101voklis b\u016bs sak\u0101rtots. Un visi piepras\u012bjumi uz \u0161\u0101diem redzam\u012bbas logiem ar sak\u0101rtoto st\u0101vokli tiks kontrol\u0113ti ar blo\u0137\u0113\u0161an\u0101m.<\/p>\n<p>Koplietojam\u0101s blo\u0137\u0113\u0161anas m\u0113r\u0137is ir aizsarg\u0101t vien\u0101das datus no daudzk\u0101rt\u0113jas piek\u013cuves \u2014 t\u0101s var ieg\u016bt vair\u0101ki procesi. \u0160\u012bs blo\u0137\u0113\u0161anas nov\u0113r\u0161 citu procesu iesp\u0113ju main\u012bt datus, t.i., t\u0101s tiek izmantotas, lai izveidotu saska\u0146otu datu b\u0101zes st\u0101vok\u013ca logus.<\/p>\n<p>Ekskluz\u012bv\u0101s blo\u0137\u0113\u0161anas tiek izmantotas datu izmai\u0146\u0101m \u2014 \u0161\u0101du blo\u0137\u0113\u0161anu var ieg\u016bt tikai viens process. Ekskluz\u012bvo blo\u0137\u0113\u0161anu var ieg\u016bt:<\/p>\n<ol>\n<li>Jebkur\u0161 process, ja dati ir br\u012bvi.<\/li>\n<li>Tikai tas process, kuram ir uz \u0161iem datiem shared blo\u0137\u0113\u0161ana un kur\u0161 pirmais piepras\u012bja ekskluz\u012bvo blo\u0137\u0113\u0161anu.<\/li>\n<\/ol>\n<p>\n<img decoding=\"async\" alt=\"Transakcijas glob\u0101los InterSystems IRIS\" src=\"\/wp-content\/uploads\/2019\/07\/bb91ed1268925bc1b9266763ab82646a.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\nJo \u0161aur\u0101ka ir redzam\u012bbas loga robe\u017ea, jo ilg\u0101k citi procesi to gaida, bet tas \u013cauj saglab\u0101t saska\u0146ot\u0101ku datu b\u0101zes st\u0101vokli taj\u0101.<\/p>\n<p><b>READ_COMMITED<\/b> \u2014 \u0161\u012b l\u012bme\u0146a b\u016bt\u012bba ir t\u0101da, ka m\u0113s redzam tikai citos pl\u016bsm\u0101s apstiprin\u0101tos datus. Ja dati cit\u0101 transakcij\u0101 v\u0113l nav apstiprin\u0101ti, tad m\u0113s redzam to veco versiju.<\/p>\n<p>Tas \u013cauj mums paraleliz\u0113t darbu, nevis gaid\u012bt blo\u0137\u0113\u0161anas atbr\u012bvo\u0161anu.<\/p>\n<p>Bez \u012bpa\u0161\u0101m vilt\u012bb\u0101m m\u0113s nesp\u0113sim redz\u0113t veco datu versiju IRIS, t\u0101p\u0113c mums n\u0101ksies iztikt ar blo\u0137\u0113\u0161an\u0101m.<\/p>\n<p>Attiec\u012bgi mums b\u016bs j\u0101at\u013cauj datu las\u012b\u0161ana ar shared blo\u0137\u0113\u0161an\u0101m tikai saska\u0146ot\u012bbas br\u012b\u017eos.<\/p>\n<p>Pie\u0146emsim, ka mums ir lietot\u0101ju datu b\u0101ze ^person, kuri p\u0101rskaita naudu viens otram.<\/p>\n<p>Naudas p\u0101rskait\u012b\u0161ana no personas 123 uz personu 242:<\/p>\n<pre><code class=\"bash\">LOCK +^person(123), +^person(242)\nSet ^person(123, amount) = ^person(123, amount) - amount\nSet ^person(242, amount) = ^person(242, amount) + amount\nLOCK -^person(123), -^person(242)<\/code><\/pre>\n<p>\nNaudas summas piepras\u012b\u0161ana no personas 123 pirms norakst\u012b\u0161anas prasa ekskluz\u012bvo blo\u0137\u0113\u0161anu (p\u0113c noklus\u0113juma):<\/p>\n<pre><code class=\"bash\">LOCK +^person(123)\nWrite ^person(123)<\/code><\/pre>\n<p>\nJa nepiecie\u0161ams par\u0101d\u012bt konta st\u0101vokli person\u012bgaj\u0101 kabinet\u0101, tad var izmantot shared blo\u0137\u0113\u0161anu vai visp\u0101r to neizmantot:<\/p>\n<pre><code class=\"bash\">LOCK +^person(123)#\u201dS\u201d\nWrite ^person(123)<\/code><\/pre>\n<p>\nTom\u0113r, pie\u0146emot, ka dar\u012bjumi ar datu b\u0101zi notiek praktiski uzreiz (atg\u0101dinu, ka glob\u0101l\u0101s datu strukt\u016bras ir daudz zem\u0101ka l\u012bme\u0146a nek\u0101 rel\u0101ciju tabulas), tad \u0161\u012b l\u012bme\u0146a nepiecie\u0161am\u012bba samazin\u0101s.<\/p>\n<p><b>REPEATABLE READ<\/b> \u2014 \u0161aj\u0101 izol\u0101cijas l\u012bmen\u012b ir at\u013cauts, ka var b\u016bt vair\u0101kas datu las\u012b\u0161anas, kuras var main\u012bt paral\u0113las transakcijas. <\/p>\n<p>Attiec\u012bgi mums b\u016bs j\u0101izmanto shared blo\u0137\u0113\u0161ana datu las\u012b\u0161anai, kuras m\u0113s main\u0101m, un ekskluz\u012bv\u0101s blo\u0137\u0113\u0161anas uz datiem, kurus m\u0113s main\u0101m.<\/p>\n<p>Operator LOCK allows you to detail all the necessary locks within a single operator, which can be quite numerous.<\/p>\n<pre><code class=\"bash\">LOCK +^person(123, amount)#\u201dS\u201d\nreading ^person(123, amount)<\/code><\/pre>\n<p>\nother operations (at this time parallel streams try to modify ^person(123, amount), but cannot)<\/p>\n<pre><code class=\"bash\">LOCK +^person(123, amount)\nmodifying ^person(123, amount)\nLOCK -^person(123, amount)\n\nreading ^person(123, amount)\nLOCK -^person(123, amount)#\u201dS\u201d<\/code><\/pre>\n<p>\nWhen listing locks separated by commas, they are taken sequentially, but if you do it this way:<\/p>\n<pre><code class=\"bash\">LOCK +(^person(123),^person(242))<\/code><\/pre>\n<p>\nthen they are taken atomically all at once.<\/p>\n<p><b>SERIALIZE<\/b> \u2014 we will have to set the locks so that ultimately all transactions that have shared data are executed sequentially. For this approach, most locks must be exclusive and taken on the smallest areas of the global for performance.<\/p>\n<p>If we talk about withdrawals from the global ^person, then only the SERIALIZE isolation level is acceptable, as money must be spent strictly sequentially; otherwise, it is possible to spend the same amount multiple times.<\/p>\n<h2>4. Longevity<\/h2>\n<p>\nI conducted tests with a hard shutdown of the container by<\/p>\n<pre><code class=\"bash\">docker kill my-iris<\/code><\/pre>\n<p>\nThe database handled it well. No problems were identified.<\/p>\n<h2>Secin\u0101jums<\/h2>\n<p>\nFor globals in InterSystems IRIS, there is support for transactions. They are truly atomic and reliable. To ensure database consistency in globals, programming effort and the use of transactions are necessary, as there are no complex built-in constructs like foreign keys.<\/p>\n<p>The isolation level for globals without the use of locks is READ UNCOMMITTED, while by using locks, it can be ensured up to the SERIALIZE level.<\/p>\n<p>The correctness and speed of transaction operations on globals strongly depend on the programmer\u2019s skill: the more widely shared locks are used during reading, the higher the isolation level, and the more narrowly exclusive locks are taken, the greater the performance.<br \/>\n<br \/>Avots: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/461753\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0421\u0423\u0411\u0414 InterSystems IRIS \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0433\u043b\u043e\u0431\u0430\u043b\u044b. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043c\u043d\u043e\u0433\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043b\u044e\u0448\u043a\u0430\u043c\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u044f\u0437\u044b\u043a\u0430 ObjectScript. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0433\u043b\u043e\u0431\u0430\u043b\u0430\u0445 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441\u0442\u0430\u0442\u0435\u0439 \u00ab\u0413\u043b\u043e\u0431\u0430\u043b\u044b \u2014 \u043c\u0435\u0447\u0438-\u043a\u043b\u0430\u0434\u0435\u043d\u0446\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445\u00bb: \u0414\u0435\u0440\u0435\u0432\u044c\u044f. \u0427\u0430\u0441\u0442\u044c 1 \u0414\u0435\u0440\u0435\u0432\u044c\u044f. \u0427\u0430\u0441\u0442\u044c 2 \u0420\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b. \u0427\u0430\u0441\u0442\u044c [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":27448,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-36650","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.5 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0421\u0423\u0411\u0414 InterSystems IRIS \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/lv\/blog\/administrirovanie\/tranzaktsii-v-globalah-intersystems-iris\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.5\" \/>\n\t\t<meta property=\"og:locale\" content=\"lv_LV\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u0430\u0445 InterSystems IRIS | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0421\u0423\u0411\u0414 InterSystems IRIS \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/lv\/blog\/administrirovanie\/tranzaktsii-v-globalah-intersystems-iris\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T19:12:54+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T19:12:54+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Transactions in globals InterSystems IRIS | ProHoster","description":"The InterSystems IRIS DBMS supports interesting structures.","canonical_url":"https:\/\/prohoster.info\/lv\/blog\/administrirovanie\/tranzaktsii-v-globalah-intersystems-iris","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"lv_LV","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0422\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u0430\u0445 InterSystems IRIS | ProHoster","og:description":"\u0421\u0423\u0411\u0414 InterSystems IRIS \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.","og:url":"https:\/\/prohoster.info\/lv\/blog\/administrirovanie\/tranzaktsii-v-globalah-intersystems-iris","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T19:12:54+00:00","article:modified_time":"2019-10-31T19:12:54+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"36650","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-22 04:17:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-03-01 01:41:52","updated":"2026-01-22 04:17:19","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/posts\/36650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/comments?post=36650"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/posts\/36650\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/media\/27448"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/media?parent=36650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/categories?post=36650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/lv\/wp-json\/wp\/v2\/tags?post=36650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}