What is an optimistic concurrency control in DBMS?

DBMSDatabaseBig Data Analytics

All data items are updated at the end of the transaction, at the end, if any data item is found inconsistent with respect to the value in, then the transaction is rolled back.

Check for conflicts at the end of the transaction. No checking while the transaction is executing. Checks are all made at once, so low transaction execution overhead. Updates are not applied until end-transaction. They are applied to local copies in a transaction space.

Phases

The optimistic concurrency control has three phases, which are explained below −

Read Phase

Various data items are read and stored in temporary variables (local copies). All operations are performed in these variables without updating the database.

Validation Phase

All concurrent data items are checked to ensure serializability will not be validated if the transaction updates are actually applied to the database. Any changes in the value cause the transaction rollback. The transaction timestamps are used and the write-sets and read-sets are maintained.

To check that transaction A does not interfere with transaction B the following must hold −

  • TransB completes its write phase before TransA starts the read phase.

  • TransA starts its write phase after TransB completes its write phase, and the read set of TransA has no items in common with the write set of TransB.

  • Both the read set and write set of TransA have no items in common with the write set of TransB and TransB completes its read before TransA completes its read Phase.

Write Phase

The transaction updates applied to the database if the validation is successful. Otherwise, updates are discarded and transactions are aborted and restarted. It does not use any locks hence deadlock free, however starvation problems of data items may occur.

Problem

S: W1(X), r2(Y), r1(Y), r2(X).

T1 -3

T2 – 4

Check whether timestamp ordering protocols allow schedule S.

Solution

Initially for a data-item X, RTS(X)=0, WTS(X)=0

Initially for a data-item Y, RTS(Y)=0, WTS(Y)=0

For W1(X) : TS(Ti)<RTS(X) i.e.
   TS(T1)<RTS(X)
TS(T1)<WTS(X)
3<0 (FALSE)

=>goto else and perform write operation w1(X) and WTS(X)=3

For r2(Y): TS(T2)<WTS(Y)
   4<0 (FALSE)

=>goto else and perform read operation r2(Y) and RTS(Y)=4

For r1(Y) :TS(T1)<WTS(Y)
   3<0 (FALSE)

=>goto else and perform read operation r1(Y).

For r2(X) : TS(T2)<WTS(X)
   4<3 (FALSE)

=>goto else and perform read operation r2(X) and RTS(X)=4

raja
Published on 06-Jul-2021 14:24:13
Advertisements