Welcome back to the TRANSACTION!
æè¿ããã©ã³ã¶ã¯ã·ã§ã³ã®ååå¼·ãå§ãã¦ãã¦ãå æ¥ã¯ã©ã¦ã温æ³ã§ãçºè¡¨ããã¦ããã£ãæåãã¡ããã©ããã®ã§ä¸åã¾ã¨ãã¦ãããã¯ããã«æã£ã¦ããã¨èªåã¯å¥ã«DBãTXã®å°é家ã§ã¯ãªãããªã®ã§ä»¥ä¸ã®å 容ã®æ£ç¢ºæ§ã«ã¤ãã¦ã¯ä¿è¨¼ããªããå 容ã«ã¤ãã¦ã¯èªåã§åå¼·ãã¦ãã ãããã
1.ããªãã§ã¾ãTXãªã®ãã
ã¾ããã£ã¦ä½æ
ã«TXãªã®ãï¼ã¨ããã話ããå§ãã¾ããããæ¯ãã¦ããããªããï¼ä»é RDBMSã§ããªãã ãããããã¯ããã§ããã以ä¸ã®æµãã¯ç¡è¦ã§ãã¾ããã
ã»RDBMSã®ç¹è¨±åã
NIIã®ä½è¤å
çã®ææã«ãããããã«ã1980-90年代ã®RDBMSé¢é£ã®ç¹è¨±ãåãå§ãã¾ããããã«ããåç¨ä¸è¾ºåã§ãOSSã§ã¯ã©ããã¦ãåã¦ãªãã£ãRDBMSã§ã®æè¡é©æ°ãããã®æè¡ãå¿ç¨ããå¥ã®ãã®ï¼RDBMSã¨ã¯éãã¾ããï¼ãç»å ´ãã¦ããå¯è½æ§ãé«ãã§ããåãã³ãã¼ããããè¦è¶ãã¦ãä¸æã«RDBMSé¢é£ã¸ã®ãéå¼µãããå§ãã¦ããããã§ãã
ã»åæ£ç°å¢ã®ä¸è¬åã«ä¼´ããTXå¦çã®éè¦æ§ã®åãã©ã¼ã«ã¹
ããã ãæ°ãã§ã¦æ¸ç±ã»æ
å ±ãåºã¦ããNoSQLãã©ããã¦ãä»ä¸æ®åããªãçç±ã®ä¸ã¤ã¯TXå¦çããªããã¨ã«ããã¾ããä¸è¬ã«åæ£ç°å¢ä¸ã§ã¯æ¬è³ªçã«âä¸è²«æ§âã®ç¢ºä¿ãå°é£ã§ãããã¨ã¯å¨ç¥ã®éãã§ããã¨ã¯ãããããããâä¸è²«æ§âã®ãªãã·ã¹ãã ã¯å°åºã«å®ç¨ã«å ªããããã®ã§ã¯ããã¾ãããããã§ã¯ãã©ã®ã¬ãã«ã®âä¸è²«æ§âãéè¦ãªã®ããã¨ãã話ã«ãªãã¾ããå½ç¶ããã®èæ¯ã«ãããã®ã¯ãããããâä¸è²«æ§âã¨ã¯ä½ãªã®ãï¼ã¨ããè°è«ãè¸ã¾ããå¿
è¦ãããã¾ãããã®è°è«ã®åºçºç¹ã¯ãã©ã³ã¶ã¯ã·ã§ã³å¦çãå·¡ãç 究ã»å®è£
ã»å®ç¸¾ãããã¾ãã¯åºã¦ããã®ã¯è«ãå¾
ã¡ã¾ãããï¼ãã¡ãããããã ãã§ã¯ãªãã§ããï¼
ã¨ããããæ¤è¨ãã¹ããã¸ãã¹ã³ã³ãã¯ã¹ãã¯ä»¥ä¸ããã§æ¬è«ã
2. TXã®å¤§äºãªæ¬è³ªãcorrectness
ï¼æåã«ãæãã§ããã以ä¸ã®è°è«ã§ã¯åä¸ãã¼ãã§ã®TXãåæã¨ãã¾ããåæ£ç°å¢ã®ä¸è²«æ§ã¯ã¾ãéãè¦ç´ ãå ¥ã£ã¦ãããããããªãä¸è²«æ§ã¨ããè¨èã§ãã«ãã¼ããç¯å²ãããã«åºããã¾ããï¼
ã¾ããæåã«æè¨ãã¾ãããTXã§ãã£ã¨ãéè¦ãªå±æ§ã¯consistencyï¼âä¸è²«æ§âï¼ã§ããããããACIDå±æ§ã®ãã®ä»ã®ä¸ã¤ï¼atomic, isolated, durableï¼ã¯consistencyã«å¯¾ããè£å®çãªå½¹å²ãæºããã«éãã¾ããï¼ãã¡ããè¨ãéãã§ãããå人ã®æè¦ãªã®ã§çéé¡ãã¾ããï¼
次ã«consistentã§ãããã¨ã¯ãTXã®è°è«ã®ã³ã³ãã¯ã¹ãã§ããã¼ã¿ã®å¦çãcorrectï¼âæ£ããâï¼ã§ããããã¨ãæããã¨ãããã¾ããå¿è«correctã§ãããã¨ãconsistentã§ãããã¨ã¨åå¤ã§ãããã©ããã«ã¤ãã¦è°è«ã¯ãããã§ãããã¾ããããå°ãªãã¨ãcorrectã§ãªãå ´åã¯ãconsistentã§ã¯ãªããã¨ãããã¨ç´æçã«ããããã¨æãã¾ããå¾ã£ã¦ãã¾ãã¯ä½ãcorrectãï¼ã¨ããã¨ããã«ç¦ç¹ãå½ã¦ãè°è«ãè¦ã¦ããã¾ãããã
ä»ã大ä¸æ®µã«correctã¨ããã¯ã¼ããç»å ´ãã¦ãã¾ããããå¿è«ãæ確ãªå®ç¾©ãå¿
è¦ã§ãã
ããªãã¡ä¸å®ã®semanticsãè¨å®ãããã¨ãå¿
è¦ã«ãªãã¾ããæ段ã¨ãã¦TXã®ææ³ã¨ãããæ¯ããæ°å¦ãæºåãããã¨ã«ãªãã¾ããããã¯ãconsistencyãã®ãã®ãããcorrectnessã®æ¹ãæ¦å¿µã¨ãã¦å®å¼åãããããæä½ããããã¨ãããã¨ãç¡ç¸ã§ã¯ããã¾ãããTXãæ°çè«çå¦ã®å¿ç¨ã¨ããèãæ¹ã§ãã
ãã¦å ·ä½çã«ã©ããããã¨è¨ãã¨ãå³å¯ã«ã¯TXãæ§æè¦ç´ ãããªãã¡TXå é¨ãæ§æããread/write/commit/abortããã³ãã®ä½ç¨å¯¾è±¡ï¼ãã¼ã¸ã¾ãã¯ãªãã¸ã§ã¯ãï¼ãã¾ããããã®ã¹ãããã®é åºã»ãã¼ã¿ã®ä¾åé¢ä¿ã«å解ãã¦ãä¸ç¨®ã®å¤å¥é¢æ°ã«æ¾ãè¾¼ã¿ã¾ãããã®å¤å¥é¢æ°ã®æ»ãå¤ã®çå½ãå¤å®ãã¦ãçãªãã°correctã§ãããã¨ãã風ã«èãã¦ãããã¨ãå¯è½ã«ãªãã¾ããã»ã»ã»ã¨ããéå ·ç«ã¦ã«ãªãã¾ãã
3. Correctnessã®å¤æåºæºãserializability
ä½ãæ£ããã®ããã«ã¤ãã¦ã¯åè¿°ã®ããã«ã
ã»TXå
é¨ãæ§æããread/write/commit/abort
ã»ãã®ä½ç¨å¯¾è±¡ï¼ãã¼ã¸ã¾ãã¯ãªãã¸ã§ã¯ãï¼
ã»ãããã®ã¹ãããã®é åº
ã»ã¹ãããã¨ãã¼ã¿ã®ä¾åé¢ä¿
ãåºæºã«èãã¾ãã
ãããã®æ§æè¦ç´ ãã²ã¨ãããã«ããè¦ç´ ï¼ä»¥éãã¹ã±ã¸ã¥ã¼ã«ã¨ãã¾ããããï¼ãéåã¨ãã¦æ±ããã©ã®ãããªéåã«å±ãããï¼ã¨ãããã¨ãcorrectnessã®å¤å¥ã®æåã«ãªãã¾ãããã£ã¨ãåºæ¬çãªéåãserializableã¨å¼ã°ãããã®ã§ããæ¥æ¬èªã«ç¡ç訳ãã¨âç´ååå¯è½æ§âã§ãããï¼ã¾ã£ããé ·ãããã§ããï¼
ãã®ã³ã³ãã¯ã¹ãã§concurrencyã¨isolationã®æ¦å¿µãå°å ¥ããã¾ããããªãã¡è¤æ°ã®TXãåæå®è¡ããå ´åã«ãã©ã®ããã«ãã¦correctnessãç¶æã§ãããï¼ã¨ããåé¡ãæèµ·ããã¾ããè¤æ°ã®TXã®å ¨ã¹ããããã·ã£ããã«ãã¦ãä¸ã¤ã®ã¹ã±ã¸ã¥ã¼ã«ãã¤ãã£ãå ´åã«ãåTXã®correctnessãä¿è¨¼ããããããªãã¡ä¸è²«æ§ãä¿è¨¼ããããã¨ãå¿ è¦ã§ãããã ããã®éã«ãå¯è½ãªéããã¿ä¸ããããã¹ã±ã¸ã¥ã¼ã«ã®æ°ãå¤ãäºï¼ããªãã¡ççéåã®è¦ç´ ãå¤ãäºï¼ãæã¾ããããã¤ãã®ã¹ã±ã¸ã¥ã¼ã«ããã¿ä¸ããã«ã¼ã«ãæéæéã«è¨ç®å¯è½ãã¤å¹³æã«å®è£ ã§ãããã¨ãæã¾ããã§ãã
ãã¦ãããã§åºæ¬ã¨ãªãserializabilityã«ã¤ãã¦ç°¡åã«ã¾ã¨ãã¾ãã端çã«ããã¨
ä¸ããããå ¨ã¦ã®TXã®ã¹ããããå«ãã¹ã±ã¸ã¥ã¼ã«ã«ã¤ãã¦ããå½è©²TXãé 次å®è¡ããçµæã¨åãâ解éâãå¾ããããã¹ã±ã¸ã¥ã¼ã«ã®éåãããã¾ãã
ãªã®ã§ãã¾ãåæã¯ãTXã®é åºå®è¡ãcorrectã§ãããã¨ããåæãããã¾ãããã®åæã®ä¸ã§ããTXã®æ§æè¦ç´ ã®çµã¿åããããã·ã£ããã«ãã¦ã¤ããããã¹ã±ã¸ã¥ã¼ã«ã«ãå½è©²TXãé åºå®è¡ãããã®ã¨ãåã解éãä¸ããããã®ã§ããã°ããã®ã¹ã±ã¸ã¥ã¼ã«ï¼serializableã§ãããããªãã¡ãcorrectã ã¨ç解ãã¦ããã ãããã¨ãããã¨ã§ãã
ãã ããããããè«ã¨ãã¦ã¯ãé åºå®è¡ãããã®ãcorrectã§ãªããã¨ãããã¨ã¯âããå¾ã¾ãâãããã¯ä¾ãã°ãã¼ã¿ã®å¶ç´æ¡ä»¶(constraint)ãè¨ãã¦correctãå¤å¥ããã¨ãããããªã±ã¼ã¹ã§ãããä¾ãã°x=yã¨ããå¶ç´ããããã¼ã¿ã«ã¤ãã¦ãããããå¥ã ã®TXãx, yã«ã¢ã¯ã»ã¹ããã¡ããã¨serializeããä¸ã§ãTX1ãx=10 TX2ãy=20ã¨æ´æ°ããã¨ãã¾ããããã¯çµæã¨ãã¦ä¸æ´å(constraint violation)ãçºçãã¾ãããã®å ´åã®correctnessã¯å¾ã§è¿°ã¹ãserializabilityãããåºãç¯å²ãã«ãã¼ããã¨ãããã¨ã«ãªãã¾ãã
å®éåé¡ã¨ãã¦ã¯ãä¸è²«æ§=consistency=correctnessã¨ãã£ã¦ããåºãæå³ã§dataã®constraintã¾ã§å«ããå ´åã¨ãããã§ã¯ãªãã¦serializableã¾ã§ã§ã¨ã©ããå ´åã¨ããããã段éãããã¨ãããã¨ã«ãªããã¨æãã¾ããä¸è¬ã«ã¯ãä¸åº¦ã«å ¨é¨constraintã¾ã§ã¾ã¨ãã¦è°è«ããã¨åæ¾ä¸è½ã«ãªãã®ã§ãserializableã¯ããã¦è°è«ãããã¨ãå¤ãããã§ããããæ®éã«constraintã¾ã§è¦éã«å ¥ãããã¨ãããã¾ããï¼inconsistent readã¯ãããèããã¨å¾®å¦ãªåé¡ãå«ã¾ãããã¨ãããã¾ãããªããããã¯TXã®å¶å¾¡ã ãã§ãªãã¢ããªã±ã¼ã·ã§ã³ãµã¤ãã«ãè¸ã¿è¾¼ã¿å 容ã«ãªããæ®éã¯ãªãããã®semanticsã«åºã¥ãæå½ãå¿ è¦ã«ãªãã¨æãã¾ããï¼
ã»ã»ã»ã»ãã®è¾ºã¯ã§ããããªãã¨ããããå¦æ´¾ãã®ãããªãã®ãã¿ããã¾ãã¦ã§ãããé常ã«èå³æ·±ãã®ã§ããããã ã§ãããæ½ãã¨æ·±æµ·ã«éããTXã®ä¸çã®è©±ã§ãããªãã¨ãããã¼ã¦ã¹ã¨ãã»ã¤ãã³ã®ç¥ã ã®æ¦ãã®æ§ç¸ãããã¾ããä¸è¬æ°é人ã¯è¦ã¦ãã ãå·»ãæ·»ããé£ããã¨ããã¬ãã«ãã¨ã
4. TXã®è§£éã¨ã¯ï¼
ãã¦ãããã§è©±ããã©ãã¦ããTXãé 次å®è¡ããçµæã¨åãâ解éâãã®ã解éãã«ã¤ãã¦èãã¾ããè¦ã¯æå³ããéãï¼ï¼è§£éï¼ã«TXãå¦çããã¦ã»ãããã¨ãããã¨ã«ãªãã¾ãããããã§ã¯ä¸»è¦³çããã¦ãå¤å¥é¢æ°ãã¸ã£ããããããã¾ãããã®ã§ããµã¯ãã¨è¿°èªè«çãå°å ¥ãã¾ãã
ããªãã¡ãã¨ã«ãã©ã³é¢æ°ãå°å
¥ãã¾ãã端çã«ããã¨ãããTXã«å±ããwriteã¯ãã®TXã«å±ããreadã®ãã¡ãå½è©²writeã®å¯¾è±¡ãreadããã¹ãããã«ä¾åãããã¨ããé¢æ°ã¨ãããTXã«å±ããreadã¯ããã®TX以åã«å§ã¾ã£ã¦ããTXã®å½è©²readãèªããã¼ã¿ã®writeã®ã¹ãããã«ä¾åãããã¨ããé¢æ°ãè¨å®ããå帰çã«é¡ããã¨ã«ãã©ã³é¢æ°ãè¨å®ãã¾ãããã§ãåæç¶æ
ãå®æ°ã¨ãã¾ãã以ä¸ã§ãæºåå®äºã§ãï¼ï¼æ°å¼ã¯å
容ã®å²ã«ã¯ä»°ã
ããè¦ããã®ã§ãã¹ï¼
ããã«ãããä¸å®ã®ã¨ã«ãã©ã³é åãæ§ç¯ããã¾ããï¼ããªãã¡ãæ§é ãã¤ãããã¾ããï¼
ããã§åTXãæ§æããã¹ãããã®è«ççãªä¾åé¢ä¿ãè©ä¾¡ããåå°ãã§ãã¾ããããã®ä¸ã§ããããããªè§£éãè¡ããã¨ãå¯è½ã«ãªãã¾ããããã¯ããªãã¡æ§ã ãªcorrectããªãã¡ããæ§ã ãªconsistencyããåå¨ãããã¨ãããã¨ãæå³ãã¾ãã
4-1ãæå¾ã«æ®ã£ããã®ã®ç¶æ
ã«ã¤ãã¦ã®ã³ã³ãã¯ã¹ããã解éã®åºç¤ã¨ããæ¹éã
ããªãã¡ã
ã»ããéåã«å±ããã¹ã±ã¸ã¥ã¼ã«ã®ä¸ã¤ãserialã§ãããï¼=çã§ããè¦ç´ ãæä½ã§ãä¸ã¤ã¯ããï¼
ã»ãã®éåã«å«ã¾ãããåã
ã®ã¹ã±ã¸ã¥ã¼ã«ã®æ§æã¹ãããã¯åä¸ã§ããã
ã»ãã®éåã«å«ã¾ãããåã
ã®ã¹ã±ã¸ã¥ã¼ã«ã®æ§ææçµã«æ®ã£ã¦ãããã¼ã¿ã«ã¤ãã¦ã®ã¨ã«ãã©ã³ã»ã»ãã³ãã£ã¯ã¹ãåãã§ããã
以ä¸ã®å ´åããã®éåãfinal state serializableã¨ãããåä¸ã®è§£éã«å±ãã¦ããã¨èãããã¨ãã§ãã¾ããé称FSRã
ä½ãè¨ã£ã¦ããã®ãã¨ããã¨ãã¾ãæå¾ã«æ®ã£ããã¼ã¿ãåãä¸ãã¦ããã®ãã¼ã¿ã¸ã®æä½ãå¦çã®éé ã«è¿½ã£ããã¦è¡ãã¾ããã¾ãwriteããã£ãå ´åã¯ããã®writeãå±ããTXå é¨ã§ã®ãã®ãã¼ã¿ã«å¯¾ããå ¨ã¦ã®readãæã¾ãã¾ãããæ¸ãåã«ã¯èªãã§ãã£ããï¼ãã£ã¦è©±ã§ãããã§ããã®readããããã以åã«ãã®ãã¼ã¿ã«ã¤ãã¦æ¸ãããå¥ã®TXã®writeãæã¾ãã¾ãããèªããã®ãªãã°ã©ã£ãã§æ¸ãã¦ãã§ããï¼ãã£ã¦è©±ã§ãããã§ããã®ã¤ãªããã追ã£ããã¦ãã£ã¦ã°ã©ããã¤ããã¨ãçµµããã§ãã¾ãããã®ãçµµããåããªãããã®ãã¼ã¿ã«å¯¾ããæä½ã¯ãããªãã³ã³ãã¯ã¹ãã§ããï¼ã£ã¦èããã£ã¦ãã¨ã§ãããã§ãåãçµµã®éåã®ãªãã®ä¸ã¤ã«å®å ¨ã«é åºå®è¡ããã¹ã±ã¸ã¥ã¼ã«ãããããã£ã¦ãã¨ã§ãã
ï¼æå¾ã®ç¶æ ã®æ¸ãè¾¼ã¿ã®ã¹ãããã ããåãã§FSRã§ãããã¨ããééã£ãæç§æ¸ãæ£è¦ããã¾ããã確å®ã«éãã®ã§æ³¨æãå¿ è¦ã§ããä»®ã«ããã§ããã°ãNPå®å ¨åé¡ã«ã¯ãªãã¾ãããï¼
4-2ãReadã®ã¹ãããã«ã¤ãã¦ã®ã³ã³ãã¯ã¹ããã解éã®åºç¤ã¨ããæ¹éã
ã»ããéåã«å±ããã¹ã±ã¸ã¥ã¼ã«ã®ä¸ã¤ãserialã§ããã
ã»ãã®éåã«å«ã¾ãããåã
ã®ã¹ã±ã¸ã¥ã¼ã«ã®æ§æã¹ãããã¯åä¸ã§ããã
ã»ãã®éåã«å«ã¾ãããåã
ã®ã¹ã±ã¸ã¥ã¼ã«ã®æ§ææçµã«æ®ã£ã¦ãããã¼ã¿ã«ã¤ãã¦ã®ã¨ã«ãã©ã³ã»ã»ãã³ãã£ã¯ã¹ãåãã§ããã
ã»ãã®éåã«å«ã¾ãããreadã®ã¹ãããã«ã¤ãã¦ã®ã¨ã«ãã©ã³ã»ã»ãã³ãã£ã¯ã¹ãåãã§ããã
以ä¸ã®å ´åããã®éåãview serializableã¨ãããããã¾ãåä¸ã®è§£éã«å±ãã¦ããã¨èãããã¨ãã§ãã¾ããé称VSRã
ããã¯FSRã§ããããã¤ããã¹ã¦ã®readã®ã³ã³ãã¯ã¹ããåãã¨ãããã¨ãæå³ãã¾ãã
åè¿°ã®ã°ã©ãã®ãçµµãã®ãã¨ãã§ããã¨ãçµµã®ãããç´°ããç·ã®ã¤ãªããï¼ã¤ã¾ãããã¹ã¦ã®èªã¿è¾¼ã¿ã«é¢ããç·ï¼ã¾ã§åãã§ããã°ãåãçµµã§ããã°åãã¨è¦ãªãã¨ãããã¨ã§ããï¼FSRã¯éä¸ã§åãã¦ãç·ããããããã¯å½±é¿ããªãã®ã§ç¡è¦ããã¨ããã¹ã¿ã³ã¹ã§ããï¼
ãã¦ãå®ã¯ä¸è¨ã®ãã¨ãã®ãçµµãåããï¼ããªãã¡ã°ã©ããåä¸ï¼ã¨ããã®ã¯ãå®ã¯æ©æ¢°çãªå¤å®ãé常ã«é¢åã¨è¨ãããæéããããã¾ããã©ããããé¢åãã¨ããã¨NPå®å ¨ãªãããé¢åã§ããï¼ããä¸å®ã®polygraphãæ³å®ãã¦ããã®é循ç°ã証æããåé¡ã§ããï¼
ãã£ã¦ãã£ã¨ç°¡åã«â解éâã§ãã¾ãããï¼ã¨ãããã¨ã«ãªãã¾ãã
4-3 ãåã¹ãããã®ç¹ã«writeã®ç«¶åç¶æ
ãã解éã®åºç¤ã¨ããæ¹éã
ä¸è¨ã®FSR/VSRã¯ã»ãã³ãã£ã¯ã¹ã解éããã«ã¯ãé常ã«ç´å¾æ§ã®ããæéã§ããããããããå
¨é¨ã®ã°ã©ããæ¸ãã¦ãã¡ãã¡è§£éããå¿
è¦ãããã大éã®TXãå¦çããã«ã¯å¹çãããããã¾ããããªã®ã§ãããå°ãç°¡åã«ã³ã³ãã¯ã¹ãã解éã§ããæéãå¿
è¦ã§ãã
ããã§ãã¼ã¿å¦çã®ç«¶åé¢ä¿ãã ããã«æ³¨ç®ãã解éãå°å ¥ãã¾ãããã®ç«¶å(conflict)ãç¹ã«ãã¼ã¿ã®æ¸ãè¾¼ã¿ã«ã¤ãã¦ã®ã¿æ³¨ç®ãã¾ããããªãã¡
w-wãããTXæ¸ãè¾¼ãã§ãå¥ã®TXãã¾ãæ¸ãè¾¼ã
w-rãããTXãæ¸ãè¾¼ãã ãã®ããå¥ã®TXãèªã¿è¾¼ã
r-wãããTXãèªã¿è¾¼ãã ãã®ããå¥ã®TXãæ¸ãè¾¼ã
ãã®ç«¶åé¢ä¿ãç¶æããã¦ããã°ãåä¸ã®ã¹ã±ã¸ã¥ã¼ã«ã¨ã¿ãªãã¨ããã解éãã§ããã¾ããã¶ã£ã¡ããr-rã®é¢ä¿ã¯é åºã¯é¢ä¿ãªãã§ããï¼ã¨ããçºæ³ã§ãããããªãã¡ãæ¸ãè¾¼ã¿ã®ç«¶åé¢ä¿ãåä¸ã§ããéåã«å±ãã¦ããã°ããã®ã¹ã±ã¸ã¥ã¼ã«ã¯ãåãã³ã³ãã¯ã¹ãã§ããã¨æå³ã§ãããã®éåãconflict serializableã¨ããã¾ããé称CSRãTXã®correctnessã®è°è«ã§ã¯ç»å ´ããªããã¨ã¯ãªããããå©ç¨ãããã³ã³ã»ããã§ãã
ã¾ããCSRã¯å¤å¥ã®ã³ã¹ããä½ãã§ãã
conflicté¢ä¿ãæåºãããã®TXã®ä¾åé¢ä¿ã®ã°ã©ããä½æãã¾ãããã¹ã¦ã®ã¹ããããæãåºãå¿
è¦ã¯ããã¾ãããconflictã®çºçããTXã ãæ½åºããã°ãã¨è¶³ãã¾ãããã®ä¸ã§ãã°ã©ãã循ç°ããªãå ´åãã¯ãããã¸ã«ã«ã½ã¼ãã«ãããTXã®ã·ã¼ã±ã³ã¹ãªé åºãä½æã§ãããã¨ãä¿è¨¼ããã¾ãã®ã§ãããªãã¡serializeãªã¹ã±ã¸ã¥ã¼ã«ãçµããã¨ãããã¨ã«ãªãã¾ãã
ä½è«ã§ããããã®conflictã¯ãå®ã¯å¾æ®µã§åºã¦ããIsolationã®anomalyã«ï¼çµæã¨ãã¦ï¼ä¸è´ãã¾ããããªãã¡ã
w-w dirty write
w-r dirty read
r-w phantom read / inconsistency read
ã§ãããããã¯æç¨ãªç¤ºåã§ãincorrectãªç¶æ
ãçºçãããªãï¼ãããã¯TXçµäºæã«ã¯invariantãä¿ã¤ï¼ã«ã¯conflictãããã«serialãªç¶æ
ã¨åãç¶æ
ã«ä¿ã¤ãï¼ã¨ãã課é¡ã«ä¸è¬ã«å¸°çããã¨ãããã¨ã§ãããã¾ããMVCCãããã§ãããä¸è¬ã«TXã®semanticsã®è°è«ã®åºçºç¹ã®ä¸ã¤ã¯ããã«ãªããã¨ãé常ã«å¤ãã§ãã
å°ãä¸è¨ã®serializableã®å
å«é¢ä¿ã¯ CSRâVSRâFSRã«ãªãã¾ãã
VSRâFSRã¯VSRã¯FSRã®ããå¶éçãªå½¢ãªã®ã§ãããã¨æãã¾ããCSRâVSRããã¾ã大ä½ããªãè·¯ç·ã§è¨¼æã§ãã¾ãããå²æãã¾ãã
5. CSRã®æ¡å¼µ
以ä¸ã¯å¤§ä½ãæ®éã®æç§æ¸ã«æ¸ãã¦ãå
容ã§ãããããã£ãããªã®ã§ãCSRã®ç¹å¾´ãçãããsubã¯ã©ã¹ãå®ç¾©ãã¦ããã®æç¨æ§ãæ¡å¼µãã¦ããã¾ããããããã¯TXã®è°è«ã§ã¯ãããã話ã§ãã
ã¾ãTX orderã¨commitã®èãæ¹ãå°å ¥ãã¦ã¿ã¾ãããã
ã¾ãé常ã«ãããã¡ãªä»®å®ã¨ãã¦ãabortãªãã§èãã¾ããããªãã¡ãããã§ã¯commitããããã®ã ãã§ã¹ã±ã¸ã¥ã¼ã«ãèãããã¨ããã¾ããï¼å®ã¯ãããã¦ãããªãã¨ããã¨ãã°CSRã§ããã«ããããããdirty readãæé¤ã§ããªãã¨ãããã¨ã«ããªãããã§ããw-rã®conflictã¯æåã®wãabortãããï¼ã¾ãã¯ããããå¯è½æ§ãããï¼ã¨correctã«ãªãã¾ããï¼
5-1. OCSR
TX orderãèãã¾ããããTX orderã¯ããã¨å¤§äºãªæ¦å¿µã§ãconflictã®é åºãå´©ããã«ãTXã®çºçé åºé ã«TXãçµäºãããï¼TXã®å®è¡ã¯å¥ã«ä¸¦åã«ãªã£ã¦ããã¾ããªãï¼ãã¨ããã«ã¼ã«ã§ããå®å
¨ã«serialã§ããªãããã¨ãã£ã¦ã§ãããã«concurrentã§ããªãã¨ããç¶æ
ã§ãè¨ã£ã¦ã¿ãã°ãã¦ã¼ã¶ã¼ããè¦ãã¨ãã«éåæã®ãªãé åºï¼å
ã«èµ°ã£ããã®ããå
ã«çµãããã§ããããã®é åºãä¿è¨¼ãããã㨠order preservationã¨è¨ãã¾ãã
TXã®é åºå®è¡ãä¿è¨¼ãããã¨ããå¶éãã¤ããCSRã®ãµãã¯ã©ã¹ãOrder-Preserving Conflict Serializablityã¨è¨ãã¾ããé称 OCSRã
ããã¯ä»¥ä¸ã®ãããªç¹å¾´ããã£ã¦ãã¾ããï¼è¨¼æã¨ãããã¾ããã©ãããã¼éã§æ³£ãã¾ãã®ã§çç¥ï¼
ã»ä¸è¬çãª2PLã§ã§ããã¹ã±ã¸ã¥ã¼ã«âOCSRãã®é¢ä¿ã«ãªã£ã¦ãã
ããã«è¨ãã¨ãlockãã¼ãã«ãæ¡å¼µããorder sharingãªlockã«ã¼ã«ã§å½¢æããã2PLã®ã¹ã±ã¸ã¥ã¼ã«ï¼ããããO2PL)ã¨ãå®å
¨ã«ä¸è´ããã¾ããããªãã¡O2PLï¼OCSRã«ãªã£ã¦ãã¾ãã
ã»OCSRãªã¹ã±ã¸ã¥ã¼ã«ã¯ãå¤å±¤ã¬ã¤ã¤ã¼ã§ã®TXå®è¡ã®åºç¤ã«ãªã
ä¸è¬ã«åç´ãªTXã¹ã±ã¸ã¥ã¼ã«ãæ¡å¼µããæä½å¯¾è±¡ããã¼ã¸ã¢ãã«ã§ã¯ãªããããä¸ä½ã®Objectã¢ãã«ãå©ç¨ãããã¨ã§ã¹ã±ã¸ã¥ã¼ãªã³ã°ã»ãã¯ã¼ãæ¡å¼µãããã¨ãå¯è½ã§ããObjectã¢ãã«ã§ã¯ãç¸äºã®æä½ã®é åºäº¤æå¯è½æ§ããã¼ã¹ã«ããreducibilityã®ã³ã³ã»ããã軸ã«serializableãã©ããã®å¤å®ãè¡ã£ã¦è¡ãã¾ããããã®éç¨ã§OCSRãå©ç¨ãããã¨ãå¯è½ã§ãã
5-2. COCSR
ã¾ããTX orderã¨ã¯å¥ã«ãcommitã®é åºãTXã®conflictã®ä¾åé åºã«åãããã¨ããå¶éã課ãã«ã¼ã«ãããã¾ãããããcommit order preservationã¨è¨ãã¾ããããã¯å®ã¯ç¹ã«abortãé害æã®å¦çãèããå ´åã«ããããã¦æå¹ãªã«ã¼ã«ã§ããé称COCSRãé常ã«éè¦ãªserializableãªã¯ã©ã¹ã§ãã
ãããã¾ã以ä¸ã®ãããªç¹å¾´ããã£ã¦ãã¾ããï¼ããã¾ã証æã¨ãããã¾ããã©ãããã¼éã§æ³£ãã¾ãã®ã§çç¥ï¼
ã»Strong 2PL(SS2PL)ã§æ§æãããã¹ã±ã¸ã¥ã¼ã«ã¨å
å«é¢ä¿ãæã¡ã¾ãã
2PLã®ä¸ã§ãw/rã¨ãã«ããã¯ãã¨ãTXã®çµäºã¾ã§ãªãªã¼ã¹ããªãã«ã¼ã«ã®2PLã§ããStrong 2PL ã§çæãããã¹ã±ã¸ã¥ã¼ã«ã¯ãCOCSRã«å®å
¨ã«å«ã¾ãã¾ãã
ããªãã¡SS2PLâCOCSR
ã»æ¥½è¦³lockå®è£
ã®ã²ã¨ã¤ã§ããforward-oriented optimistic concurrency control (FOCC)ã«ããçæãããã¹ã±ã¸ã¥ã¼ã«ã¯COCSRãä¿è¨¼ããã¾ãã
ããªãã¡FOCCâCOCSR
ã»ãã£ã¨ãåºæ¬çãªrecoveryã¹ã±ã¸ã¥ã¼ã«ã§ããrigorousnessï¼é称RGï¼ã®ã«ã¼ã«ãå®ã£ãå ´åã¯ããã®ã¹ã±ã¸ã¥ã¼ã«ã¯COCSRã§ãããã¨ãä¿è¨¼ããã¾ããï¼ããã¯å®ã¯RGï¼SS2PLã§ãããã¨ãèæ¯ã«ã¯ããã¾ããï¼
ããªãã¡ RGâCOCSR
ã»global serializabilityã¨ã®é¢ä¿
ãã£ã¨ããã¯ã¾ãå¥ã®æ©ä¼ã«ã¾ã¨ãã¾ãããåæ£TXã§ãserializabilityã¨ãããã®ãåå¨ãã¾ãããã®ãã¼ã¹ã«ãªãã¯ã©ã¹ã¨ãã¦COCSRãå©ç¨ããããã¨ãããã¾ãã
ã»å°ãåè¿°ã®OCSRã¨ã®é¢ä¿ã§ããã¨ãå
å«é¢ä¿ã«ãªã
COCSRâOCSRã«ãªãã¾ããããªãã¡COCSRâOCSRâCSRâVSRâFSR
以ä¸ã®CSRã®ãµãã¯ã©ã¹ã¯å ¨ã¦serializableã§ããã¨ãããã¨ã¯ã¤ã¾ãcorrectã§ãããããªãã¡ãconsistentã§ããã¨ãããã¨ã§ããä¸è¬ã«ãä¸è²«æ§ããããã¨ãã£ã¦ããå®ã«æ§ã ãªã«ã¼ã«ãã»ãã³ãã£ã¯ã¹ããããã¨ããããã¾ããã¾ãåãªãCSRã§ã¯ãªãããããæ¡å¼µããã¢ãã«ãTXå¦çã§ã¯æ§ã ã«æ´»ç¨ã§ãããã¨ãããããã¨æãã¾ãã
6. Isolationã¬ãã«ã¨ã¯ä½ãï¼
ãã§ãã¾ãserializableãæå¿«ã«ãªã£ãã¨ããã§ã次ã«æ®éã«ãããããã¡ãªIsolationã¬ãã«ã®è©±ãããã£ã¦ãã¾ããå®éã«RDBMã§TXå¦çãè¡ãå ´åã«è¨å®ãããã®ã§ããã
ã¾ããè¦ããã«ç¾å®ã®è©±ã¯ã©ããï¼ã¨ããè°è«ãå ãã¦ã¿ã¾ããããã¨ãããã¨ã§ãã
ã¾ãåæã§ãããIsolationã¬ãã«ãSERIALIZABLE以å¤ã®ãã®ãããªãã¡READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READã¯ååã¨ãã¦ãcorrectã§ã¯ããã¾ããã
大äºãªã®ã§ããä¸åº¦ããã¾ãããSERIALIZABLE以å¤ã®Isolationã¬ãã«ã§ã¯ä¸è²«æ§ã¯âç¡æ¡ä»¶âã§ã¯æ ä¿ããã¾ããã大æµã®RDBMSã§ã¯Isolationã¬ãã«ã®ããã©ã«ãè¨å®ã¯ãREPEATABLE_READã«è¨å®ããã¦ããããããã£ã¦ããã®ã¾ã¾ä½¿ãã¨ãåºæ¬çã«ãã¼ã¿ä¸æ´åãèµ·ããå¯è½æ§ãããã¾ãã(ããã¯å¸¸èã§ã¯ããã¾ãããæå¤ã«å¿ãã¦ãã人ããã¾ãï¼
ãã¨ãã¨Isolationã¬ãã«ã®ãå®ç¾©ãã¯ãããã§ãããã¨ããå®ç¾©ã§ã¯ãªããããã¨ããä¸æ´åã¯æé¤ã§ããªããã¨ããå®ç¾©ã§ããããããããã¨ã«ããã¨ãã°REPEATABLE_READãããã¯ãè±èªã¨ãã¦ããä½åèªãã§ãåããã¨ãã風ã«èªããã®ã§èª¤è§£ãå¤ãã¨ãããããã¶ã誤解ãããªãã®ã§ãé常ã«ãããããªãã§ããæ¬æ¥ã¯phantomãæé¤ã§ããªãã¬ãã«ã®Isolationã¨ããå®ç¾©ã§ãã
ãªã®ã§ãREPEATABLE_READã«è¨å®ããå ´åã¯ãphantomãæé¤ã§ããããã«èªåã§ä½ããã®æå½ãããã¾ãããã¨ãããã¨ã«ãªãã¾ãããä½åèªãã§ãåããã¨ãããã¨ã§ã¯ãªãã§ãã
Isolationã¬ãã«ã®è¨å®ã¯ãæ¼ãã¦ãã¾ãanomalyãæ確ã«æèãã¦æå½ãããã¨ã主ããç®çã§ãããããã¾ãcorrectã¨ã¢ããªã±ã¼ã·ã§ã³ãµã¤ãã§ã©ãæ ä¿ãããï¼ãconsistencyãã©ãæ ä¿ãããï¼ã¨ããåé¡ãã®ãã®ã§ãã
çæ³è«ããè¨ãã¨ãconsistencyã®ç¢ºä¿ã¯ããã«å´ã§è¡ãã®ãåºæ¬ã§ããä¸è²«æ§ã®ç¢ºä¿ã¯å¯è½ãªéãã¢ããªã±ã¼ã·ã§ã³ãµã¤ãã«ã¯æèããããééçã«å¦çã§ããåºç¤ãæä¾ããã¨ãããã¨ãæ¬çã§ããIsolationã¬ãã«ã¯ãæ¬æ¥ã¯ããã¾ã§consistencyãæ ä¿ãããã¬ãã«ã«è¨å®ããæ¹ãæã¾ããããã§ããã¡ããã¨å®è£ ããã¦ããDBã§ããã°ãæ®éã«serializableã«è¨å®ãã¦ãããããå¦çãå ¨é¨æ¾ãè¾¼ãã°ããã£ã¡ãserializableã«ãã¦ããã®ã§åé¡ãªãï¼ã¨ãã風ã«ãªãã¯ãã§ãã
ããDBãµã¤ãã®å®è£ ãå²ã¨ã¢ã¬ãªã±ã¼ã¹ã ã¨ãæ®å¿µãªããr/wãåããããªå ´åã§ã¯ãããã©ã¼ãã³ã¹ããããããªãã¨ãããã¨ã«ãªãã¾ããï¼æ®éã¯ããã¯å®è£ ãã¢ã¬ãªããã ã¨æããã¾ããï¼ãã£ã¦serializableã¯å©ç¨ããªãã¨ããã®ãç¾å®ã§ãããããªããªãçæ³çãªTXå¦çå®è£ ã¯å°é£ã§ããã¨ããã®ã¯ãå®æã¨ãã¦ããããã¨æãã¾ãã
7 ã¾ã¨ã
以ä¸ã¯åãã¼ãã§ã®consistency(correctness)ã®è©±ã§ããä¸è¬ã«åæ£å¦çã§ã¯ãããã«å ãã¦ããã¼ã¿ã®ã¬ããªã±ã¼ã·ã§ã³ã®è©±ãå
¥ãã®ã§ãããè¤éã«ãªãã¾ãããã ããåæ£å¦çã«ããã¦ããconflictã®èãæ¹ãã³ã³ã»ããã¯æ¥µãã¦æå¹ãªæ¦å¨ã§ã¯ããã®ã§ãã¾ãã¯åãã¼ãã§ã®ã³ã³ã»ãããã¡ããã¨ç解ãã¦ããå¿
è¦ãããã¾ããï¼ããããªãã¨ããã¨ãã°ãserializabilityã¨linearizabilityãæ··ä¹±ãããããªãã¨ã«ãªã£ã¦ãã¾ãã¾ãï¼
ãã®ãããã¯èªåã§ãããä¸åº¦ååå¼·ãã¦ãã¡ããã¨ã¾ã¨ãããã¨æã£ã¦ãã¾ããåç´ã«ã¿ãã³ãã¦ã æ¬èªãã§ãã¨ãããã¨ã§ã¯ãªããããã¾ã§ã¾ãã¯ã¡ããã¨åºæ¬ã®TXãç解ããä¸ã§ãªãã¨ããã®å¿ç¨ã«å ãã¦ãç¬èªã®èãæ¹ãå å³ããã¦ããåæ£TXã¯ãã¨ã¦ããã¡ããã¨ãç解ã§ãããã®ã¯ããã¾ããã
8.ã©ãèãã¦ããã®ãï¼
ã¾ããã£ã¦ãä¸è²«æ§ããTXããã®å
·ä½çãªå®è£
ãè°è«ã®åã«ããä½ãåé¡ãªã®ãï¼ãããã¦ãã®è§£æ±ºã®ããã«ä½ãæ¤è¨ããã¦ãã¦ãã©ããªçè«çãªéå
·ç«ã¦ãæºåããã¦ãã¦ããã®ãï¼ãã¨ãããã¨ãç解ãã¦ãããã¨ãèè¦ã§ãããã
åè¿°ã®TXã®è©±ã«ãã¦ãç´°ãã話é¡ã«è§¦ãã¦ããã°ãlockã»MVCCã»reducibilityã»é層å¦çã®è©±ãå¿ è¦ã«ãªãã¾ããã¾ããå½ç¶ãç°å¸¸ç³»ã®abortã»recoveryã»logå¦çãèæ ®ãã¦ããå¿ è¦ãããã¾ããããããã¾ãcorrectnessãã©ãæ ä¿ãããï¼ã¨ããåé¡ãã®ãã®ã«é¢é£ãã¦ãã¾ãã
ä¸è¨ã®ãããªçè«çãªèæ¯ãèããã°ããNoSQLã¯ä¸è²«æ§ããªãã¦ãRDBMSã¯ä¸è²«æ§ããããã¨ããåç´ãªè¨ãæ¹ã¯ãè¦æ¹ã«ãã£ã¦ã¯ãé常ã«ãã¤ã¼ããªè¨ãããã«ãªããã¨ããã¯ããããããã¨æãã¾ãã
æåã®æ»ãã¾ãããTXã¯é常ã«æ´çãããæ°å¦çãªèæ¯ããã¤æè¡ã§ããããããè¸ã¾ãã¦ãä¸ã§ããã®èãæ¹ãæ骨奪èããåæ£å¦çãªãã次ä¸ä»£ã®TXå¶å¾¡æè¡ãªããä½ãä¸ãã¦ãããã¨ãä»å¾å¿ è¦ã¨ããããã¯ããã¸ã¼ã§ã¯ãªããã¨æãã¾ããé ããã¦æ»ã«ãããªæãã§ããã»ã»ã»
ã¾ããããªæãã