日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【COMP207 LEC10-12】

發(fā)布時間:2024/1/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【COMP207 LEC10-12】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

LEC 10-12

Conflict?

>> 當(dāng)兩條指令是不同事務(wù)相同數(shù)據(jù)項上的操作,并且其中至少有一個是write指令時,則稱這兩條指令是沖突的 (不用想其他的東西,單純滿足這三個條件就可以了)例:

?①Ii?= read(Q),?Ij?= read(Q);

?②Ii?= read(Q),?Ij?= write(Q);?

?③Ii?= write(Q),?Ij?= read(Q);?

?④Ii?= write(Q),?Ij?= write(Q);?

比如 這四個操作中?②、③、④就是li和lj沖突的?

Precedence Graph

>> 是一個有向圖(directed graph)G = (V,E),V是頂點集,E是邊集

當(dāng)滿足以下任意一個條件時,T1指向T2:

?①在T2執(zhí)行read(Q)之前,T1執(zhí)行write(Q)

?②在T2執(zhí)行write(Q)之前,T1執(zhí)行read(Q)

?③在T2執(zhí)行write(Q)之前,T1執(zhí)行write(Q)

(其實為了好記的話,除了“rr”,其他的只要后面字母一樣都可以當(dāng)作邊的條件)

Testing Conflict-Serializability? 判斷是否有沖突可串行性

>> 有如上圖的“圈”的話就不是conflict-serializability,沒有圈就是conflict-serializability,唯一判斷標(biāo)準(zhǔn)

Enforcing Conflict-Serializability Using Locks 使用locks強制...

>> Operations

(x) :??lock?

(x) : unlock

>> Rules

1. 每一個r(x)/ w(x)前面都要有一個li(x),并且li(x)和ui(x)不能挨著

2. li(x)在?lj(x)前面那么 ui(x) 就要在uj(x)前面

Two-Phase Locking (2PL)?:?

>> Simple modification of the simple locking mechanism that guarantees conflict-serializability

>> 2PL分為phase 1和phase 2, phase 1 是從第一個lock到第一個unlock之前,phase 2 是從第一個unlock到最后。如果phase 2 里還有l(wèi)ock,那么這就不是一個2PL

>> If S is a schedule containing only 2PL transactions, then S is conflict-serializable

>> ?2PL可能會引起一些問題,例如死鎖 ?:?deadlocks whick leads to wait forever

>>?How can we make 2PL more flexible? By using different lock modes

1. Share lock ? Operation : s-lock(X) ?Shorthand notation : sli(X)

>> 可能會造成死鎖 例如:

T1:

begin Transaction t1

select * from table with (holdlock) (holdlock的意思是加共享鎖,直到事務(wù)結(jié)束(提交或回滾)才會釋放)

update table set column1=‘hello’

T2:

begin Transaction t2

select * from table with (holdlock)

update table set column1=‘world’
假設(shè)T1和T2同時到達select語句,都為table加上了共享鎖(hold lock),那么當(dāng)T1、T2要執(zhí)行update時,根據(jù)鎖機制,共享鎖需要升級為排他鎖,但是排他鎖與共享鎖不能共存,要給table加排他鎖,必須等待table上的共享鎖全部釋放才可以,可是holdlock的共享鎖必須等待事務(wù)結(jié)束才能釋放,因此T1和T2都在等待對方釋放共享鎖,形成循環(huán)等待,造成死鎖
?

2. Exclusive lock ? ? ?Operation : x-lock(X) ?Shorthand notation : xli(X)

3. Update lock Operation : u-lock(X) uli(X)?

作用和s-lock()是類似的,但更新鎖與共享鎖兼容(shared lock和exclusive lock不兼容),所以更新鎖可以防止里那種一般情況的死鎖發(fā)生,update lock不必等共享鎖全部釋放成才能變成exclusive lock,可以直接變成

更新鎖會阻塞其他的更新鎖和排他鎖,因此更新鎖和更新鎖是不兼容的

New upgrading policy :

4. Intention lock :??If a transaction wants to lock an item X, it must first put an intention lock on the super-items of X ?(就是在在lock item X前,需要先有一個intention lock)

Intention shared : IS ?Intention to request a shared lock on a sub-item

Intention exclusive : IX ?Intention to request an exclusive lock on a sub-item

>>?Policy for Granting Locks

Why Might a Transaction Abort?

1. Errors while executing transactions

2. Deadlocks

3. Explicit request

Logging in DBMS

>> Undo log?

作用 :undo log是為了恢復(fù)“撤銷”這個行為之前的數(shù)據(jù)

>> Records :?

<START T>: Transaction T has started.

<COMMIT T>: Transaction T has committed.

<ABORT T>: Transaction T was aborted.

<T, X, v> : Transaction T has updated the value of database item X, and the old value of X was v. 和redo log不同,這里v是指的是在改變前的數(shù)據(jù)

>> 其實看懂這張圖就行了,write()是不寫入database的,而只寫入buffer,等待buffer把X寫入log后再用output()寫入disk(database)

>> Redo log

作用 : 為了恢復(fù)已經(jīng)提交的數(shù)據(jù)

<T, X, v>: “Transaction T has updated?the value of database item X & the new value of X is v.” 這里最新的X值是v,而不是以前的值是v。在<commit t>時,直接將v寫入disk就行

>> Combinations of undo and redo

>> Record :?

?<T, X, v, w>: “Transaction T has updated the value of database item X, and the?old/new?value of X is v/w.”

總結(jié)

以上是生活随笔為你收集整理的【COMP207 LEC10-12】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。