Knowee
Questions
Features
Study Tools

How does a DBMS handle concurrent access to data? What issues can arise and how are they addressed?

Question

How does a DBMS handle concurrent access to data? What issues can arise and how are they addressed?

🧐 Not the exact question you are looking for?Go ask a question

Solution

A Database Management System (DBMS) handles concurrent access to data through a process known as concurrency control. This process ensures that transactions are executed concurrently without violating data consistency.

Here are the steps involved:

  1. Locking Mechanism: The DBMS uses a locking mechanism where any data item being used by a transaction is locked, preventing other transactions from accessing it. There are two types of locks: shared locks and exclusive locks. Shared locks allow multiple transactions to read (but not write) the same data item simultaneously, while exclusive locks allow only one transaction to read and write a data item.

  2. Timestamp-Based Protocols: The DBMS assigns a timestamp to each transaction. If a transaction wants to read or write a data item, the DBMS compares the transaction's timestamp with the data item's read-timestamp or write-timestamp. This helps to maintain the order of transactions and prevent conflicts.

  3. Optimistic Concurrency Control: This method assumes that conflicts between transactions are rare and allows multiple transactions to access the same data item without locks. However, before committing, it checks whether conflicts have occurred. If a conflict is detected, the transaction is rolled back and restarted.

  4. Multi-version Concurrency Control (MVCC): In this method, the DBMS creates a new version of a data item each time it is written, allowing multiple transactions to read different versions of the same data item. This reduces the need for locks and increases concurrency.

Issues that can arise during concurrent access include:

  1. Deadlocks: This occurs when two or more transactions indefinitely wait for each other to release resources. DBMSs handle deadlocks by using a deadlock detection and prevention system that rolls back one of the transactions to break the deadlock.

  2. Dirty Reads: This occurs when a transaction reads data that has been written by another uncommitted transaction. To prevent this, DBMSs use isolation levels that define how and when the changes made by one transaction are visible to others.

  3. Non-repeatable Reads and Phantom Reads: These occur when a transaction reads the same data twice and gets different results each time. This can be prevented by using higher isolation levels or locking mechanisms.

  4. Update Lost: This occurs when two transactions that access the same database item have their operations interleaved in a way that makes the value of some database item incorrect. The DBMS can use a lock-based protocol to prevent this problem.

In summary, a DBMS handles concurrent access to data by using various concurrency control techniques and isolation levels to ensure data consistency and prevent conflicts.

This problem has been solved

Similar Questions

How does a DBMS ensure data integrity and consistency?

Which of the following is a function of the DBMS?Storing dataProviding multi-users access controlData IntegrityAll of the above

Select the purpose of concurrency control.To enforce IsolationTo preserve database consistencyTo resolve read-write and write-write conflictsTo make data more readable to the users

2 Concurrency Control TechniquesThese rules can be enforced by the lock manager module of the DBMS. Between thelock_item(X) and unlock_item(X) operations in transaction T, T is said to hold thelock on item X. At most one transaction can hold the lock on a particular item.Thus no two transactions can access the same item concurrently.Shared/Exclusive (or Read/Write) Locks. The preceding binary lockingscheme is too restrictive for database items because at most, one transaction canhold a lock on a given item. We should allow several transactions to access the sameitem X if they all access X for reading purposes only. This is because read operationson the same item by different transactions are not conflicting (see Section 21.4.1).However, if a transaction is to write an item X, it must have exclusive access to X. Forthis purpose, a different type of lock called a multiple-mode lock is used. In thisscheme—called shared/exclusive or read/write locks—there are three lockingoperations: read_lock(X), write_lock(X), and unlock(X). A lock associated with anitem X, LOCK(X), now has three possible states: read-locked, write-locked, orunlocked. A read-locked item is also called share-locked because other transactionsare allowed to read the item, whereas a write-locked item is called exclusive-lockedbecause a single transaction exclusively holds the lock on the item.One method for implementing the preceding operations on a read/write lock is tokeep track of the number of transactions that hold a shared (read) lock on an itemin the lock table. Each record in the lock table will have four fields: <Data_item_name,LOCK, No_of_reads, Locking_transaction(s)>. Again, to save space, the system needs tomaintain lock records only for locked items in the lock table. The value (state) ofLOCK is either read-locked or write-locked, suitably coded (if we assume no recordsare kept in the lock table for unlocked items). If LOCK(X)=write-locked, the value oflocking_transaction(s) is a single transaction that holds the exclusive (write) lockon X. If LOCK(X)=read-locked, the value of locking transaction(s) is a list of one ormore transactions that hold the shared (read) lock on X. The three operationsread_lock(X), write_lock(X), and unlock(X) are described in Figure 22.2. 2 As before,each of the three locking operations should be considered indivisible; no interleav-ing should be allowed once one of the operations is started until either the opera-tion terminates by granting the lock or the transaction is placed in a waiting queuefor the item.When we use the shared/exclusive locking scheme, the system must enforce the fol-lowing rules:1. A transaction T must issue the operation read_lock(X) or write_lock(X) beforeany read_item(X) operation is performed in T.2. A transaction T must issue the operation write_lock(X) before anywrite_item(X) operation is performed in T.2These algorithms do not allow upgrading or downgrading of locks, as described later in this section. Thereader can extend the algorithms to allow these additional operations.read_lock(X):B: if LOCK(X) = “unlocked”then begin LOCK(X) ← “read-locked”;no_of_reads(X) ← 1endelse if LOCK(X) = “read-locked”then no_of_reads(X) ← no_of_reads(X) + 1else beginwait (until LOCK(X) = “unlocked”and the lock manager wakes up the transaction);go to Bend;write_lock(X):B: if LOCK(X) = “unlocked”then LOCK(X) ← “write-locked”else beginwait (until LOCK(X) = “unlocked”and the lock manager wakes up the transaction);go to Bend;unlock (X):if LOCK(X) = “write-locked”then begin LOCK(X) ← “unlocked”;wakeup one of the waiting transactions, if anyendelse it LOCK(X) = “read-locked”then beginno_of_reads(X) ← no_of_reads(X) −1;if no_of_reads(X) = 0then begin LOCK(X) = “unlocked”;wakeup one of the waiting transactions, if anyendend;22.1 Two-Phase Locking Techniques for Concurrency Control 781Figure 22.2Locking and unlockingoperations for two-mode (read-write orshared-exclusive)locks.3. A transaction T must issue the operation unlock(X) after all read_item(X) andwrite_item(X) operations are completed in T.34. A transaction T will not issue a read_lock(X) operation if it already holds aread (shared) lock or a write (exclusive) lock on item X. This rule may berelaxed, as we discuss shortly.3This rule may be relaxed to allow a transaction to unlock an item, then lock it again later.782 Chapter 22 Concurrency Control Techniques5. A transaction T will not issue a write_lock(X) operation if it already holds aread (shared) lock or write (exclusive) lock on item X. This rule may also berelaxed, as we discuss shortly.6. A transaction T will not issue an unlock(X) operation unless it already holdsa read (shared) lock or a write (exclusive) lock on item X

Which is one function of a database management system (DBMS)?OptionsEnsuring usabilityDeciding what to do with legacy systemsPreventing errors arising, while enabling multiple, simultaneous usersIdentifying what a user needs

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.