翻译 Oracle 8i interal Service (3.1 Latches and Locks)

Chapter 3. Latches

There are numerous data structures in Oracle's System Global Area (SGA) that need to be

accessed concurrently by many different database processes. It is essential that only one

process be able to modify any particular data structure at one time, and that the data

structure cannot be modified while it is being inspected. Oracle makes sure this does not

happen by protecting all SGA data structures with either locks or latches. (See Chapter 6,

for a description of the contents of the SGA and other memory areas.)

第三章 latches

许多不同的数据库进程需要访问 SGA ,在 ORACLE SGA 中有很多数据结构。在同一时刻,紧紧只让一个进程修改某个特定的数据结构是必要的,当数据结构被检查时,数据结构不能修改。 Oracle 使用 locks 或者 latches 来保护所有的 SGA 数据结构不发生这样事情。

3.1 Latches and Locks

Latches are the more restrictive mechanism, because they do not allow multiple

processes to inspect the protected data structure at the same time—they provide

for exclusive access only.[1] Locks allow for better concurrency, because they may

be held in a shared mode when the data structure is simply being inspected.

[1] This is a simplification. The redo copy latches can be shared, but this is hardware

dependent.

3.1 latchesLocks

Latches是受限的结构,因为他们不允许多个进程同时检查被保护的数据结构――他们只提供排它访问『1』。Locks考虑到更好协助,因为当数据结构被简单保护时,他们能在共享模式被得到。

[1] 这里简化了,redo copy latches能被共享,不过要依赖硬件。

Another significant difference between locks and latches is request queuing.

Requests for locks are queued if necessary and serviced in order, whereas latches

do not support request queuing. If a request to get a latch fails because the latch

is busy, the process just continues to retry until it succeeds. So latch requests are

not necessarily serviced in order.

它们之间另一个重要的区别时队列需求。如果LOCKS的需求是排序的那么服务也是排序的,然而LATCHES不支持需要队列,如果因为latches忙而得不到LATCH,那么进程就会一直试着得到它直到成功。所以对Lach的需求不是必须按序服务的.

Because a latch can only be held by one process at a time, and because there is no

inherent concept of queuing, the latch data structure itself is very simple—

essentially just a single location in memory representing the state of the latch.

And because the latch data structure is so simple, the functions to get and release

a latch have very little work to do. By contrast, the data structures for locks are

much more sophisticated because of their support for queuing and concurrency.

So the functions to get, convert, and release locks have correspondingly more

work to do.

因为一个latch在某一时刻只能被一个进程占用,并且没有队列概念,latch本身的数据结构是非常简单的――实质上仅仅是一个内存位置描述latch的。因为latch数据结构很简单,所以几乎不需要做什么工作就能得到和释放latch。相对来说,locks的数据结构就比较复杂,因为它们支持队列和concurrency。所以得到,convert和释放锁相应的会有比较多的工作要做。

Of course, it is necessary for Oracle to ensure that only one process at a time can

modify the latch and lock data structures themselves. For latches this is easy.

Because each latch is just a single location in memory, Oracle is able to use the

TEST AND SET, LOAD AND CLEAR, or COMPARE AND SWAP instructions of

the underlying hardware's instruction set for its latch get operations. Because

these are simple machine instructions that are guaranteed to be atomic, no other

locking mechanism is needed. This simplicity makes latch gets very efficient.

当然,在同一时刻只允许一个进程修改latchlock它们本身的数据结构是必须的。对latches来说这是简单的。因为每一个latch仅仅有一个内存位置,Oracle能用硬件下指令设置的(instruction set 指令设置, CPU 可以执行的命令TEST,SET,LOAD,CLEAR,COMPARESWAP来对latch进行操作。因为这是简单的保证原子的machine instructions,没有其他锁结构被需要,latch的操作是很高效率的。

Oracle's lock data structures, on the other hand, have several parts, and therefore

cannot be modified atomically. For this reason, Oracle actually protects operations

on locks with latches. The type of latch used varies depending on the type of lock.

For example, the cache buffer locks are indirectly protected by the cache buffers

chains latches, and the row cache enqueue locks are protected by the row cache

objects latch.

Oracle锁的数据结构,有几部分,所以不能被自动修改。由于这种原因,Oraclelatches保护在锁上的操作。这种latch多样化的使用依靠锁的类型。例如,the cache buffer locks间接的被the cache buffers chains latches保护。the row cache enqueue locksthe row cache objects latch保护。

Because latches are efficient, Oracle often uses a latch, rather than a lock and latch

combination, to protect data structures that are expected to be accessed only

briefly and intermittently.

因为 latches 是很有效的,所以比起锁和 latch combination Oracle 宁愿用一个 latch 来保护 间歇地,暂时的数据结构。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/51726/viewspace-65965/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/51726/viewspace-65965/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值