ablog

不器用で落着きのない技術者のメモ

Oracle8i Internal Services for Waits, Latches, Locks, and Memory が届いた

Debug Hacks Night に行ったときに id:wmo6hash さんに教えていただいてアマゾンに注文していた
Oracle 8i Internal Services: for Waits, Latches, Locks, and Memory
が昨日届いた。注文してから1ヶ月くらい経っていたので忘れかけていた。えらい時間がかかったなと思ったら発送元がロスになっていた。


とりえずパラパラっとめくってみて、興味のあるところを少し読んでみたら、以前から疑問に思っていたことについて書かれていた。
Primary Key に同じ値を insert すると、トランザクション・ロック(TX)の競合が発生する - ablog
Oracle のトランザクションロック待ち - ablog
に書いているけど、「Primary Key に同一の値を別セッションから insert しようとすると発生する TYPE=TX, REQUEST=4 のロック待ちはなんだろう?」という疑問。

P.37

When a transaction modifies a row, its transaction identifier is recorded in an entry in the interested transaction list (ITL) in the header of the data block itself, and row header is modified to point to that ITL entry.
...
When another transaction wants to modify the same row, and see that an uncommited transaction has modified that row, that transaction waits, not on a row-level lock, but on the transaction lock for the blocking transaction.

ふむふむ。別セッションから同じ行を変更しようとすると、トランザクションロック待ちで待機すると。トランザクションロックは変更しようとしている行が入っているデータブロックのITLに対するロック。

P.48

The blocked transaction waits in shared mode on the TX enqueue for one of the transactions, chosen psedo-randomly.

トランザクションロックは TX 4(shared mode on the TX enqueue) で待つということか。


ここから妄想モード炸裂。フィクションの可能性大。
ITLは配列のようなもので、その中に複数のエントリがある。各トランザクションはITLという配列を共有しているが、その中の各エントリは対応するトランザクションが排他的に所有している。ITLをテーブル、エントリを行にたとえるとわかりやすい。行を変更するとき、行には排他ロックをかけ、表には共有ロックをかける。だから、この TX 4 はITLという表みたいなものに対する共有ロックを表している。エントリという行レベルのロックについてはv$lockなどには表示されない。
ということではないかと勝手に妄想してみた。