å ¨ITé¢ä¿è ãç¥ã£ã¦ããã¹ãã1-copy-snapshot isolationã
snapshot isolationãåæ£ç°å¢ã«é©ç¨ããå ´åã®ãåºæ¬ãã®å 容ã®ã¾ã¨ãã«ãªãã¾ããï¼åºæ¬èªåç¨ã®ã¡ã¢ãªã®ã§ãééã£ã¦ããããã¿ã¾ããï¼
ã¾ãã¯ã¼ãã£ã³ã°ã®æ´ç
ã»snapshot isolation
ãTXã®åé¢ã¬ãã«ã¨ãã¦ã®snapshot isolationï¼ä»¥ä¸SIï¼ã¯ãç¾å¨ã®RDBMSã®TX管çã§ã¯ãã»ã¼å®è£
çã«ã¯ããã¡ã¯ãã¨è¦ã¦ããã¨æãã¾ãããã ãANSIã®è¦å®ã®ISOLATION_LEVELã«ã¯å®ç¾©ããªãã®ã§ãã©ã®ãããã«ä½ç½®ã¥ããã®ãã¯ãDBå®è£
ã®ããããã®åãæ±ãã«ããç°ãªãã¾ããã¨ã¯ãããã©ã®DBã§ãã»ã¼SERIALIZABLEã«è¿ãä½ç½®ã¥ãã«ãã¦ããã¨ãããå¤ãã§ãããã¨ããããSIï¼ç¹ã«Serializable SIï¼ãããã§ãªãã¨serializableã«ç¾å®çã«ã¯è¿ã¥ããªãã¨ããã®ãå®æ
ãã¨æãã¾ããï¼å¿è«çè«ä¸ã¯S2PLã§å®è£
ã¯å¯è½ã§ãããã¾ãããã©ã¼ãã³ã¹ãã¢ã¬ãããã®ã§ï¼
ãã®ä¸ã§ã»ã»ã»
ã»snapshot isolationã¨åæ£ç°å¢ã®è¦ªåæ§
ãã¡ãã£ã¨èããã°ããã«ãããã¾ããããã¡ããã¡ãé«ãããã§ããåºæ¬çã«snapshotã®å®è¡å
ï¼å¥ãã¼ãï¼å¥ããã»ã¹ï¼ã¨è¦ãã°ããããã§ããread-onlyãªTXã§ããã°ããã®ã¾ã¾å¥ããã»ã¹ã§å®è¡ãããã¨ã§ãåãã¼ãã§ãããã¨ãåæ£ãã¼ãã§ãããã¨ãã»ã¼ééçãªæ±ãã«ãããã¨ãå¯è½ã§ããè¦ããã«ãsnapshotãã¨ããã¨ã¨replicationã®å®è¡ãããã¨ããã¾ãåºæ¬çã«åãï¼å³å¯ã«ã¯å
¨ç¶éãã¾ããï¼ã¨è¦ãªããã¨ã§ããªãã¨ãªãåããããªãã¨ãã§ãããã ãã¨ããåãã¯ããããã§ãããã§ãã¾ãå®éããã®åæ£ç°å¢ä¸ã§ã®snapshot-isolationã¯ãå²ã¨å¿ç¨ç¯å²ãåºãæãã§åãæ¢ãããã¦ããã®ã§ãä¸å¿ãã»ã¼ä»å¾ã®åæ£ãã©ã³ã¶ã¯ã·ã§ã³ã®ããã¡ã¯ãã¨ãã¦è¦ã¦ããã§ããããåºæ¬ã¨ãã¦æ¼ããã¦ããã¹ãã§ããã»ã»å½ç¶ãæ´æ°ãåé¡ã«ãªãããã§ããã
ããã§ã1-copy-snapshot isolationã«å ¥ãåã«ã§ããã»ã»ã»
ã»1-copy-hogehoge
ãä¸è¬ã«1-copy-hogehogeã¨ããå ´åã¯ããåãã¼ãã§å®ç¾ã§ãã¦ããhogeghogeãåæ£ç°å¢ã§ãééçã«éæã§ããããã¨ãæå³ãã¾ãããã¨ãã° 1-copy-serializableã¨ãããã¨ã§ããã°ãåãã¼ãã§ã®å¦çãserializableãªå®è¡ãããã®ã¾ã¾âåãããã«âåæ£ç°å¢ã§å®è¡ã§ãããã¨ãããã¨ãæå³ãã¾ããããã§ããããã®ããåãã¼ãç°å¢ã§ã®ACIDç¹æ§ããã®ã¾ã¾åæ£ç°å¢ã§ãå®è¡ã§ãã¾ããã¨ããæ¦å¿µã§ã1-copy-atomicityã¨ã1-copy-isolationã¨ããè¨ãæ¹ããã¾ãã1-copy-durabilityã¨ããã®ãããã¾ãããä¾ãã°ã1-copy-okachimachiã¨ããã¨åãã¼ãã®okachimachiå±æ§ãåæ£ç°å¢ã§ãééçã«å®ç¾ã§ãã¦ããã¨ããæãã§ãã
ããã£ã¦ããã§ãã 1-copy-snapshot isolationã¨ãããã¨ã§ããã°ãããã¯åãã¼ãã§å®è¡ã§ãã¦ããsnapshot isolationãåæ£ãã¼ãã§ãå®è¡ã§ããã¨ãããã¨ãæå³ãã¾ãããããããåããã£ã¦ã®ã¯ã©ããããã¨ãã£ã¦ããè°è«ã¯ããã®ã§ãããã¾ã端(client)ããè¦ã¦ãã¦åãã«è¦ããã¨ããæå³ã§ããã§ã¯éãã¾ããããå°ãTxã®ä¸çã§ã¯ããåããã£ã¦ãããã¨ã¯ãããå³å¯ã«ããã¨Txãæ§æããä¸é£ã®æç¶ãã®æå³è«ãåããã種ã®ç³»ã«å±ãããã¨ããäºã«ãªãã¾ãã
ã»1-copy-snapshot isolation詳説
ãã¨ããããã§ãå人çã«ãã»ã¼ä¸çã®å¸¸èã¨ãã¦ãå
¨äººé¡ãç¥ã£ã¦ããã¹ã1-copy-snapshot isolationããé ã追ã£ã¦è§£èª¬ãã¦ããã¾ããã¨ããããå²ã¨ç°¡åãªãã§ããã©ãtransactionç³»ã®ã話ã¯ãå¿ããæã¯å¿ããã®ã§ãã¡ã¢ã£ã¦ããã¾ããï¼ä»¥ä¸ã¯ããç¨åº¦replicationã®å¸¸èãããã£ã¦ããåæãããã¾ãããé¢åãªäººã¯ä¸ã®æ¹ã®ããªã¨ã¼ã·ã§ã³ãèªãã°ãããã¨æãã¾ããï¼
1) eagerãlazyã
ãåºæ¬eagerã§ããã¨ãããlazyã¯ããããæ¬æ¥çã«ä¸è²«æ§ãåãã«ããã§ããlazyã ã¨updateã®conflictãcommitå¾ã«æ¤åºãããã®ã§ãããããserializableã¨ãããããè°è«ã«ã¯ãªãé£ãã§ããä¸åcommitãããã¤ãã²ã£ããè¿ãã¨ãã¢ã¬éãã¾ããããã
ãpropagationã¯ãåºæ¬çã«é対称(è¦ããã«SQLã³ãã¼ä¸¸æããããªãã¦ãå·®åbinaryçãªã¢ã¬)ã§write-setãåå¾ãã¦ãåå¾åreplicaã¸è»¢éãã¾ããcommitã®ã¿ã¤ãã³ã°ã¯é常ãwrite-setãåå¾ãã段éã§è¡ããã¾ããã»ã»ã»ããã¦ããã話é¡ã«ãªãã¾ãã
2) primary-backupã¨update-anywhere
両è
ããã¾ããç¾è¡ã®éç¨ã¬ãã«ã§ã¿ãã°ã妥å½ãªãã®ã¯primaryã ã¨æãã¾ãããä»å¾ã®ãã«ãDCã¨ãgeo-replicationã¨ãèããã¨ãããç¨åº¦update-anywhereãæ³å®ããæ¹ãããã¨æããã¾ããã¨ã¯ããåºæ¬çã«ROWAããã¼ã¹ã«æ·ãã¦ãã¾ããã¾ãfull-replicationãåºæ¬ã§ãããé¨åreplicationã«ããã¨ãå¾è¿°ã®validationã®ã¿ã¤ãã³ã°ã§çµè«ãä¸è´ããªãã¨ããå¯è½æ§ãåºã¦ãã¾ããï¼ãªã®ã§ããã®ã¨ãã©ãããããã¨ãããã¨ã§å¯¾å¿çãå¥ã«ããã¾ããï¼
ãå°ãfull-replicationã¯ãwrite-intensiveã«ãªãã¨ã¹ã±ã¼ã«ã¢ã¦ãããã¥ããã®ã§ãã¢ãã«ã¨ãã¦ã®ROWAã¯ããããããåªç§ã ã¨ã¯æãã¾ãããç¾å®è·¯ç·ãè¦ãã¨ãã«é¨åreplicationãèããå¿ è¦ãããã¨æã£ã¦ãã¾ãããã ããããã¯ãã¼ã¿ã®ãã¼ãã£ã·ã§ãã³ã°ããã¼ã¹ã«ãªãã¯ããªã®ã§ããããæ¥åçãªãã¶ã¤ã³ã®åé¡ã«ãªãã¯ãã§ããï¼å¿ è¦ãªãã¼ã¿ã®ãã¹ã¦ã®ä¸ææ´æ°ã¨ããROWAã ã¨ã»ã¼ææªã®å¦çã«è¿ãã¯ãã§ããããããè³æ¥µæ®éã«ããããã§ãããï¼
3) centralizedã¨de-centralized
snapshot isolationã¯åºæ¬çã«optimistic concurrency controlã§ããå¾ã£ã¦commit validationãã©ãã§ãããï¼ã¨ãããã¨ãåé¡ã«ãªãã¾ããcentralizedã¯ä¸ã«æã§ãde-centralizedã¯è¤æ°ç®æã§è¡ãã¾ããå¯ç¨æ§ãèããã°ãã¶ãde-centralizedã ã¨æãã¾ãããã¨ã¯ãããå®è£
ãå質ãèããã¨centralizedãæ¤è¨ã®ç¯å²ã§ã¯ããã¨æãã¾ãããã ããããããã«ãDCã¨ãgeo-replicationã¨ããèããã¨de-centralizedãå¿
è¦ã«ãªãã¾ãã
ã¨ãããã¨ãè¸ã¾ããä¸ã§ã»ã»ã»åºæ¬ã¨ãªããã¿ã¼ã³ãé çªã«åæãã¦ããã¾ãã
â ãã¼ã¹ãããã³ã«ï¼
ã¾ãåæã¨ãã¦ãTxããã¼ã¹ããæç¹ã§read onlyãwriteãå«ãããå¤æãã¾ãã
read only Txï¼Txéå§æç¹ã«ã¢ãµã¤ã³ããããåreplicaãã¼ã«ã«ã®ææ°ã®versionãèªã¿ã¾ããreadãwriteã«ãããã¯ããã¾ããã
write ãå«ãTxï¼æ¸ãè¾¼ã¿ã¯ãã¹ã¦ä¸åº¦ãã¼ã«ã«ã«æ¸ãåºãã¾ãããã ãã³ããããããã¾ã§ã¯ãæ¸ãåºããTx以å¤ã¯è§¦ãããã¨ã¯ã§ãã¾ããã
commitï¼optimistic concurrency controlã§ããwriteæä½ãå«ãTxã«ã¤ãã¦ã¯commitæç¹ã§Txã®æå¦ãå¤æãã¾ããåºæ¬çã«Txéå§æç¹ã®timestamp(tx_begin)ã¨commitæç¹ã®ææ°ã®versionã®timestamp(current_version)ãæ¯è¼ãã¦ãå¾è
ãåè
ããããã¨ï¼timestamp(tx_begin)ï¼timestamp(current_version))ã®å ´åã¯abortãããããããfirst-commit-winã«ã¼ã«ãé©ç¨ãã¾ãã
validationã«æåããå ´åã¯ãæ¸ããã¾ãããã®å¤ãææ°versionã«ããåreplicaã«ã°ãã¾ãã¾ããå°ãä»çµã¿ã¨ãã¦ã¯ãå
¨é åºãåããã°ããã¨ããã¬ãã«ã®è¦æ±ã«ãªãã¾ããé çªãããããªãã¨ã¢ã¦ãã§ãã
â ããªã¨ã¼ã·ã§ã³:
ã¾ãå
±éã®ã±ã¼ã¹ã¢ãã«ï¼
Tx1 w1(x)c1
Tx2 r2(y)w2(x)c2âa2
Tx3 r3(y)r3(x)c3
Tx4 r4(x)r4(y)c4
history:w1(x)r2(y)r3(y)c1r4(x)w2(x)c2âa2r3(x)c3r4(y)c4
Tx1ããTx4ã¾ã§ãã¹ã¦concurrentã«ãªãã¾ããTx1ã¨Tx4ã¯ãªã¼ãã¼ã©ãããã¾ããã
Tx2ã§ã¯xãæ¸ãã«ããã¾ãããc1ãå
ã«ãªã£ã¦ããã®ã§ãfirst-commit-winã§è² ãã¦abortã«ãªãã¾ãã
Tx3/Tx4ã¯read onlyãªã®ã§ãreplicaã§å¦çããã¾ãã
1) Primary-backup & Central
ãã£ã¨ãåç´ã§ããããããããã以éã¯ãã®ããªã¨ã¼ã·ã§ã³ã«ãªãã¾ãã
Txã¯ãã¹ã¦central middlewareã§ä¸åãã³ããªã³ã°ãã¾ããread-only Txã¨å¤æã§ããã¨ãã¯ãæå®ãããã¼ã«ã«replicaã«å¦çãé£ã°ãã¾ããããã§ã¯Tx3âsecondary1 Tx4âsecondary2ã«ã¢ãµã¤ã³ãã¾ããwriteãå«ããread-only Tx以å¤ã®Txã«ã¤ãã¦ã¯ãwriteãprimaryã§å¦çãã¾ããcommitãªã¯ã¨ã¹ããæ¥ãã¿ã¤ãã³ã°ã§ãprimaryããwriteã®å
容ï¼write setï¼ãåå¾ãã¦ãvalidationãè¡ãã¾ããæåããå ´åã¯ã³ããããprimaryã«æ¸ãè¾¼ãã§ãwrite setãåreplicaã«é
å¸ãã¾ããåreplicaã¯ã³ãããé ã«é
å¸ãããwrite setãèªåã®ãã¼ã«ã«ã§updateãã¦ããã¾ããã»ã»ã»ä»¥ä¸å
·ä½çã«
ã»w1(x) Tx beginãprimaryã«æ¸ãã ãã
ã»r2(y) Tx beginãwriteãããTxãã¾ãã¯readãsecondary2ã¸é£ã°ãã¦ãy0ãåå¾ã
ã»r3(y) Tx beginãread-onlyã§ãå¦çã¯secondary1ã¸é£ã°ãã
ã»c1 Tx1 commitãæ¸ãè¾¼ã¾ããwrite set(以ä¸ws) ãåå¾ãxã®ææ°versionã¯x0ãªã®ã§ãvalidationã¯OKãæ°ããversionãçæ(x1)ããã®ç´å¾ã«ãwsãåsecondaryã«é
å¸ããåsecondaryã¯ãã®wsãæ´æ°ããversionãçæã
ã»r4(x) Tx beginãread-onlyã§ãå¦çã¯secondary2ã¸é£ã°ãããã ããæ¢ã«ææ°versionã¯æ´æ°ããã¦ããã®ã§ãèªãå¤ã¯x1ã«ãªãã
ã»w2(x)ãprimaryã«æ¸ãã ãã
ã»c2âa2ãTx2 commitãæ¸ãè¾¼ã¾ããwrite setãåå¾ãxã®ææ°versionã¯x1ãªã®ã§ããã§ã«æ´æ°æ¸ã¿ãTxéå§æç¹ã®versionã¯x0ãªã®ã§ãvalidationã¯NGããã£ã¦abort
ã»r3(x)ãsecondary1ã§readããã ããTx3ã®beginãc1ãããåãªã®ã§ãåå¾ããxã¯x0
ã»c3 Tx3 commitã
ã»r4(y) secondary2ã§readãy0ãåå¾ã
ã»c4 Tx4 commitã
2) Update-anywhere & Central
ãUpdate-anywhereã§ã¯primaryãåå¨ããããã¹ã¦replicaã«ãªãã¾ããå¾ã£ã¦ãwriteã¯ä¸ç¾©çã«ãåreplicaã«æ¸ãè¾¼ã¾ããä»ã®replicaã«ä¼æãã¾ãããã ãvalidationã®å¶å¾¡ã¯central middlewareã§è¡ãã¾ãã
Txã®validationï¼
ãTxã®æåæ¡ä»¶ã¯ãããã®Txãéå§ããæç¹ã§ã®ãã¼ã¿ã»ããã«ã¤ãã¦ã®ãæ¸ãè¾¼ã¿ã«ã¤ãã¦ã³ããã競åãçºçãã¦ããªãããã§ãã
ãç¹°ãè¿ãã«ãªãã¾ãããæ¸ãè¾¼ã¿ã競åããTxéå§æç¹ã®timestamp(tx_begin)ã¨commitæç¹ã®ææ°ã®versionã®timestamp(current_version)ãæ¯è¼ãã¦ãtimestamp(tx_begin)ï¼timestamp(current_version)ã®å ´åã¯abortãããã以å¤ã¯commitãããã¨ãããã¨ã«ãªãã¾ãããã§ãããã«ãéè¦ãªã®ã¯é åºã§ãããæéãã®ãã®ã§ã¯ãªããã¨ãããã¨ã§ãã
ãä»çµã¿ã¨ãã¦ã¯ãããããã®ã³ãããã®ã«ã¦ã³ã¿ã¼ãå©ç¨ãã¾ããã³ããããæåããã¿ã¤ãã³ã°ã§ãã«ã¦ã³ã¿ã¼ãã¤ã³ã¯ãªã¡ã³ããã¦ãtimestampã®æ¯è¼ã®ä»£ããã«å©ç¨ãã¾ãã
central middlewareãä¿æãããã®
ã»æåããTxã®ã«ã¦ã³ã¿ã¼ã(lastValidated)
ã»åreplica R(j)ã§ã³ããããããæ´æ°Txã®æ° (lastCommitted[j])
ã»ç´åã«æåããTxã®Set (validatedSet)ï¼ã©ããã§GCããã¨ããåæï¼
Txãéå§ããæï¼
åTxã«startTsã¨ãã¦ãéå§æç¹ã®æ´æ°ããreplicaã®lastCommitted[j]ãã»ãããã
Commitãªã¯ã¨ã¹ãæï¼
ã»concurrentãªTxã§ãwsã競åããstartTsï¼commitTsã§ãããã®ãããå ´åã¯abortãããã以å¤ã¯commitãããï¼å¤å®ããTxã¯validatedSetãéããè¦ã¦ããï¼
ã»æåããå ´åãlastValidatedã®ã«ã¦ã³ã¿ã¼ãã¤ã³ã¯ãªã¡ã³ãããã
ã»ãã¼ã«ã«ã®lastCommitted[j]ãã¤ã³ã¯ãªã¡ã³ãã
ã»Txã®commitTsã¨ãã¦ãlastValidatedã®å¤ãã»ããããã
ã»å½è©²TxãvalidatedSetã«appendããã
ã»wsãreplicaã®æ´æ°queueã«ç©ãã
å¤ã®Propagationï¼
ã»åreplicaã«ç©ã¾ããqueueããé åºãä¿ã£ã¦ããã¼ã«ã«ã®å¤ãæ´æ°ããã
ã»lastCommitted[j]++
以ä¸å ·ä½çã«ã»ã»ã»å°Tx1/Tx3ã¯replica Aã§ãTx2/Tx4ã¯replica Bã§ããããåæ£å¦çããã¾ãããã©ã³ã¶ã¯ã·ã§ã³åä½ã§concurrentã«åæ£å¦çãè¡ãããã¤å ¨ä½ã§ä¸è²«æ§ãæ ä¿ããå½¢ã«ãªãã¾ããåæ£snapshot isolationã®æ¬é çºæ®ã«ãªãã¾ãã
initialization:
ã»lastValidated=0
ã»lastCommitted[A]=0
ã»lastCommitted[B]=0
ã»validatedSet=Ï
ã»w1(x) Tx beginãstartTs:=0 ãã®ä¸ã§ãreplica Aã«å¤ãæ¸ãã¾ãã
ã»r2(y) Tx beginãstartTs:=0 readãreplica Bã¸é£ã°ãã¦ãy0ãåå¾ã
ã»r3(y) Tx beginãstartTs:=0 read-onlyã§ãå¦çã¯replica Aã¸é£ã°ãã
ã»c1 Tx1 commitãæ¸ãè¾¼ã¾ããws1ãreplica Aããåå¾ãvalidatedSet ã«ä½ããªãã®ã§ãå¾ã£ã¦validationã¯OKããã£ã¦ãcommit versionãçæã
lastValidated=1
Tx1.commitTs:= lastValidated
validatedSet.append(Tx1)
ããããã該å½ããws1ãåreplicaã«é£ã°ãã¾ããã¾ãreplica Aã§ã¯ã³ãããå¦çããã§ããã®ä»ã®åreplicaã¯ãã®ws1ãæ´æ°ããversionãçæãå ãã¦ãlastCommitted[]++ãå¦çãï¼ããã§ã¯lastCommitted[A]=1 lastCommitted[B]=1)
ã»r4(x) Tx beginãstartTs:=1(lastCommitted[B]) read-onlyã§ãå¦çã¯replica Bã¸é£ã°ããæ¢ã«versionã¯æ´æ°ããã¦ããã®ã§ãèªãå¤ã¯x1ã«ãªãã
ã»w2(x)ãreplica Bã«æ¸ãã ãã
ã»c2âa2ãTx2 commitãæ¸ãè¾¼ã¾ããws2ãreplica Bããåå¾ãããã§validationããã
ws2âªws1 ã§ãã¤ãTx2.startTS=0 ï¼ validatedSet.Tx1.commitTs=1ãªã®ã§ãabort
ã»r3(x)ãreplica Aã§readããã ããTx3ã®beginãc1ãããåãªã®ã§ãåå¾ããxã¯x0
ã»c3 Tx3 commitã
ã»r4(y) replica Bã§readãy0ãåå¾ã
ã»c4 Tx4 commitã
3) Update-anywhere & De-Central
ã2)ã¨åæ§ã«ãprimaryãåå¨ããããã¹ã¦replicaã«ãªãã¾ããåããwriteã¯åreplicaã«æ¸ãè¾¼ã¾ããä»ã®replicaã«ä¼æãã¾ããããã«å ãã¦è«ççãªvalidationå¶å¾¡ã®middlewareãåæ£ããã¾ããé常ã¯ãreplicaã¨ãã¢ã«ãã¦ãå¶å¾¡ããã«ãã°ãæãå½¢ã«ãªãã®ã§ãmiddle+replicaã®å½¢ã§ãã¼ããã¬ã·ã¬ã·è¶³ãã¦ããå½¢ã®ã¯ã©ã¹ã¿ã¼ã«ãªãã¾ããæåéãã®åæ£ã¯ã©ã¹ã¿ã¼ã§ãã
ãmiddlewareéã®ä»çµã¿ã¯ãåºæ¬çã«2)ã¨åãã§ããé åºä¿è¨¼ãã§ãã¦ããã°ãvalidationãå¯è½ã«ãªãã¾ããã¤ã¾ãããé åºä¿è¨¼ãåæã«ã§ããã°ãåã種é¡ã®ãã¼ãã足ããã¨ã§ã¹ã±ã¼ã«ã¢ã¦ãå¯è½ãªåæ£ã¯ã©ã¹ã¿ã¼ä¸ã§ãä¸è²«æ§ãä¿è¨¼ããsnapshot isolationã®ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çãã§ãããã¨ããã¢ã¼ããã¯ãã£ã«ãªãã¾ããè¦ããã«ï¼æ¬å½ã«ãã¾ãè¡ãã°ï¼ç¡æµã§ãã
ãåæ£ã¯ã©ã¹ã¿ã¼ä¸ã§ã®ãã©ã³ã¶ã¯ã·ã§ã³å¦çã¨ãã¦ããã®ã¢ã¼ããã¯ãã£ãæåè¦ããã¦ãããã¨ã¯ããªãã¨ãªããããã¨æãã¾ããï¼ãã ããwrite setãåreplicaã§é£ã°ãã£ã±ãªãã«ãªãã®ã§ãé害çºçæã®å¾©æ§ã¯ããããªãã«èããªãã¨ããã¾ãããã¨ãããã¨ã§ããã話é¡ï¼
åºæ¬çãªä»çµã¿ã¯2)ã¨åãã§ãããåreplicaãmiddlewareæ©è½ãæã£ã¦ãã¾ãã
åmiddlewareãä¿æãããã®
ã»èªèº«ã®replicaã§ã³ããããããæ´æ°Txã®æ° (lastCommitted)
ã»ç´åã«æåããTxã®Set (validatedSet)ï¼ã©ããã§GCããã¨ããåæï¼
Txãéå§ããæï¼
åTxã«startTsã¨ãã¦ãéå§æç¹ã®æ´æ°ããreplicaã®lastCommittedãã»ãããã
Commitãªã¯ã¨ã¹ãæï¼
ã»wsãåå¾ãã¦ãvalidationã®ããã«ãã«ããã£ã¹ãããããã¼ã«ã«ãªå ´åã¯æå
ã§å¦çãã¾ãã
ã»åreplicaã§ãwsã競åããstartTsï¼commitTsã§ãããã®ãããå ´åã¯abortãããã以å¤ã¯commitãããï¼å¤å®ããTxã¯validatedSetãéããè¦ã¦ããï¼
ã»æåããå ´åãlastCommittedãã¤ã³ã¯ãªã¡ã³ãã
ã»replicaãæ´æ°
ã»Txã®commitTsã¨ãã¦ãlastCommittedã®å¤ãã»ããããã
ã»å½è©²TxãvalidatedSetã«appendããã
以ä¸å ·ä½çã«ã»ã»ã»å°Tx1/Tx3ã¯middleA-replica Aã§ãTx2/Tx4ã¯middelB-replica Bã§ããããåæ£å¦çããã¾ãã
initialization:åreplicaã®ã»ããã¢ãã
ã»replicaA.lastCommitted=0
ã»replicaA.validatedSet=Ï
ã»replicaB.lastCommitted=0
ã»replicaB.validatedSet=Ï
ã»replicaA w1(x) Tx beginãstartTs:=0 ãã®ä¸ã§å¤ãæ¸ãã¾ãã
ã»replicaB r2(y) Tx beginãstartTs:=0 y0ãåå¾ã
ã»replicaA r3(y) Tx beginãstartTs:=0 y0ãåå¾ã
ã»replicaA c1 Tx1 commitãæ¸ãè¾¼ã¾ããws1ãreplica Aããåå¾ãããã¼ããã£ã¹ãã
ãã¼ã«ã«ã§ã¯ãvalidatedSet ã«ä½ããªãã®ã§ãå¾ã£ã¦validationã¯OKããã£ã¦ãcommit version(replicaA.x1)ãçæã
replicaA.lastCommitted=1
Tx1.commitTs:= replicaA.lastCommitted
replicaA .validatedSet.append(Tx1)
ããã¼ããã£ã¹ãå
ï¼replicaB)ã§ããvalidatedSet ã«ä½ããªãã®ã§ãå¾ã£ã¦validationã¯OKããã£ã¦ãcommit version(replicaB.x1)ãçæã
replicaB.lastCommitted=1
Tx1.commitTs:= replicaB.lastCommitted
replicaB .validatedSet.append(Tx1)
ã»replicaB r4(x) Tx beginãstartTs:=1(replicaB.lastCommitted) readã§èªãå¤ã¯x1ã«ãªãã
ã»replicaB w2(x)ãreplica Bã«æ¸ãã ãã
ã»replicaB c2âa2ãTx2 commitãæ¸ãè¾¼ã¾ããws2ãreplica Bããåå¾ãããã¼ããã£ã¹ãã
ãã¼ã«ã«ã§ã¯ãws2âªws1 ã§ãã¤ãTx2.startTS=0 ï¼ replicaB.validatedSet.Tx1.commitTs=1ãªã®ã§ãabort
ããã¼ããã£ã¹ãå
ï¼replicaA)ã§ããws2âªws1 ã§ãã¤ãTx2.startTS=0 ï¼ replicaA.validatedSet.Tx1.commitTs=1ãªã®ã§ãabort
ã»replicaA r3(x)ãreadããã ããTx3ã®beginãc1ãããåãªã®ã§ãåå¾ããxã¯x0
ã»replicaA c3 Tx3 commitã
ã»replicaB r4(y) replica Bã§readãy0ãåå¾ã
ã»replicaB c4 Tx4 commitã
以ä¸ã«ãªãã¾ãã
ä¸å¿ããããããã人åãã«3è¡ã§èª¬æãã¾ãã
ã»ä¸å¿åæ£ç°å¢ã§ç¹ã«å¶å¾¡ã®é ã¨ãããªã
ã»readã¯å¥½ãåæã©ãã§ãèªãã§ãããwriteã好ãåæã©ãã«æ¸ãã¦ãè¯ãã
ã»writeã¯ã©ããã§åæã«èµ·ãã¦ããTxã§å
ã«ã³ãããããããè² ãããã£ãããã ãã§ãTxã®ä¸è²«æ§ãæ
ä¿ãããä»çµã¿ã§ãã
ãã¨ã¯è£è¶³çãªæãã§
ã»æ£å¸¸ç³»ã¯ç³ãåãªãããé害対çã¯ã¡ããã¨èããªãã¨ã¾ããã
ç¹ã«ã³ãããã®èé害æ§ããããå¿
è¦ãããã¾ããvalidationã®çµæã®åæãé害ã§ãããæã«ã¯ã¡ãã£ã¨ã¾ãããã¨ã«ãªãã¾ããä»ã¾ã§ã®æ¹éã§ã¯2PCãæåã§ãããããããPaxosãå©ç¨ããæ¹éãåºãæ¤è¨ããã¤ã¤ããã¾ãããã®ãããã®ã¢ã¬ã¤ã³ã¬ã¤ãWalterã ã£ãããMDCCã ã£ãããã¾ãããã®æã®ãã®ã¯ãå¿è«ãã©ãããã¤ã¼ããªSIã§ã¯ããã¾ãããããéæãã¹ãã¯ã©ã¤ããªã¢ã¨ãã¦ã¯ãæ確ã«1-copy-SIãè¨ããããã¨ãå¤ãã§ãã
ã»SSIã«æ¡å¼µã§ããã
ã¨ã¯ããããã®åºæ¬ã«ãªããããã³ã«ã¯write skewã¯æé¤ã§ãã¾ããããªã®ã§ãSSIãå°å
¥ãããã¨ã«ãªãã¾ããåºæ¬çã«r-wã®anti-dependencyã®ã°ã©ãæ§é ãæ½åºã§ããã°ããã®ã§ãåé¡ã¯ãåæ£ç°å¢ã§ãã®ã°ã©ããã©ãä½ããï¼ã¨ãããã¨ã«ãªãã¾ãããã¨ã§ã¾ããã¾ã¨ãã¾ãããä¸å¿ã§ãã¦ã¾ãããã£ã¨ãå½ç¶write-setã®æã¡åãã«anti-dependencyã®æ
å ±ãæããã¦ãä¸æã«é£ã°ãå½¢ã«ãªãã®ã§ãããread-setãä¸ç·ã«é
ãã¨å´©å£ããã®ã§ã工夫ãã¾ãããã£ã¨ãããã«å¤å®åºæºãã¡ãã£ã¨å·¥å¤«ããªãã¨ã¾ããã®ã§ãreplicated serializable snapshot isolation(RSSI)ã¨ããå½¢ã§ã¡ãã£ã¨æ¡å¼µãã¦ã¾ããã»ã»ã»ã¶ã£ã¡ããããã®æã®è«æã¯ãããã©ã«ãã§åæ£SIã¨SSIãããã£ã¦ããªãã¨ã¾ããã«ãã«ãããç¶æ
ã«ãªãã¾ãã
ã»æ¸ãè¾¼ã¿ã®ãã«ãããã«ã¯å¼±ããã¨ã¯ããããç¨åº¦ã®writeã®è² è·ã«ã¯å¼·ãã
èªãæ¹ã¯ã»ã¼ç¡æµã§ããããåæ£ã¯ã¨ãªã¼ã®å®è¡åºç¤ã¨ãã¦ã¯ç³ãåãªãã§ãããããã ãä¸è¬çã«ãã®æã®åæ£ãã©ã³ã¶ã¯ã·ã§ã³å¦çã¯ãç¹ã«æ¸ãè¾¼ã¿ãã«ãããã«ã¯ã極端ã«å¼±ãã¨ãã宿å½ãæã£ã¦ããã®ã§ãã¾ã¼å®åä¸ã¯ããã¦èããã¹ãã§ãããããã¨ã¯ããããã³ããã¼ã¯ã§ãwriteã«å¼·ãã®ã¯ããããç«è¨¼ããã¦ãã¾ãã®ã§ãæ®éã®è² è·ã®èªã¿æ¸ãç¨åº¦ã§ããã°ã»ã¼åé¡ãªãã§ãããã
ã»çµå±Transactionã¯è¦ãã®ãï¼
ããããNoSQLã®ä¸çã§TXã¨ãããã®ãï¼ã¨ããè°è«ã§ãããä»ã®ã¨ããè¦ãã¾ãããã¨ããçµè«ã®ããã§ããããã¨ãã°ããè¨ãããã®ã¯ãwallã¸ã®æ¸ãè¾¼ã¿ã®é åºæ§ã®ç¢ºä¿ã§ãããé åºãã°ãã°ãã«ãªãã¨ä¼è©±ãæç«ãã¾ããããã§ãããã¯ä¸ç¨®ã®constraintã«ãªãã®ã§ãTXå¶å¾¡ã®è©±ã«ãªãã¾ããï¼ä»ã¯ãªããææ¸ãå®è£
ã¨ããã¦ããã¨ãã話ãããããã§ãããï¼ã¾ããæç³å²ãå
çã®ããã«ãNo ACID is No Interestãã¨è¨ãåãã®ã¢ã¬ãããã¨ã¯æãã¾ãããä¼¼ããããªäººã¯å¤ããã¨ã
ã»å人çè¦è§£
ããããã«ãããåæ£ã§ãããã¨åãã¼ãã§ãããcorrectã®ã³ã³ã»ããã¯ç¶æãã¦ãããªãã¨ããããè°è«ã®åå°ã«ãã®ãã¾ãããç¹ã«constraintã«ã¤ãã¦ã¯è¿½å çã«ããããè°è«ã¯çºçããã¨å人çã«ã¯æã£ã¦ãã¾ããSSIã§ã«ã¿ãã¤ãããã¨ããè¦è§£ãããã¨ã¯æãã¾ãããæããã¦ãããªã®ãã¨ããæ°ããã¦ãã¾ãããããããSSIã«ãã¦ãå¶éçã«ãã¦ããã®ã§ãserializableå
¨ä½ã®éåãã«ãã¼ãã¦ããããã§ã¯ãªãã§ãããããæã
ã®ç¥ããªãæãéãã¾ã ãããã¨èããæ¹ã妥å½ã§ããããã»ã»ã»ãªããããæ°å¦çãªè©±ã«ã¯ãªãã¾ããããããããã®ãã¨ããããã«ãã¦ãåºæ¬ã¯å¤ãããªãã§ãããã
ãããã¯ãã¦ãããããæ®éã«ãã¤ããã©ã¼ãã³ã¹ãªåæ£Txãserializableã«è¿ãå½¢ã§å©ç¨ã§ããç¶æ³ã«ãªãã¤ã¤ããã¾ããåºæ¬ã«ãªã£ã¦ããå
¨é åºåé¡ã¯ãGoogleã®spannerãå°çã®éãéãã¦ãã¾ã£ãæãããããã¶ãæ濤ã®éçºç«¶äºã«ãªã£ã¦ããã¨æãã¾ããææ±æ´ã®å³¶å½ã®ç«ã¡å¾ãæã¯ãã±ãªãæãã§ãããçããé å¼µãã¾ãããã
ã