The Wayback Machine - https://web.archive.org/web/20241114082713/https://www.geeksforgeeks.org/timestamp-based-concurrency-control/
Open In App

Timestamp based Concurrency Control

Last Updated : 27 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Timestamp-based concurrency control is a method used in database systems to ensure that transactions are executed safely and consistently without conflicts, even when multiple transactions are being processed simultaneously. This approach relies on timestamps to manage and coordinate the execution order of transactions. Refer to the timestamp of a transaction T as TS(T).

What is Timestamp Ordering Protocol?

The main idea for this protocol is to order the transactions based on their Timestamps. A schedule in which the transactions participate is then serializable and the only equivalent serial schedule permitted has the transactions in the order of their Timestamp Values. Stating simply, the schedule is equivalent to the particular Serial Order corresponding to the order of the Transaction timestamps. An algorithm must ensure that, for each item accessed by Conflicting Operations in the schedule, the order in which the item is accessed does not violate the ordering. To ensure this, use two Timestamp Values relating to each database item X. 

  • W­_TS(X) is the largest timestamp of any transaction that executed write(X) successfully.
  • R_TS(X) is the largest timestamp of any transaction that executed read(X) successfully.

Basic Timestamp Ordering

Every transaction is issued a timestamp based on when it enters the system. Suppose, if an old transaction Ti has timestamp TS(Ti), a new transaction Tj is assigned timestamp TS(Tj) such that TS(Ti) < TS(Tj). The protocol manages concurrent execution such that the timestamps determine the serializability order. The timestamp ordering protocol ensures that any conflicting read and write operations are executed in timestamp order. Whenever some Transaction T tries to issue a R_item(X) or a W_item(X), the Basic TO algorithm compares the timestamp of T with R_TS(X) & W_TS(X) to ensure that the Timestamp order is not violated. This describes the Basic TO protocol in the following two cases. 

  • Whenever a Transaction T issues a W_item(X) operation, check the following conditions: 
    • If R_TS(X) > TS(T) and if W_TS(X) > TS(T), then abort and rollback T and reject the operation. else,
    • Execute W_item(X) operation of T and set W_TS(X) to TS(T).
  • Whenever a Transaction T issues a R_item(X) operation, check the following conditions: 
    • If W_TS(X) > TS(T), then abort and reject T and reject the operation, else
    • If W_TS(X) <= TS(T), then execute the R_item(X) operation of T and set R_TS(X) to the larger of TS(T) and current R_TS(X). 

Whenever the Basic TO algorithm detects two conflicting operations that occur in an incorrect order, it rejects the latter of the two operations by aborting the Transaction that issued it. Schedules produced by Basic TO are guaranteed to be conflict serializable. Already discussed that using Timestamp can ensure that our schedule will be deadlock free. 
One drawback of the Basic TO protocol is that Cascading Rollback is still possible. Suppose we have a Transaction T1 and T2 has used a value written by T1. If T1 is aborted and resubmitted to the system then, T2 must also be aborted and rolled back. So the problem of Cascading aborts still prevails. Let’s gist the Advantages and Disadvantages of Basic TO protocol: 

  • Timestamp Ordering protocol ensures serializability since the precedence graph will be of the form: 

Timestamp based Protocol

Precedence Graph for TS ordering 

  • Timestamp protocol ensures freedom from deadlock as no transaction ever waits.
  • But the schedule may not be cascade free, and may not even be recoverable.

Strict Timestamp Ordering

A variation of Basic TO is called Strict TO ensures that the schedules are both Strict and Conflict Serializable. In this variation, a Transaction T that issues a R_item(X) or W_item(X) such that TS(T) > W_TS(X) has its read or write operation delayed until the Transaction T‘ that wrote the values of X has committed or aborted. 

Advantages of Timestamp Ordering Protocol

  • High Concurrency: Timestamp-based concurrency control allows for a high degree of concurrency by ensuring that transactions do not interfere with each other.
  • Efficient: The technique is efficient and scalable, as it does not require locking and can handle a large number of transactions.
  • No Deadlocks: Since there are no locks involved, there is no possibility of deadlocks occurring.
  • Improved Performance: By allowing transactions to execute concurrently, the overall performance of the database system can be improved.

Disadvantages of Timestamp Ordering Protocol

  • Limited Granularity: The granularity of timestamp-based concurrency control is limited to the precision of the timestamp. This can lead to situations where transactions are unnecessarily blocked, even if they do not conflict with each other.
  • Timestamp Ordering: In order to ensure that transactions are executed in the correct order, the timestamps need to be carefully managed. If not managed properly, it can lead to inconsistencies in the database.
  • Timestamp Synchronization: Timestamp-based concurrency control requires that all transactions have synchronized clocks. If the clocks are not synchronized, it can lead to incorrect ordering of transactions.
  • Timestamp Allocation: Allocating unique timestamps for each transaction can be challenging, especially in distributed systems where transactions may be initiated at different locations.

Conclusion

In database management systems, timestamp-based protocols are used to organize database transactions according to their timestamp. Timestamp-based protocols in databases enable transaction serialization. Transactions in databases that use timestamp-based protocols are deadlock free. Timestamp-based protocol transactions may not be cascade-free or recoverable.

Related GATE Questions on Timestamp Based Protocol 

  1. GATE | GATE CS 2010 | Question 20
  2. GATE | GATE-CS-2017 (Set 1) | Question 46
  3. GATE | GATE-IT-2004 | Question 21

Frequently Asked Questions on Timestamp Based Protocol – FAQs

What is the timestamp based protocol used for?

Databases use timestamp-based protocols to sort transactions in ascending order based on their creation time.

Is timestamp protocol deadlock free?

Yes Timestamp protocol is deadlock free.

What is the difference between lock and timestamp protocol?

Timestamp-based protocols provide higher concurrency but may lose strict serializability, whereas lock-based protocols provide high serializability but may introduce additional contention and possibly deadlocks.



Previous Article
Next Article

Similar Reads

Graph Based Concurrency Control Protocol in DBMS
Graph-based concurrency control protocols are used in database management systems (DBMS) to ensure that concurrent transactions do not interfere with each other and maintain the consistency of the database. In graph-based concurrency control, transactions are represented as nodes in a graph, and the conflicts between transactions are represented as
4 min read
Lock Based Concurrency Control Protocol in DBMS
In a database management system (DBMS), lock-based concurrency control (BCC) is used to control the access of multiple transactions to the same data item. This protocol helps to maintain data consistency and integrity across multiple users. In the protocol, transactions gain locks on data items to control their access and prevent conflicts between
6 min read
Two Phase Locking (2-PL) Concurrency Control Protocol | Set 3
Prerequisite - Basics of Two-Phase Locking protocol(2-PL), Types of 2-PL. Now, we know both Strict 2-PL and Rigorous 2-PL avoids Cascading Rollbacks and ensures a Strict schedule but still cannot guarantee that our schedule is Deadlock free. We have seen both Strict and Rigorous 2-PL are similar in application and a general misconception is common
3 min read
Types of Locks in Concurrency Control
Commercial demands for ensuring smooth functionality and highly efficient run-time servers, make it highly prime for Database Designers to work out systems and code which cleverly avoid any kinds of inconsistencies in multi-user transactions, if not doubt the standard of memory management in read-heavy, write-heavy and all such commercial databases
11 min read
MOSS Concurrency Control Protocol (Distributed Locking in Database)
This is a protocol which is used to control the concurrency in the Distributed database environment, Here we'll read about the rules and regulations that are required to keep in mind while applying MOSS Concurrency Control Protocol. MOSS Concurrency Control Protocol:- a) It is mainly used for handling the nested(hierarchical) transactions which are
2 min read
Concurrency Control in DBMS
Concurrency control is a very important concept of DBMS which ensures the simultaneous execution or manipulation of data by several processes or user without resulting in data inconsistency. Concurrency Control deals with interleaved execution of more than one transaction. What is Transaction? A transaction is a collection of operations that perfor
13 min read
What is Multi-Version Concurrency Control (MVCC) in DBMS?
Multi-Version Concurrency Control (MVCC) is a database optimization method, that makes redundant copies of records to allow for safe concurrent reading and updating of data. DBMS reads and writes are not blocked by one another while using MVCC. A technique called concurrency control keeps concurrent processes running to avoid read/write conflicts o
5 min read
Concurrency Control Techniques
Concurrency control is provided in a database to: (i) enforce isolation among transactions. (ii) preserve database consistency through consistency preserving execution of transactions. (iii) resolve read-write and write-read conflicts. Various concurrency control techniques are: 1. Two-phase locking Protocol2. Time stamp ordering Protocol3. Multi v
4 min read
Difference Between Flow Control and Error Control
In data transmission, the general aspect of maintaining effective and accurate transfer of data between gadgets is very important. This is where the flow control and the error control mechanisms will be of help. Flow control regulates the amount of data being transmitted from the sender to the receiver so that it does not overpower the receiver, wh
5 min read
Difference between Flow Control and Congestion Control
Flow Control and Congestion Control are traffic controlling methods for different situations. The main difference between flow control and congestion control is that, In flow control, rate of traffic received from a sender can be controlled by a receiver. On the other hand, In congestion control, rate of traffic from sender to the network is contro
4 min read
Concurrency problems in DBMS Transactions
Concurrency control is an essential aspect of database management systems (DBMS) that ensures transactions can execute concurrently without interfering with each other. However, concurrency control can be challenging to implement, and without it, several problems can arise, affecting the consistency of the database. In this article, we will discuss
4 min read
Concurrency in Operating System
Concurrency in operating systems refers to the capability of an OS to handle more than one task or process at the same time, thereby enhancing efficiency and responsiveness. It may be supported by multi-threading or multi-processing whereby more than one process or threads are executed simultaneously or in an interleaved fashion. Thus, more than on
7 min read
Computer based control in Database
In this article, we will discuss the overview of computer-based controls and will discuss computer-based control available in a multi-user database environment in detail. Let's discuss it one by one. Overview :The different forms of countermeasure to threats on the computer systems from physical controls to the managerial procedure. In spite of the
4 min read
Introduction to TimeStamp and Deadlock Prevention Schemes in DBMS
Deadlock occurs when each transaction T in a schedule of two or more transactions waiting for some item locked by some other transaction T' in the set. Thus, both end up in a deadlock situation, waiting for the other to release the lock on the item. Deadlocks are a common problem and we have introduced the problem while solving the Concurrency Cont
7 min read
Multiversion Timestamp Ordering
In the Multiversion timestamp ordering technique, for each transaction in the system, a unique timestamp is assigned before the start of the execution of the transaction. The timestamp of a transaction T is denoted by TS(T). For each data item X a sequence of versions <X1, X2, X3,......XK> is associated. For each version Xi of a data item(X),
3 min read
Main difference between Timestamp protocol and Thomas write rule in DBMS
In database systems, the issue of maintaining consistency while executing transactional processes concurrently is very important. Two concurrency control methods that can maintain the correct sequential Transaction processing in such an environment are the Timestamp Protocol and the Thomas Write Rule. These techniques are however convenient and eff
5 min read
Process-Based and Thread-Based Multitasking
Multitasking operating system is an operating system that gives you the perception of two or more tasks/jobs/processes running simultaneously. It does this by dividing system resources amongst these tasks/jobs/processes and switching between the tasks/jobs/processes while they are executing over and over again. The CPU processes only one task at a
2 min read
Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
Prerequisite - CPU Scheduling Priority Scheduling : In priority scheduling, each process has a priority which is an integer value assigned to it. The smallest integer is considered as the highest priority and the largest integer is considered as the lowest priority. The process with the highest priority gets the CPU first. In rare systems, the larg
4 min read
Difference between Memory based and Register based Addressing Modes
Prerequisite - Addressing Modes Addressing modes are the operations field specifies the operations which need to be performed. The operation must be executed on some data which is already stored in computer registers or in the memory. The way of choosing operands during program execution is dependent on addressing modes of instruction. "The address
4 min read
What is Dispatch and Location-Based Services in Graph-based Database?
Pre-requisites: Types of NoSQL Databases, Introduction to Graph Database on NoSQL NoSQL systems called graph databases were developed for investigating correlation within intricately connected entities. By emphasizing the data relationship more, the structure addresses the drawbacks of relational databases. The use of a graph database approach enab
3 min read
Multi-Cycle Data path and Control
Overview : Multi-cycle data path break up instructions into separate steps. It reduces average instruction time. Each step takes a single clock cycle Each functional unit can be used more than once in an instruction, as long as it is used in different clock cycles. It reduces the amount of hardware needed. (I) Fetch Instruction : An instruction sto
3 min read
Machine Control Instructions in Microprocessor
Introduction Microprocessors are electronic devices that process digital information using instructions stored in memory. Machine control instructions are a type of instruction that control machine functions such as Halt, Interrupt, or do nothing. These instructions alter the different type of operations executed in the processor. In this article,
4 min read
Thread Control Block in Operating System
Very similar to Process Control Blocks (PCBs) which represents processes, Thread Control Blocks (TCBs) represents threads generated in the system. It contains information about the threads, such as it's ID and states. The components have been defined below: Thread ID: It is a unique identifier assigned by the Operating System to the thread when it
1 min read
Real-time Transport Control Protocol (RTCP)
Real-time Transport Protocol (RTP) allows only that type of message, which carries data from the source to the destination. But in some cases, we need some other type of messages in a session. The messages that can control the transmission and quality of data as well as also allow the recipients so that they can send feedback to the source or sourc
3 min read
Control methods of Database Security
Database Security means keeping sensitive information safe and prevent the loss of data. Security of data base is controlled by Database Administrator (DBA). The following are the main control measures are used to provide security of data in databases: 1. Authentication 2. Access control 3. Inference control 4. Flow control 5. Database Security app
3 min read
Job Control Language (JCL) Utilities
JCL Utilities are pre-written programs, widely used in mainframe to achieve day-to-day requirements, organizing and maintaining data. It is used to reorganize, change or compare data at the data set or record level. These utilities allow to manipulate data sets, which are provided as input to the programs. IEBCOPY - It is used to copy one or more m
3 min read
Control Logic Gates in Computer Organization
Control Logic Gates is the hardware component of a basic computer. It comprises some inputs and outputs. The diagram given below is related to the hardwired control organization. The diagram below consists of the instruction register which has three parts: the I bit (15), the operation code (12, 13, 14), and bits 0 through 11. The symbols as D0 to
2 min read
Applications of Microprogrammed Control Unit
Prerequisite : Introduction of Control Unit and its Design Microprogrammed Control Unit :Microprogrammed Control Unit produces control signals by using micro-instructions. Micro program : A program is a set of instructions. An instruction requires a set of micro-operations.Micro-operations are performed using control signals.Here, these control sig
4 min read
Control Signals Generation using Counter
In various digital applications(For example : hardwired control unit) control signals are needed to start, execute and step various operations in a particular time sequence.For this control signals are required and for the generation of control signals, a counter circuit is designed whose outputs are connected to a decoder. The decoder provides the
2 min read
Designing methods of hardwired control unit
Prerequisites : Hardwired control unit Here the control signals are generated using hardware. There are three types of Hardwired Control Units.1. State table method : Here the behavior of control unit is represented in the form of a table, which is known as the state table.Here, each row represents the T-states and the columns represent the instruc
6 min read
Article Tags :
three90RightbarBannerImg