ArticleslgStudy

computer science

Timestamp-based concurrency control

Timestamp-based concurrency control is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Timestamp-based concurrency control rather than just read about it. In short: In computer science, a timestamp-based concurrency control algorithm is a optimistic concurrency control method. It is used in some databases to safely handle transactions using timestamps for synchronization instead of locks.

Key takeaways

  • Timestamp-based concurrency control belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Timestamp-based concurrency control to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Timestamp-based concurrency control from memory before moving on to harder problems.

Reference excerpt

In computer science, a timestamp-based concurrency control algorithm is a optimistic concurrency control method. It is used in some databases to safely handle transactions using timestamps for synchronization instead of locks.

Operation

Assumptions Every timestamp value is unique and accurately represents an instant in time. A higher-valued timestamp occurs later in time than a lower-valued timestamp.

Generating a timestamp A number of different approaches can generate timestamps

Using the value of the system's clock at the start of a transaction as the timestamp. Using a thread-safe shared counter that is incremented at the start of a transaction as the timestamp. A combination of the above two methods.

Formal definition Each transaction (Ti) is an ordered list of actions (Aix). Before the transaction performs its first action (Ai1), it is marked with the current timestamp, or any other strictly totally ordered sequence: TS(Ti)=NOW(). Every transaction is also given an initially empty set of transactions upon which it depends, DEP(Ti)=[], and an initially empty set of old objects which it updated, OLD(Ti)=[]. Each object (Oj) in the database is given two timestamp fields which are not used other than for concurrency control:

RT(Oj) is the timestamp of the last transaction that read the value of the object ( TS(Tr), where Tr is the last transaction that read the value of the object). WT(Oj) is the timestamp of the last transaction that updated the value of the object ( TS(Tw), where Tw is the last transaction that updated the value of the object). For all Ti:

For each action Aix: If Aix wishes to read the value of Oj: If WT(Oj)>TS(Ti) then abort (a more recent thread has overwritten the value), Otherwise update the set of dependencies DEP(Ti).add(WT(Oj)) and set RT(Oj)=max⁡(RT(Oj),TS(Ti)); If Aix wishes to update the value of Oj: If RT(Oj)>TS(Ti) then abort (a more recent thread is already relying on the old value), If WT(Oj)>TS(Ti) then skip (the Thomas Write Rule), Otherwise store the previous values, OLD(Ti).add(Oj,WT(Oj)), set WT(Oj)=TS(Ti), and update the value of Oj. While there is a transaction in DEP(Ti) that has not ended: wait If there is a transaction in DEP(Ti) that aborted then abort Otherwise: commit. To abort:

For each (oldOj,oldWT(Oj)) in OLD(Ti) If WT(Oj) equals TS(Ti) then restore Oj=oldOj and WT(Oj)=oldWT(Oj)

Informal definition Whenever a transaction initiated, it receives a timestamp. The transaction's timestamp indicates when the transaction was initiated. These timestamps ensure that transactions affect each object in the same sequence of their respective timestamps. Thus, given two operations that affect the same object from different transactions, the operation of the transaction with the earlier timestamp must execute before the operation of the transaction with the later timestamp. However, if the operation of the wrong transaction is actually presented first, then it is aborted and the transaction must be restarted. Every object in the database has a read timestamp, which is updated whenever the object's data is read, and a write timestamp, which is updated whenever the object's data is changed. If a transaction wants to read an object,

but the transaction started before the object's write timestamp it means that something changed the object's data after the transaction started. In this case, the transaction is canceled and must be restarted. and the transaction started after the object's write timestamp, it means that it is safe to read the object. In this case, if the transaction's timestamp is after the object's read timestamp, the read timestamp is set to the transaction's timestamp. If a transaction wants to write to an object,

but the transaction started before the object's read timestamp it means that something has had a look at the object, and we assume it took a copy of the object's data. So we can't write to the object as that would make any copied data invalid, so the transaction is aborted and must be restarted. and the transaction started before the object's write timestamp it means that something has changed the object since we started our transaction. In this case we use the Thomas write rule and simply skip our write operation and continue as normal; the transaction does not have to be aborted or restarted otherwise, the transaction writes to the object, and the object's write timestamp is set to the transaction's timestamp.

Physically unrealizable The behavior is physically unrealizable if the results of transactions could not have occurred if transactions were instantaneous. The following are the only two situations that result in physically unrealizable behavior:

Transaction T tries to read X but TS(T) < WT(X). Reason: It means that X has been written to by another transaction after T began. Transaction T tries to write X but TS(T) < RT(X). Reason: It means that a later transaction read X before it was written by T.

Recoverability

Note that timestamp ordering in its basic form does not produce recoverable histories. Consider for example the following history with transactions T1 and T2:

W1(x)R2(x)W2(y)C2R1(z)C1 This could be produced by a TO scheduler, but is not recoverable, as T2 commits even though having read from an uncommitted transaction. To make sure that it produces recoverable histories, a scheduler can keep a list of other transactions each transaction has read from, and not let a transaction commit before this list consisted of only committed transactions. To avoid cascading aborts, the scheduler could tag data written by uncommitted transactions as dirty, and never let a read operation commence on such a data item before it was untagged. To get a strict history, the scheduler should not allow any operations on dirty items.

Implementation issues

Timestamp resolution This is the minimum time elapsed between two adjacent timestamps. If the resolution of the timestamp is too large (coarse), the possibility of two or more timestamps being equal is increased and thus enabling some transactions to commit out of correct order. For example, for a system that creates one hundred unique timestamps per second, two events that occur 2 milliseconds apart may be given the same timestamp even though they occurred at different times.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Timestamp-based concurrency control

Start with the simplest possible case. Write down what Timestamp-based concurrency control claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Timestamp-based concurrency control before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Timestamp-based concurrency control ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Timestamp-based concurrency control

In research
Timestamp-based concurrency control appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Timestamp-based concurrency control in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Timestamp-based concurrency control is common in secondary-school and first-year university syllabi. It links to neighbouring topics Concurrency control, Concurrency control algorithms, Transaction processing, so understanding it makes those chapters shorter.
In everyday life
Look for Timestamp-based concurrency control outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Timestamp-based concurrency control” →

How to study Timestamp-based concurrency control in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Timestamp-based concurrency control means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Timestamp-based concurrency control out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Timestamp-based concurrency control in simple terms?

In computer science, a timestamp-based concurrency control algorithm is a optimistic concurrency control method. It is used in some databases to safely handle transactions using timestamps for synchronization instead of locks.

Why does Timestamp-based concurrency control matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Timestamp-based concurrency control?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Timestamp-based concurrency control.

Tags

  • Concurrency control
  • Concurrency control algorithms
  • Transaction processing

Keep exploring