Transaction Processing: Concurrency Control ACID Transaction in SQL Concurrency Control Good Versus Bad Schedules Serial Schedul

Total Page:16

File Type:pdf, Size:1020Kb

Transaction Processing: Concurrency Control ACID Transaction in SQL Concurrency Control Good Versus Bad Schedules Serial Schedul ACID • Atomicity Transaction Processing: – Transactions are either done or not done Concurrency Control – They are never left partially executed • Consistency – Transactions should leave the database in a consistent state CPS 216 • Isolation – Transactions must behave as if they were executed in isolation Advanced Database Systems • Durability – Effects of completed transactions are resilient against failures 2 Transaction in SQL Concurrency control • (Implicit beginning of transaction) • Goal: ensure the “I” (isolation) in ACID SELECT …; T1: T2: UPDATE …; read(A); read(A); …… write(A); write(A); ROLLBACK | COMMIT; read(B); read(C); write(B); write(C); • ROLLBACK (a.k.a. transaction abort) commit; commit; – Will undo the the partial effects of the transaction – May be initiated by the DBMS A B C • For example, when some statement in the transaction violates a database constraint 3 4 Good versus bad schedules Serial schedule Good! Bad! Good! (But why?) • Execute transactions in order, with no T1 T2 T1 T2 T1 T2 interleaving of operations – T1.r(A), T1.w(A), T1.r(B), T1.w(B), T2.r(A), T2.w(A), r(A) r(A) r(A) T .r(C), T .w(C) w(A) Read 400 r(A) w(A) 2 2 Read 400 – T .r(A), T .w(A), T .r(C), T .w(C), T .r(A), T .w(A), r(B) Write w(A) r(A) 2 2 2 2 1 1 400 – 100 T1.r(B), T1.w(B) w(B) w(A)Write w(A) r(A) r(B) 400 – 50 r(B) – Isolation achieved by definition! w(A) r(C) r(C) • Problem: no concurrency at all r(C) w(B) w(B) • Question: how to reorder schedule to allow more w(C) w(C) w(C) 5 concurrency 6 1 Conflicting operations Precedence graph • Two operations on the same data item conflict if • A node for each transaction at least one of the operations is a write • A directed edge from Ti to Tj if an operation of Ti –r(X) and w(X) conflict precedes and conflicts with an operation of Tj in –w(X) and r(X) conflict the schedule –w(X) and w(X) conflict T1 T2 T1 T2 T1 T1 –r(X) and r(X) do not r(A) r(A) w(A) r(A) T T –r/w(X) and r/w(Y) do not r(A) 2 w(A) 2 • Order of conflicting operations matters w(A) w(A) r(B) Good: r(B) Bad: r(C) r(C) –If T1.r(A) precedes T2.w(A), then conceptually, T1 no cycle cycle w(B) w(B) should precede T2 7 w(C) w(C) 8 Conflict-serializable schedule Locking • A schedule is conflict-serializable iff its •Rules precedence graph has no cycles – If a transaction wants to read an object, it must first • A conflict-serializable schedule is equivalent to request a shared lock (S mode) on that object some serial schedule (and therefore is “good”) – If a transaction wants to modify an object, it must first request an exclusive lock (X mode) on that object – In that serial schedule, transactions are executed in the topological order of the precedence graph – Allow one exclusive lock, or multiple shared locks – You can get to that serial schedule by repeatedly Mode of the lock requested Mode of lock(s) swapping adjacent, non-conflicting operations from SX currently held SYesNo Grant the lock? different transactions by other transactions XNoNo Compatibility matrix 9 10 Basic locking is not enough Two-phase locking (2PL) Add 1 to both A and B T1 T2 Multiply both A and B by 2 (preserve A=B) (preserves A=B) lock-X(A) • All lock requests precede all unlock requests Read 100 r(A) – Phase 1: obtain locks, phase 2: release locks Write 100+1 w(A) T T T T unlock(A) 1 2 1 2 lock-X(A) lock-X(A) 2PL guarantees a T r(A) conflict-serializable r(A) Possible schedule r(A) Read 101 1 w(A) schedule w(A) under locking w(A) Write 101*2 lock-X(B) r(A) unlock(A) unlock(A) T2 lock-X(A) w(A) But still not lock-X(B) r(A) r(B) Read 100 conflict-serializable! r(B) w(A) w(B) w(B) Write 100*2 lock-X(B) r(B) unlock(B) r(B) w(B) lock-X(B) w(B) Read 200 r(B) A <> B! r(B) Cannot obtain the lock on B until T unlocks Write 200+1 w(B) 11 w(B) 1 12 unlock(B) unlock(B) 2 Problem of 2PL Strict 2PL T T 1 2 • T2 has read uncommitted data r(A) written by T1 w(A) • Only release locks at commit/abort time r(A) • If T1 aborts, then T2 must – A writer will block all other readers until the writer w(A) abort as well r(B) commits or aborts w(B) • Cascading aborts possible if r(B) w(B) other transactions have read Abort! • Used in most commercial DBMS (except Oracle) data written by T2 • What’s worse, what if T2 commits before T1? – Not recoverable if the system crashes right after T2 commits 13 14 Deadlocks Dealing with deadlocks • Impose an order for locking objects T1 T2 lock-X(A) – Must know in advance which objects a transaction will access r(A) Deadlock = w(A) lock-X(B) cycle in the wait-for graph • Timeout r(B) – If a transaction has been blocked for too long, just abort w(B) T lock-X(B)lock-X(A) 1 • Prevention Deadlock! T1 is waiting for T2 T2 is waiting for T1 – Idea: abort more often, so blocking is less likely r(B) r(A) T w(B) w(A) 2 – Wait/die versus wound/wait • Detection using wait-for graph – Idea: deadlock is rare, so only deal it when it becomes an issue – How often do we detect deadlocks? 15 – Which transactions do we abort in case of deadlock? 16 Implementation of locking SQL transaction isolation levels • Do not rely on transactions themselves to • SERIALIZABLE (default) lock/unlock explicitly • Weaker isolations levels • DBMS inserts lock/unlock requests automatically – READ UNCOMMITTED Transactions – READ COMMITTED Streams of operations – REPEATABLE READ Insert lock/unlock requests Operations with • Why weaker levels? lock/unlock requests – Increase performance by eliminating overhead and Lock table Scheduler allowing higher degree of concurrency Lock info for each object, Serialized schedule with no including locks currently held lock/unlock operations and the request queue 17 18 3 READ UNCOMMITTED READ COMMITTED • Dirty reads possible (dirty = uncommitted) • No dirty reads, but non-repeatable reads possible • Example: wrong average • Example: different averages T1: T2: T1: T2: SELECT AVG(balance) UPDATE Account UPDATE Account FROM Account; SET balance = balance – 200 SET balance = balance – 200 WHERE number = 142857; SELECT AVG(balance) WHERE number = 142857; FROM Account; COMMIT; ROLLBACK; SELECT AVG(balance) COMMIT; FROM Account; COMMIT; • Possible cause • Possible cause – Non-strict locking protocol, or no read lock 19 – Locking is not two-phase 20 REPEATABLE READ Summary of SQL isolation levels • Reads repeatable, but may see phantoms Isolation level / anomaly Dirty reads Non-repeatable reads Phantoms • Example: different average (still!) READ UNCOMMITTED Yes Yes Yes READ COMMITTED No Yes Yes T1: T2: REPEATABLE READ No No Yes SELECT AVG(balance) SERIALIZABLE No No No INSERT INTO Account FROM Account; VALUES(428571, 1000); COMMIT; • Criticized for definition in terms of anomalies SELECT AVG(balance) FROM Account; – Berenson, Bernstein, Gray, et al. “A critique of ANSI COMMIT; SQL isolation levels,” SIGMOD 1995 • Possible cause – Insertion did not acquire any lock (what to acquire?) 21 22 Concurrency control without locking Optimistic concurrency control • Locking is pessimistic • Optimistic (validation-based) – Use blocking to avoid conflicts – Overhead of locking even if contention is low • Timestamp-based • Optimistic concurrency control – Assume that most transactions do not conflict – Let them execute as much as possible • Multi-version (Oracle) – If it turns out that they conflict, abort and restart 23 24 4 Sketch of protocol Pessimistic versus optimistic • Read phase: transaction executes, reads from the • Overhead of locking versus overhead of database, and writes to a private space validation and copying private space • Validate phase: DBMS checks for conflicts with • Blocking versus aborts and restarts other transactions; if conflict is possible, abort • Agrawal, Carey, and Livny. “Concurrency control and restart performance modeling: alternatives and implications,” – Requires maintaining a list of objects read and written TODS 12(4), 1987 by each transaction – Locking has better throughput for environments with • Write phase: copy changes in the private space to medium-to-high contention the database – Optimistic concurrency control is better when resource utilization is low enough 25 26 Timestamp-based Multi-version concurrency control • Associate each database object with a read • Maintain versions for each database object timestamp and a write timestamp – Each write creates a new version • Assign a timestamp to each transaction – Each read is directed to an appropriate version • Timestamp order is commit order – Conflicts are detected in a similar manner as • When transaction reads/writes an object, check timestamp concurrency control the object’s timestamp for conflict with a younger • In addition to the problems inherited from transaction; if so, abort and restart timestamp concurrency control • Problems – Pro: Reads are never blocked – Even reads require writes (of object timestamps) – Con: Multiple versions need to be maintained – Ensuring recoverability is hard (plenty of dirty reads) • Oracle uses some variant of this scheme 27 28 Summary Next time • Covered – Conflict-serializability – 2PL, strict 2PL Recovery – Deadlocks SQL triggers and programming interface – Overview of other concurrency-control methods • Not covered – View-serializability – Hierarchical locking – Predicate locking and tree locking 29 30 5.
Recommended publications
  • Rainblock: Faster Transaction Processing in Public Blockchains
    RainBlock: Faster Transaction Processing in Public Blockchains Soujanya Ponnapalli1, Aashaka Shah1, Souvik Banerjee1, Dahlia Malkhi2, Amy Tai3, Vijay Chidambaram1,3, and Michael Wei3 1University of Texas at Austin, 2Diem Association and Novi Financial, 3VMware Research Abstract Metric No state State: 10M Ratio We present RAINBLOCK, a public blockchain that achieves Time taken to mine txs (s) 1047 6340 6× " high transaction throughput without modifying the proof-of- # Txs per block 2150 833 2.5× # work consensus. The chief insight behind RAINBLOCK is that Tx throughput (txs/s) 28.6 4.7 6× # while consensus controls the rate at which new blocks are added to the blockchain, the number of transactions in each Table 1: Impact of system state on blockchain throughput. block is limited by I/O bottlenecks. Public blockchains like This table shows the throughput of Ethereum with proof-of- Ethereum keep the number of transactions in each block low work consensus when 30K txs are mined using three miners, so that all participating servers (miners) have enough time to in two scenarios: first, there are no accounts on the blockchain, process a block before the next block is created. By removing and in the second, 10M accounts have been added. Despite the I/O bottlenecks in transaction processing, RAINBLOCK al- no other difference, tx throughput is 6× lower in the second lows miners to process more transactions in the same amount scenario; we trace this to the I/O involved in processing txs. of time. RAINBLOCK makes two novel contributions: the RAIN- BLOCK architecture that removes I/O from the critical path of processing transactions (txs), and the distributed, multi- Bitcoin [1] and Ethereum, process only tens of transactions versioned DSM-TREE data structure that stores the system per second, limiting their applications [33, 65].
    [Show full text]
  • Not ACID, Not BASE, but SALT a Transaction Processing Perspective on Blockchains
    Not ACID, not BASE, but SALT A Transaction Processing Perspective on Blockchains Stefan Tai, Jacob Eberhardt and Markus Klems Information Systems Engineering, Technische Universitat¨ Berlin fst, je, [email protected] Keywords: SALT, blockchain, decentralized, ACID, BASE, transaction processing Abstract: Traditional ACID transactions, typically supported by relational database management systems, emphasize database consistency. BASE provides a model that trades some consistency for availability, and is typically favored by cloud systems and NoSQL data stores. With the increasing popularity of blockchain technology, another alternative to both ACID and BASE is introduced: SALT. In this keynote paper, we present SALT as a model to explain blockchains and their use in application architecture. We take both, a transaction and a transaction processing systems perspective on the SALT model. From a transactions perspective, SALT is about Sequential, Agreed-on, Ledgered, and Tamper-resistant transaction processing. From a systems perspec- tive, SALT is about decentralized transaction processing systems being Symmetric, Admin-free, Ledgered and Time-consensual. We discuss the importance of these dual perspectives, both, when comparing SALT with ACID and BASE, and when engineering blockchain-based applications. We expect the next-generation of decentralized transactional applications to leverage combinations of all three transaction models. 1 INTRODUCTION against. Using the admittedly contrived acronym of SALT, we characterize blockchain-based transactions There is a common belief that blockchains have the – from a transactions perspective – as Sequential, potential to fundamentally disrupt entire industries. Agreed, Ledgered, and Tamper-resistant, and – from Whether we are talking about financial services, the a systems perspective – as Symmetric, Admin-free, sharing economy, the Internet of Things, or future en- Ledgered, and Time-consensual.
    [Show full text]
  • Failures in DBMS
    Chapter 11 Database Recovery 1 Failures in DBMS Two common kinds of failures StSystem filfailure (t)(e.g. power outage) ‒ affects all transactions currently in progress but does not physically damage the data (soft crash) Media failures (e.g. Head crash on the disk) ‒ damagg()e to the database (hard crash) ‒ need backup data Recoveryyp scheme responsible for handling failures and restoring database to consistent state 2 Recovery Recovering the database itself Recovery algorithm has two parts ‒ Actions taken during normal operation to ensure system can recover from failure (e.g., backup, log file) ‒ Actions taken after a failure to restore database to consistent state We will discuss (briefly) ‒ Transactions/Transaction recovery ‒ System Recovery 3 Transactions A database is updated by processing transactions that result in changes to one or more records. A user’s program may carry out many operations on the data retrieved from the database, but the DBMS is only concerned with data read/written from/to the database. The DBMS’s abstract view of a user program is a sequence of transactions (reads and writes). To understand database recovery, we must first understand the concept of transaction integrity. 4 Transactions A transaction is considered a logical unit of work ‒ START Statement: BEGIN TRANSACTION ‒ END Statement: COMMIT ‒ Execution errors: ROLLBACK Assume we want to transfer $100 from one bank (A) account to another (B): UPDATE Account_A SET Balance= Balance -100; UPDATE Account_B SET Balance= Balance +100; We want these two operations to appear as a single atomic action 5 Transactions We want these two operations to appear as a single atomic action ‒ To avoid inconsistent states of the database in-between the two updates ‒ And obviously we cannot allow the first UPDATE to be executed and the second not or vice versa.
    [Show full text]
  • What Is a Database Management System? What Is a Transaction
    What is a Database? Collection of data central to some enterprise Overview of Databases and Essential to operation of enterprise Transaction Processing Contains the only record of enterprise activity An asset in its own right Chapter 1 Historical data can guide enterprise strategy Of interest to other enterprises State of database mirrors state of enterprise Database is persistent 2 What is a Database Management What is a Transaction? System? When an event in the real world changes the A Database Management System (DBMS) state of the enterprise, a transaction is is a program that manages a database: executed to cause the corresponding change in the database state Supports a high-level access language (e.g. With an on-line database, the event causes the SQL). transaction to be executed in real time Application describes database accesses using A transaction is an application program that language. with special properties - discussed later - to DBMS interprets statements of language to guarantee it maintains database correctness perform requested database access. 3 4 What is a Transaction Processing Transaction Processing System System? Transaction execution is controlled by a TP monitor s DBMS database n o i Creates the abstraction of a transaction, t c a analogous to the way an operating system s n a r creates the abstraction of a process t DBMS database TP monitor and DBMS together guarantee the special properties of transactions TP Monitor A Transaction Processing System consists of TP monitor, databases, and transactions 5 6 1 System
    [Show full text]
  • Transaction Processing Monitors
    Chapter 24: Advanced Transaction Processing ! Transaction-Processing Monitors ! Transactional Workflows ! High-Performance Transaction Systems ! Main memory databases ! Real-Time Transaction Systems ! Long-Duration Transactions ! Transaction management in multidatabase systems 1 Database System Concepts 24.1 ©Silberschatz, Korth and Sudarshan Transaction Processing Monitors ! TP monitors initially developed as multithreaded servers to support large numbers of terminals from a single process. ! Provide infrastructure for building and administering complex transaction processing systems with a large number of clients and multiple servers. ! Provide services such as: ! Presentation facilities to simplify creating user interfaces ! Persistent queuing of client requests and server responses ! Routing of client messages to servers ! Coordination of two-phase commit when transactions access multiple servers. ! Some commercial TP monitors: CICS from IBM, Pathway from Tandem, Top End from NCR, and Encina from Transarc 2 Database System Concepts 24.2 ©Silberschatz, Korth and Sudarshan 1 TP Monitor Architectures 3 Database System Concepts 24.3 ©Silberschatz, Korth and Sudarshan TP Monitor Architectures (Cont.) ! Process per client model - instead of individual login session per terminal, server process communicates with the terminal, handles authentication, and executes actions. ! Memory requirements are high ! Multitasking- high CPU overhead for context switching between processes ! Single process model - all remote terminals connect to a single server process. ! Used in client-server environments ! Server process is multi-threaded; low cost for thread switching ! No protection between applications ! Not suited for parallel or distributed databases 4 Database System Concepts 24.4 ©Silberschatz, Korth and Sudarshan 2 TP Monitor Architectures (Cont.) ! Many-server single-router model - multiple application server processes access a common database; clients communicate with the application through a single communication process that routes requests.
    [Show full text]
  • High-Performance Transaction Processing in SAP HANA
    High-Performance Transaction Processing in SAP HANA Juchang Lee1, Michael Muehle1, Norman May1, Franz Faerber1, Vishal Sikka1, Hasso Plattner2, Jens Krueger2, Martin Grund3 1SAP AG 2Hasso Plattner Insitute, Potsdam, Germany, 3eXascale Infolab, University of Fribourg, Switzerland Abstract Modern enterprise applications are currently undergoing a complete paradigm shift away from tradi- tional transactional processing to combined analytical and transactional processing. This challenge of combining two opposing query types in a single database management system results in additional re- quirements for transaction management as well. In this paper, we discuss our approach to achieve high throughput for transactional query processing while allowing concurrent analytical queries. We present our approach to distributed snapshot isolation and optimized two-phase commit protocols. 1 Introduction An efficient and holistic data management infrastructure is one of the key requirements for making the right deci- sions at an operational, tactical, and strategic level and is core to support all kinds of enterprise applications[12]. In contrast to traditional architectures of database systems, the SAP HANA database takes a different approach to provide support for a wide range of data management tasks. The system is organized in a main-memory centric fashion to reflect the shift within the memory hierarchy[2] and to consistently provide high perfor- mance without prohibitively slow disk interactions. Completely transparent for the application, data is orga- nized along its life cycle either in column or row format, providing the best performance for different workload characteristics[11, 1]. Transactional workloads with a high update rate and point queries can be routed against a row store; analytical workloads with range scans over large datasets are supported by column oriented data struc- tures.
    [Show full text]
  • SQL Vs Nosql: a Performance Comparison
    SQL vs NoSQL: A Performance Comparison Ruihan Wang Zongyan Yang University of Rochester University of Rochester [email protected] [email protected] Abstract 2. ACID Properties and CAP Theorem We always hear some statements like ‘SQL is outdated’, 2.1. ACID Properties ‘This is the world of NoSQL’, ‘SQL is still used a lot by We need to refer the ACID properties[12]: most of companies.’ Which one is accurate? Has NoSQL completely replace SQL? Or is NoSQL just a hype? SQL Atomicity (Structured Query Language) is a standard query language A transaction is an atomic unit of processing; it should for relational database management system. The most popu- either be performed in its entirety or not performed at lar types of RDBMS(Relational Database Management Sys- all. tems) like Oracle, MySQL, SQL Server, uses SQL as their Consistency preservation standard database query language.[3] NoSQL means Not A transaction should be consistency preserving, meaning Only SQL, which is a collection of non-relational data stor- that if it is completely executed from beginning to end age systems. The important character of NoSQL is that it re- without interference from other transactions, it should laxes one or more of the ACID properties for a better perfor- take the database from one consistent state to another. mance in desired fields. Some of the NOSQL databases most Isolation companies using are Cassandra, CouchDB, Hadoop Hbase, A transaction should appear as though it is being exe- MongoDB. In this paper, we’ll outline the general differences cuted in iso- lation from other transactions, even though between the SQL and NoSQL, discuss if Relational Database many transactions are execut- ing concurrently.
    [Show full text]
  • APPENDIX G Acid Dissociation Constants
    harxxxxx_App-G.qxd 3/8/10 1:34 PM Page AP11 APPENDIX G Acid Dissociation Constants §␮ ϭ 0.1 M 0 ؍ (Ionic strength (␮ † ‡ † Name Structure* pKa Ka pKa ϫ Ϫ5 Acetic acid CH3CO2H 4.756 1.75 10 4.56 (ethanoic acid) N ϩ H3 ϫ Ϫ3 Alanine CHCH3 2.344 (CO2H) 4.53 10 2.33 ϫ Ϫ10 9.868 (NH3) 1.36 10 9.71 CO2H ϩ Ϫ5 Aminobenzene NH3 4.601 2.51 ϫ 10 4.64 (aniline) ϪO SNϩ Ϫ4 4-Aminobenzenesulfonic acid 3 H3 3.232 5.86 ϫ 10 3.01 (sulfanilic acid) ϩ NH3 ϫ Ϫ3 2-Aminobenzoic acid 2.08 (CO2H) 8.3 10 2.01 ϫ Ϫ5 (anthranilic acid) 4.96 (NH3) 1.10 10 4.78 CO2H ϩ 2-Aminoethanethiol HSCH2CH2NH3 —— 8.21 (SH) (2-mercaptoethylamine) —— 10.73 (NH3) ϩ ϫ Ϫ10 2-Aminoethanol HOCH2CH2NH3 9.498 3.18 10 9.52 (ethanolamine) O H ϫ Ϫ5 4.70 (NH3) (20°) 2.0 10 4.74 2-Aminophenol Ϫ 9.97 (OH) (20°) 1.05 ϫ 10 10 9.87 ϩ NH3 ϩ ϫ Ϫ10 Ammonia NH4 9.245 5.69 10 9.26 N ϩ H3 N ϩ H2 ϫ Ϫ2 1.823 (CO2H) 1.50 10 2.03 CHCH CH CH NHC ϫ Ϫ9 Arginine 2 2 2 8.991 (NH3) 1.02 10 9.00 NH —— (NH2) —— (12.1) CO2H 2 O Ϫ 2.24 5.8 ϫ 10 3 2.15 Ϫ Arsenic acid HO As OH 6.96 1.10 ϫ 10 7 6.65 Ϫ (hydrogen arsenate) (11.50) 3.2 ϫ 10 12 (11.18) OH ϫ Ϫ10 Arsenious acid As(OH)3 9.29 5.1 10 9.14 (hydrogen arsenite) N ϩ O H3 Asparagine CHCH2CNH2 —— —— 2.16 (CO2H) —— —— 8.73 (NH3) CO2H *Each acid is written in its protonated form.
    [Show full text]
  • Drugs and Acid Dissociation Constants Ionisation of Drug Molecules Most Drugs Ionise in Aqueous Solution.1 They Are Weak Acids Or Weak Bases
    Drugs and acid dissociation constants Ionisation of drug molecules Most drugs ionise in aqueous solution.1 They are weak acids or weak bases. Those that are weak acids ionise in water to give acidic solutions while those that are weak bases ionise to give basic solutions. Drug molecules that are weak acids Drug molecules that are weak bases where, HA = acid (the drug molecule) where, B = base (the drug molecule) H2O = base H2O = acid A− = conjugate base (the drug anion) OH− = conjugate base (the drug anion) + + H3O = conjugate acid BH = conjugate acid Acid dissociation constant, Ka For a drug molecule that is a weak acid The equilibrium constant for this ionisation is given by the equation + − where [H3O ], [A ], [HA] and [H2O] are the concentrations at equilibrium. In a dilute solution the concentration of water is to all intents and purposes constant. So the equation is simplified to: where Ka is the acid dissociation constant for the weak acid + + Also, H3O is often written simply as H and the equation for Ka is usually written as: Values for Ka are extremely small and, therefore, pKa values are given (similar to the reason pH is used rather than [H+]. The relationship between pKa and pH is given by the Henderson–Hasselbalch equation: or This relationship is important when determining pKa values from pH measurements. Base dissociation constant, Kb For a drug molecule that is a weak base: 1 Ionisation of drug molecules. 1 Following the same logic as for deriving Ka, base dissociation constant, Kb, is given by: and Ionisation of water Water ionises very slightly.
    [Show full text]
  • Concurrency Control
    Concurrency Control Instructor: Matei Zaharia cs245.stanford.edu Outline What makes a schedule serializable? Conflict serializability Precedence graphs Enforcing serializability via 2-phase locking » Shared and exclusive locks » Lock tables and multi-level locking Optimistic concurrency with validation Concurrency control + recovery CS 245 2 Lock Modes Beyond S/X Examples: (1) increment lock (2) update lock CS 245 3 Example 1: Increment Lock Atomic addition action: INi(A) {Read(A); A ¬ A+k; Write(A)} INi(A), INj(A) do not conflict, because addition is commutative! CS 245 4 Compatibility Matrix compat S X I S T F F X F F F I F F T CS 245 5 Update Locks A common deadlock problem with upgrades: T1 T2 l-S1(A) l-S2(A) l-X1(A) l-X2(A) --- Deadlock --- CS 245 6 Solution If Ti wants to read A and knows it may later want to write A, it requests an update lock (not shared lock) CS 245 7 Compatibility Matrix New request compat S X U S T F Lock already X F F held in U CS 245 8 Compatibility Matrix New request compat S X U S T F T Lock already X F F F held in U F F F Note: asymmetric table! CS 245 9 How Is Locking Implemented In Practice? Every system is different (e.g., may not even provide conflict serializable schedules) But here is one (simplified) way ... CS 245 10 Sample Locking System 1. Don’t ask transactions to request/release locks: just get the weakest lock for each action they perform 2.
    [Show full text]
  • Sundial: Harmonizing Concurrency Control and Caching in a Distributed OLTP Database Management System
    Sundial: Harmonizing Concurrency Control and Caching in a Distributed OLTP Database Management System Xiangyao Yu, Yu Xia, Andrew Pavlo♠ Daniel Sanchez, Larry Rudolph|, Srinivas Devadas Massachusetts Institute of Technology, ♠Carnegie Mellon University, |Two Sigma Investments, LP [email protected], [email protected], [email protected] [email protected], [email protected], [email protected] ABSTRACT and foremost, long network delays lead to long execution time of Distributed transactions suffer from poor performance due to two distributed transactions, making them slower than single-partition major limiting factors. First, distributed transactions suffer from transactions. Second, long execution time increases the likelihood high latency because each of their accesses to remote data incurs a of contention among transactions, leading to more aborts and per- long network delay. Second, this high latency increases the likeli- formance degradation. hood of contention among distributed transactions, leading to high Recent work on improving distributed concurrency control has abort rates and low performance. focused on protocol-level and hardware-level improvements. Im- We present Sundial, an in-memory distributed optimistic concur- proved protocols can reduce synchronization overhead among trans- rency control protocol that addresses these two limitations. First, to actions [22, 35, 36, 46], but can still limit performance due to high reduce the transaction abort rate, Sundial dynamically determines coordination overhead (e.g., lock blocking). Hardware-level im- the logical order among transactions at runtime, based on their data provements include using special hardware like optimized networks access patterns. Sundial achieves this by applying logical leases to that enable low-latency remote memory accesses [20, 48, 55], which each data element, which allows the database to dynamically calcu- can increase the overall cost of the system.
    [Show full text]
  • A Transaction Processing Method for Distributed Database
    Advances in Computer Science Research, volume 87 3rd International Conference on Mechatronics Engineering and Information Technology (ICMEIT 2019) A Transaction Processing Method for Distributed Database Zhian Lin a, Chi Zhang b School of Computer and Cyberspace Security, Communication University of China, Beijing, China [email protected], [email protected] Abstract. This paper introduces the distributed transaction processing model and two-phase commit protocol, and analyses the shortcomings of the two-phase commit protocol. And then we proposed a new distributed transaction processing method which adds heartbeat mechanism into the two- phase commit protocol. Using the method can improve reliability and reduce blocking in distributed transaction processing. Keywords: distributed transaction, two-phase commit protocol, heartbeat mechanism. 1. Introduction Most database services of application systems will be distributed on several servers, especially in some large-scale systems. Distributed transaction processing will be involved in the execution of business logic. At present, two-phase commit protocol is one of the methods to distributed transaction processing in distributed database systems. The two-phase commit protocol includes coordinator (transaction manager) and several participants (databases). In the process of communication between the coordinator and the participants, if the participants without reply for fail, the coordinator can only wait all the time, which can easily cause system blocking. In this paper, heartbeat mechanism is introduced to monitor participants, which avoid the risk of blocking of two-phase commit protocol, and improve the reliability and efficiency of distributed database system. 2. Distributed Transactions 2.1 Distributed Transaction Processing Model In a distributed system, each node is physically independent and they communicates and coordinates each other through the network.
    [Show full text]