本文為TimesTen數(shù)據(jù)庫復(fù)制系列的第1篇。
復(fù)制就是在多個數(shù)據(jù)庫中存在多份數(shù)據(jù)拷貝,對性能影響最小的同時保證數(shù)據(jù)高可用,除數(shù)據(jù)恢復(fù)外,還可以均衡工作負(fù)載,以最大化性能和實現(xiàn)轉(zhuǎn)動升級和保護
TT復(fù)制的實現(xiàn)是在master和subscriber數(shù)據(jù)庫都有復(fù)制代理,1個負(fù)責(zé)讀,1個負(fù)責(zé)加載,數(shù)據(jù)在rep agent間傳遞
TT推薦的方法是ASP(active standby pair),TT支持復(fù)制整庫,部份表,cache group, sequence等。ASP是唯1支持復(fù)制cache group的方案
TT也支持復(fù)制DDL
必須同平臺,同字節(jié)順序。
雖然可以復(fù)制同1主機上兩個庫,但最好建議是不同主機上的兩個庫
復(fù)制的庫必須具有相同字符集(DatabaseCharacterSet)和數(shù)據(jù)類型模式(TypeMode,缺省為Oracle)
通過主機名和文件系統(tǒng)路徑名可以唯1肯定1個庫,rep agent之間通過TCP/IP socket通訊
The replication agent on the master database reads the records from the transaction log and forwards any detected changes to replicated elements to the replication agent on the subscriber database. The replication agent on the subscriber database then applies the updates to its database. If the subscriber agent is not running when the updates are forwarded by the master, the master retains the updates in the transaction log until they can be transmitted.
支持3種模式,按性能影響和數(shù)據(jù)1致性由小到大為:
1. NO RETURN (缺省,異步模式)
2. RETURN RECEIPT (對方接到即返回)
3. RETURN TWOSAFE (對方接到,并提交后返回)
缺省模式提供最好性能,但存在數(shù)據(jù)丟失的風(fēng)險。利用更新主庫后,無需等待更新傳遞和加載到定閱庫。主庫和定閱庫之間有內(nèi)部機制肯定更新被成功傳遞和加載,和利用完全獨立。
幾點說明:
* 利用在交易提交,然后寫入log buffer后才可以返回,也就是完成步驟2后。
* replication agent負(fù)責(zé)將log buffer的數(shù)據(jù)flush到磁盤和傳遞到subscriber
* 在subscriber返回接受成功后,replication agent就能夠刪除沒必要要的日志了
* 更新的傳遞采取批量模式,以提高效力。
利用阻塞,直到對方接遭到更新后便可返回
幾點說明:
* 對方接收到是指在內(nèi)存中接遭到便可,而后續(xù)寫入log buffer和持久化不計在內(nèi)
* 如果10秒內(nèi)未返回receipt,利用可繼續(xù),此超時時間可配置。
* 超時的緣由多是網(wǎng)絡(luò),復(fù)制代理失效等
利用阻塞,直到交易在對方提交后方可繼續(xù)。
幾點說明:
* 交易先在備點提交再在主點提交
* 主點的復(fù)制代理在傳遞變化到備點前,其實不需要將log buffer中的內(nèi)容flush到磁盤。這點是和異步和return receipt是不同的。這也是為什么return twosafe的性能實際上是比return receipt要快的緣由。
> Transmission of return twosafe transactions is nondurable, so the master replication agent does not flush the log records to disk before sending them to the subscriber, as it does by default when replication is configured for asynchronous or return receipt replication.
* 超時可配置,缺省為10秒。超時后可以設(shè)置為重新提交或無條件提交(不顧備點未接遭到數(shù)據(jù))
這里的replication scheme稱為replication pattern更好理解。
Active Standby Pair(以下簡稱ASP)是TimesTen最經(jīng)常使用的的復(fù)制模式。
ASP中包括3個成員,分別是兩個master和1組只讀的subscriber(最多127個)。
其中active和standby都是master,只不過active為可讀寫,standby為只讀。
幾點說明:
* 既然ASP是Pair,說明active和standby是成對出現(xiàn)的,1個active對應(yīng)多個standby是不支持的。
* 如果standby失效,active可以直接向subscriber復(fù)制;如果standby恢復(fù),會先和active同步,然后重新承當(dāng)起向subscriber復(fù)制的責(zé)任。
在Classic復(fù)制中,master和subscriber都是可讀寫的(待后續(xù)實驗確認(rèn))
以下為整庫復(fù)制:
以下為選擇性復(fù)制,可以復(fù)制同1個對象到多個目標(biāo),也可分別復(fù)制不同的對象到目標(biāo),以下圖:
單向復(fù)制是1個master對應(yīng)多個subscriber,而雙向復(fù)制是指1個數(shù)據(jù)庫既是master也是subscriber。
雙向復(fù)制也有兩種用法,1個是用于負(fù)載分擔(dān),即兩個庫散布承當(dāng)不同的服務(wù),以下圖:
另外一種是復(fù)制均衡,即兩個庫承當(dāng)相同的服務(wù),以下圖:
這類模式斟酌的更多的是網(wǎng)絡(luò)帶寬的影響和復(fù)制負(fù)載的分擔(dān)。
下圖為直接復(fù)制:
下圖為中轉(zhuǎn)復(fù)制,propagator和subscribers在1個網(wǎng)絡(luò)內(nèi):
下圖為復(fù)制負(fù)載分擔(dān)的中轉(zhuǎn)復(fù)制:
緩存組的復(fù)制只支持Active Standby Pair1種復(fù)制模式。支持復(fù)制的緩存組包括AWT和只讀緩存組。
上圖我們先關(guān)注左側(cè)active和standby兩個庫,更新是通過standby傳遞到Oracle數(shù)據(jù)庫的。目的是為了減輕active master的負(fù)擔(dān)。
如果master失效,standby會承當(dāng)業(yè)務(wù)讀寫,并仍保持與Oracle數(shù)據(jù)庫的同步。
如果standby失效,或standby還未建立,這時候active可以同時承當(dāng)接受業(yè)務(wù)讀寫和與Oracle同步數(shù)據(jù)的職責(zé)。
standby變成新的active時, TimesTen會重寫配置緩存組,使得新的standby承當(dāng)起與Oracle同步的任務(wù)。
再來看看右側(cè)從standby到只讀subscriber的復(fù)制,在只讀subscriber上的復(fù)制目標(biāo)不是cache group中的表,而只是普通的non-cache表。
如果說上1種方式是針對HA,由于active和master是同享Oracle數(shù)據(jù)庫的。那末此處的方式則面向D/R,由于主點和備點分別有不同的Oracle數(shù)據(jù)庫。
在這類復(fù)制模式中,active 數(shù)據(jù)庫自動同步來做Oracle的數(shù)據(jù)。其實standby也配置了autorefresh,只不過處于pause狀態(tài)。
如果master失效,standby會接收,同時autorefresh狀態(tài)改成ON。
由于TimesTen不但會跟蹤active與Oracle的同步狀態(tài),同時也會跟蹤active和standby的同步狀態(tài),因此,當(dāng)standby接收失效的master時,其實不需要從頭開始與Oracle同步。
不過對只讀緩存組的復(fù)制,如果master失效后,再配置新的master應(yīng)當(dāng)不是很容易。
TimesTen支持Sequence的復(fù)制,通常Sequence用來作為主鍵,唯1肯定1行。在這類場景中,Sequence比TimeStamp更經(jīng)常使用。
You may choose to replicate all or a subset of tables that have foreign key relationships with one another. However, the method for how to replicate the tables involved in the relationship differ according to the type of replication scheme.
如果復(fù)制表定義了Aging策略,不管是基于時間戳還是LRU,那末:
* 源和目標(biāo)的Aging策略必須1致
* 對ASP,只有主點應(yīng)用Aging策略,引發(fā)的數(shù)據(jù)刪除通過復(fù)制傳播到目標(biāo)
* 如果不是ASP,則主點和備點分別應(yīng)用自己的Aging策略
* 如果是AWT緩存組,Aging引發(fā)的數(shù)據(jù)刪除其實不傳遞到Oracle,這點其實與復(fù)制沒關(guān)系,對Aging來講,這是公道的行動。