Concurrency Control:Weak Levels of Consistency

Weak Levels of Consistency

Serializability is a useful concept because it allows programmers to ignore issues related to concurrency when they code transactions. If every transaction has the property that it maintains database consistency if executed alone, then serializability ensures that concurrent executions maintain consistency. However, the protocols required to ensure serializability may allow too little concurrency for certain applications. In these cases, weaker levels of consistency are used. The use of weaker levels of consistency places additional burdens on programmers for ensuring database correctness.

Degree-Two Consistency

The purpose of degree-two consistency is to avoid cascading aborts without necessarily ensuring serializability. The locking protocol for degree-two consistency uses the same two lock modes that we used for the two-phase locking protocol: shared (S) and exclusive (X). A transaction must hold the appropriate lock mode when it accesses a data item.

In contrast to the situation in two-phase locking, S-locks may be released at any time, and locks may be acquired at any time. Exclusive locks cannot be released until the transaction either commits or aborts. Serializability is not ensured by this pro- tocol. Indeed, a transaction may read the same data item twice and obtain different

image

results. In Figure 16.20, T3 reads the value of Q before and after that value is written by T4.

The potential for inconsistency due to nonserializable schedules under degree-two consistency makes this approach undesirable for many applications.

Cursor Stability

Cursor stability is a form of degree-two consistency designed for programs written in host languages, which iterate over tuples of a relation by using cursors. Instead of locking the entire relation, cursor stability ensures that

• The tuple that is currently being processed by the iteration is locked in shared mode.

• Any modified tuples are locked in exclusive mode until the transaction commits.

These rules ensure that degree-two consistency is obtained. Two-phase locking is not required. Serializability is not guaranteed. Cursor stability is used in practice on heavily accessed relations as a means of increasing concurrency and improving system performance. Applications that use cursor stability must be coded in a way that ensures database consistency despite the possibility of nonserializable schedules. Thus, the use of cursor stability is limited to specialized situations with simple consistency constraints.

Weak Levels of Consistency in SQL

The SQL standard also allows a transaction to specify that it may be executed in such a way that it becomes nonserializable with respect to other transactions. For instance, a transaction may operate at the level of read uncommitted, which permits the transaction to read records even if they have not been committed. SQL provides such features for long transactions whose results do not need to be precise. For instance, approx- imate information is usually sufficient for statistics used for query optimization. If these transactions were to execute in a serializable fashion, they could interfere with other transactions, causing the others’ execution to be delayed.

The levels of consistency specified by SQL-92 are as follows:

Serializable is the default.

Repeatable read allows only committed records to be read, and further re- quires that, between two reads of a record by a transaction, no other trans- action is allowed to update the record. However, the transaction may not be serializable with respect to other transactions. For instance, when it is search- ing for records satisfying some conditions, a transaction may find some of the records inserted by a committed transaction, but may not find others.

Read committed allows only committed records to be read, but does not re- quire even repeatable reads. For instance, between two reads of a record by the transaction, the records may have been updated by other committed transactions. This is basically the same as degree-two consistency; most systems sup- porting this level of consistency would actually implement cursor stability, which is a special case of degree-two consistency.

Read uncommitted allows even uncommitted records to be read. It is the lowest level of consistency allowed by SQL-92.

Comments

Popular posts from this blog

XML Document Schema

Extended Relational-Algebra Operations.

Distributed Databases:Concurrency Control in Distributed Databases