05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 7<br />

■ ■ ■<br />

Concurrency <strong>and</strong><br />

Multi-Versioning<br />

As stated in the last chapter, one of the key challenges in developing multiuser, databasedriven<br />

applications is to maximize concurrent access but, at the same time, ensure that each<br />

user is able to read <strong>and</strong> modify the data in a consistent fashion. In this chapter, we’re going<br />

to take a detailed look at how <strong>Oracle</strong> achieves multi-version read consistency, <strong>and</strong> what that<br />

means to you, the developer. I will also introduce a new term, write consistency, <strong>and</strong> use it to<br />

describe how <strong>Oracle</strong> works not only in a read environment with read consistency, but also in<br />

a mixed read <strong>and</strong> write environment.<br />

What Are Concurrency Controls?<br />

Concurrency controls are the collection of functions that the database provides to allow many<br />

people to access <strong>and</strong> modify data simultaneously. As noted in the previous chapter, the lock is<br />

one of the core mechanisms by which <strong>Oracle</strong> regulates concurrent access to shared database<br />

resources <strong>and</strong> prevents “interference” between concurrent database transactions. To briefly<br />

summarize, <strong>Oracle</strong> uses a variety of locks, including the following:<br />

• TX locks: These locks are acquired for the duration of a data-modifying transaction.<br />

• TM <strong>and</strong> DDL locks: These locks ensure that the structure of an object is not altered<br />

while you are modifying its contents (TM lock) or the object itself (DDL lock).<br />

• Latches: These are internal locks that <strong>Oracle</strong> employs to mediate access to its shared<br />

data structures.<br />

In each case, there is minimal overhead associated with lock acquisition. TX transaction<br />

locks are extremely scalable in terms of both performance <strong>and</strong> cardinality. TM <strong>and</strong> DDL locks<br />

are applied in the least restrictive mode whenever possible. Latches <strong>and</strong> enqueues are both<br />

very lightweight <strong>and</strong> fast (enqueues are the slightly heavier of the two, though they’re more<br />

feature-rich). Problems only arise from poorly designed applications that hold locks for longer<br />

than necessary <strong>and</strong> cause blocking in the database. If you design your code well, <strong>Oracle</strong>’s locking<br />

mechanisms will allow for scaleable, highly concurrent applications.<br />

But <strong>Oracle</strong>’s support for concurrency goes beyond efficient locking. It implements a<br />

multi-versioning architecture (introduced in Chapter 1) that provides controlled, yet highly<br />

concurrent access to data. Multi-versioning describes <strong>Oracle</strong>’s ability to simultaneously<br />

231

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!