Transaction Processing (Διαχείριση Δοσοληψιών)

Σχετικά έγγραφα
Αρχεία και Βάσεις Δεδομένων

Locking to ensure serializability

Αρχεία και Βάσεις Δεδομένων

EE512: Error Control Coding

Συστήματα Διαχείρισης Βάσεων Δεδομένων

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

Fractional Colorings and Zykov Products of graphs

2 Composition. Invertible Mappings

C.S. 430 Assignment 6, Sample Solutions

The challenges of non-stable predicates

Section 8.3 Trigonometric Equations

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

Instruction Execution Times

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Nowhere-zero flows Let be a digraph, Abelian group. A Γ-circulation in is a mapping : such that, where, and : tail in X, head in

Homework 3 Solutions

Every set of first-order formulas is equivalent to an independent set

Other Test Constructions: Likelihood Ratio & Bayes Tests

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

Εγκατάσταση λογισμικού και αναβάθμιση συσκευής Device software installation and software upgrade

PARTIAL NOTES for 6.1 Trigonometric Identities

Physical DB Design. B-Trees Index files can become quite large for large main files Indices on index files are possible.

On a four-dimensional hyperbolic manifold with finite volume

Example Sheet 3 Solutions

ST5224: Advanced Statistical Theory II

Finite Field Problems: Solutions

Assalamu `alaikum wr. wb.

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

ANSWERSHEET (TOPIC = DIFFERENTIAL CALCULUS) COLLECTION #2. h 0 h h 0 h h 0 ( ) g k = g 0 + g 1 + g g 2009 =?

Matrices and Determinants

6.1. Dirac Equation. Hamiltonian. Dirac Eq.

Lecture 2. Soundness and completeness of propositional logic

Απόκριση σε Μοναδιαία Ωστική Δύναμη (Unit Impulse) Απόκριση σε Δυνάμεις Αυθαίρετα Μεταβαλλόμενες με το Χρόνο. Απόστολος Σ.

Potential Dividers. 46 minutes. 46 marks. Page 1 of 11

Section 7.6 Double and Half Angle Formulas

TMA4115 Matematikk 3

Section 9.2 Polar Equations and Graphs

Congruence Classes of Invertible Matrices of Order 3 over F 2

The Simply Typed Lambda Calculus

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

Practice Exam 2. Conceptual Questions. 1. State a Basic identity and then verify it. (a) Identity: Solution: One identity is csc(θ) = 1

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

Reminders: linear functions

Second Order RLC Filters

Μηχανική Μάθηση Hypothesis Testing

k A = [k, k]( )[a 1, a 2 ] = [ka 1,ka 2 ] 4For the division of two intervals of confidence in R +

Math 6 SL Probability Distributions Practice Test Mark Scheme

4.6 Autoregressive Moving Average Model ARMA(1,1)

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

Lecture 34 Bootstrap confidence intervals

Αλγόριθμοι και πολυπλοκότητα NP-Completeness (2)

CHAPTER 48 APPLICATIONS OF MATRICES AND DETERMINANTS

[1] P Q. Fig. 3.1

Test Data Management in Practice

ΤΕΧΝΟΛΟΓΙΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ ΤΜΗΜΑ ΝΟΣΗΛΕΥΤΙΚΗΣ

Fourier Series. MATH 211, Calculus II. J. Robert Buchanan. Spring Department of Mathematics

Concrete Mathematics Exercises from 30 September 2016

Partial Differential Equations in Biology The boundary element method. March 26, 2013

CRASH COURSE IN PRECALCULUS

Inverse trigonometric functions & General Solution of Trigonometric Equations

Math221: HW# 1 solutions

1) Formulation of the Problem as a Linear Programming Model

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

SCHOOL OF MATHEMATICAL SCIENCES G11LMA Linear Mathematics Examination Solutions

derivation of the Laplacian from rectangular to spherical coordinates

Main source: "Discrete-time systems and computer control" by Α. ΣΚΟΔΡΑΣ ΨΗΦΙΑΚΟΣ ΕΛΕΓΧΟΣ ΔΙΑΛΕΞΗ 4 ΔΙΑΦΑΝΕΙΑ 1

Second Order Partial Differential Equations

Modbus basic setup notes for IO-Link AL1xxx Master Block

Strain gauge and rosettes

Solution Series 9. i=1 x i and i=1 x i.

( y) Partial Differential Equations

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Bounding Nonsplitting Enumeration Degrees

the total number of electrons passing through the lamp.

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

5.4 The Poisson Distribution.

Οδηγίες Αγοράς Ηλεκτρονικού Βιβλίου Instructions for Buying an ebook

Approximation of distance between locations on earth given by latitude and longitude

Areas and Lengths in Polar Coordinates

Abstract Storage Devices

Statistical Inference I Locally most powerful tests

2. THEORY OF EQUATIONS. PREVIOUS EAMCET Bits.

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/2006

Numerical Analysis FMN011

Tridiagonal matrices. Gérard MEURANT. October, 2008

CHAPTER 101 FOURIER SERIES FOR PERIODIC FUNCTIONS OF PERIOD

Advanced Subsidiary Unit 1: Understanding and Written Response

Econ 2110: Fall 2008 Suggested Solutions to Problem Set 8 questions or comments to Dan Fetter 1

(1) Describe the process by which mercury atoms become excited in a fluorescent tube (3)

Στο εστιατόριο «ToDokimasesPrinToBgaleisStonKosmo?» έξω από τους δακτυλίους του Κρόνου, οι παραγγελίες γίνονται ηλεκτρονικά.

Mean bond enthalpy Standard enthalpy of formation Bond N H N N N N H O O O

Areas and Lengths in Polar Coordinates

Business English. Ενότητα # 9: Financial Planning. Ευαγγελία Κουτσογιάννη Τμήμα Διοίκησης Επιχειρήσεων

A Bonus-Malus System as a Markov Set-Chain. Małgorzata Niemiec Warsaw School of Economics Institute of Econometrics

5. Choice under Uncertainty

Συστήματα Διαχείρισης Βάσεων Δεδομένων

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 10η: Basics of Game Theory part 2 Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

Transcript:

Transaction Processing (Διαχείριση Δοσοληψιών) In modern applications databases are shared by more than one users at the same time who can query and update them It is not possible to provide each user with their own copy of the database A database management system must ensure that: concurrent access is provided each user has a consistent view of the data 1

Transaction Management The problems encountered in the development of large database applications led to the development of transaction management techniques Creation of inconsistent results (Consistency) the machine crashes in the middle of the execution process Errors in concurrent execution (Concurrency) arbitrary concurrent execution of processes lead to the inconsistent views of data Uncertainty as to when changes become permanent: can we be confident about the results residing in secondary storage even if processes have completed successfully? The concept of a transaction was invented to solve these problems 2

Transaction Processing (Διαχείριση Δοσοληψιών) A transaction is a series of database operations (reads and writes) that form a single logical entity with respect to the application being modeled. Example: a transfer of funds between accounts is considered a logical entity A transaction commits when it finishes execution normally otherwise it aborts User transactions appear to execute in isolation, although they may execute concurrently 3

Inconsistent view of Data (Ασυνέπεια στα Δεδομένα) accounts account# lname fname type balance 1234 Doe John Checking 900.00 5678 Doe John Savings 100.00..... Process P1 transfers $400 from account 1234 to account 5678 Transfer is implemented by 1. (S1) subtracting $400 from the balance of account 1234 2. (S2) adding $400 to the balance of account 5678 Accounts can be found in the following 3 states: Balance 1234 Balance 5678 Before P1 $900 $100 After S1 $500 $100 After S2 $500 $500 4

Inconsistent view of Data: Process Interleaving (Ασυνέπεια στα Δεδομένα: Παρεμβολές μεταξύ Διαδικασιών) Process P2 performs a credit check on the account holder and requires a minimum of $900 as the total balance of the accounts to approve the insurance of a credit card P2 reads the balance values of the two accounts and computes their sum P2 and P1 are running concurrently Execution is incorrect since the real sum is 1000$ Process P1 subtract 400$ from the balance of 1234 balance:=500 add $400 to the balance of 5678 Process P2 sum:=0 add balance of 1234 to sum sum:=sum+500 = 500 add balance of 5678 to sum sum:=500 + 100 = 600 reject 5

Inconsistent view of Data: Process Interleaving It is equivalent to serial executions P1, P2 This execution is correct both processes see the correct data Transaction management must ensure that only correct interleaving of processes takes place Process P1 subtract 400$ from the balance of 1234 balance:=500 add $400 to the balance of 5678 Process P2 sum:=0 add balance of 1234 to sum sum:=900 add balance of 5678 to sum sum:=900+ 100 = 1000 Issue approval 6

Transaction Management Transactions guarantee the following properties: Atomicity (Ατομικότητα) Consistency (Συνέπεια) Isolation (Μεμονωμένη Εκτέλεση Διαδικασιών) Durability (Διάρκεια) Known as ACID Properties 7

Transaction Management: ACID Properties Atomicity Transactions are considered atomic when considering their effect on the database: all operations that make up the transaction are executed or none is: the set of operations that make up the transaction is considered indivisible result of the transaction is preserved even when crashes occur: a database recovery procedure performs a rollback to bring the database back to its state prior to transaction execution 8

Transaction Management: ACID Properties Consistency a transaction should preserve a domain-specific consistency constraint independently of whether it is executed concurrently with other transactions or in isolation. Isolation (serializability) serial schedule: when transactions are executed one after the other any schedule of interleaved execution of transactions is equivalent to some serial schedule Durability After a transaction commits, it is guaranteed to be recoverable transactions are durable to crashes 9

Transaction Management (ACID Properties) Atomicity and durability are trivially satisfied by any transaction that performs only read operations Notation: Transactions: T 1, T 2, T k R i (X): transaction T i reads database item X R i (X,u): transaction T i reads database item X, u is the value read W i (X): transaction T i writes database item X W i (X,u): transaction T i writes database item X, u is the value written C i : transaction T i commits A i : transaction T i aborts 10

Transaction Management (ACID Properties) A schedule or history is an interleaved sequence of operations. Transactions: T 1, T 2 Schedule : R 2 (A) W 2 (A) R 1 (A) R 1 (B) R 2 (B) W 2 (B) C 1 C 2 A schedule is the result of the translation of processes - specified in some high-level language - into a series of primitive operations The scheduler component of the transaction processing component of a DBMS ensures that only correct schedules are executed 11

Transaction Management (ACID Properties) Given a set of transaction specifications, the scheduler component produces a schedule that is equivalent to some serial execution of the transaction If no such schedule is possible, the transaction manager aborts or delays some of the transactions The scheduler also detects deadlocks Situations in which none of the transactions participating in the schedule can proceed unless one of them is aborted 12

Example: Scheduling Schedule S = R 2 (A) W 2 (A) R 1 (A) R 1 (B) R 2 (B) W 2 (B) C 1 C 2 involves transactions T 1, T 2 is not equivalent to any serial execution of the two transactions. Interpretation of the schedule T 1 = R 1 (A), R 1 (B), C 1 T 2 = R 2 (A), W 2 (A), R2(B),W 2 (B), C 2 13

Example: Scheduling Schedule S = R 2 (A) W 2 (A) R 1 (A) R 1 (B) R 2 (B) W 2 (B) C 1 C 2 T 1 = R 1 (A), R 1 (B), C 1 T 2 = R 2 (A), W 2 (A), W 2 (B), C 2 S is correct only if it is equivalent to one of the serial schedules T 1, T 2 or T 2, T 1 Case 1: serial schedule S = T 1, T 2 S: T 1 reads A after T 2 has modified it. S : the values of A and B read by T 1 have not been modified by T 2 Case 2: serial schedule S = T 2, T 1 S: T1 reads B before T 2 writes it. S : T 2 modifies the values of A and B, then T 1 reads it. Hence the schedule has different effects than any serial execution 14

Interleaving of DB Operations Interleaving of database operations can yield large performance gains While some transaction is performing I/O, another transaction can use the CPU System throughput the number of transactions that can finish execution in a given period of time) increases whereas response time remains constant 15

Serial vs Concurrent Execution (Example) Transaction Manager services database transactions Each transaction uses both CPU and I/O Resources T i : (cpu operation) R I () (cpu operation) W I () C I The system has a single CPU with a 5ms interval and a single disk. Each I/O operation requires 50ms of wait time. Serial Execution: Resource usage 16

Serial vs Concurrent Execution (Example) Serial Execution a transaction needs 110ms throughput is 1 transaction per 110ms (9.09 transactions per second) CPU is underutilized: active 9.09% of the time Interleaved execution of transactions can increase CPU utilization and thus the system throughput 17

Serial vs Concurrent Execution (Example) Interleaved Execution throughput has increased throughput will increase with the number of transactions processes executed concurrently additional improvements: more than one I/O devices are used 18

Testing Serializability Criteria to determine given a set of transactions S if interleaved schedules for S are equivalent to some serial execution for the transactions in S Conflicting database operations when they I. belong to different transactions II. III. refer to the same data item at least one of them is a write operation a transaction reads an attribute and another tries to write its value 19

Properties of Schedules Two schedules are called equivalent if for any initial state of the database, they result to the same database state. Two schedules are equivalent if all pairs of conflicting operations occur in the same order A schedule is called serializable if it can be shown to be equivalent to some serial execution of its transactions Only serializable schedules are acceptable Example: T 1 = R 1 (A), R 1 (B), W 1 (A), C 1 T 2 = W 2 (A), R 2 (A), C 2 S = W 2 (A) R 1 (A) R 1 (B) R 2 (A) W 1 (A) Is S serializable? There may be more than one serial schedules equivalent to some serializable schedule Yes, it is equivalent to T 2 T 1 20

Testing Schedule Serializability Notation: op i (X) << S op j (X) means that operation op i of some transaction T i on item X, precedes operation op j of some transaction T j on item X in schedule S Cases: If op i (X)<< S1 op j (X) then op i (X)<< S2 op j (X) where S2 is a serial schedule equivalent to S1 If op i (X)<< S1 op j (X) and op j (Y) << S1 op i (Y), then S1 is not serializable. If it were, then, in the equivalent serial schedule S2, transaction T i should both precede and follow transaction T j. 21

Testing Serializability: The lost update problem The case in which two users want to update the same item in a database. Suppose transaction T 1 reads item A first : R 1 (A) Assume transaction T 2 reads item A: R 2 (A) T 2 writes immediately its value to A, before T 1 performs the update: W 2 (A) T 1 writes its value to A: W 1 (A) Hence any changes made by T 2, are lost. 22

Testing Serializability: The lost update problem Schedule: S1 = R 1 (A) R 2 (A) W 2 (A) W 1 (A) C 1 C 2 Conflicting Operations: R 1 (A), W 2 (A) R 2 (A), W 1 (A) Assume there is a serial schedule S2 equivalent to S1. S1: R 1 (A) << S1 W 2 (A) S2: R 1 (A) << S2 W 2 (A) T1 must precede T2 S1: R 2 (A) << S1 W 1 (A) S2:R 2 (A) << S2 W 1 (A) T2 must precede T1 The schedule is non-serializable 23

Testing Serializability: The blind write problem Occurs when a transaction writes a value before reading it Schedule: S1 = W 1 (A) W 2 (A) W 2 (B) W 1 (B) C 1 C 2 Conflicting Operations: W 1 (A) W 2 (A) W 2 (B) W 1 (B) Assume there is a serial schedule S2 equivalent to S1. S1: W 1 (A) << S1 W 2 (A) S2: W 1 (A) << S2 W 2 (A) T1 must precede T2 S1: W 2 (B) << S1 W 1 (B) S2:W 2 (B) << S2 W 1 (B) T2 must precede T1 The schedule is non-serializable 24

Testing Serializability: Precedence Graphs Given a schedule S, a precedence graph graph PG(S) for S is a directed graph whose vertices correspond to the transactions T in the schedule and set of edges consists of an edge Ti Tj whenever there exist two conflicting operations op i, op j in S and op i << S op j Example: S1 = R 1 (A) R 2 (A) W 1 (A) W 2 (A) C 1 C 2 PG(S1) PG(S2) T1 T2 Schedule S2 = W 1 (A) W 2 (A) W 2 (B) W 1 (B) C 1 C 2 25

Serializability Theorem: A schedule S is serializable if and only if the precedence graph PG(S) contains no cycle Lemma 1: In any finite directed acyclic graph G, there is always a vertex u with no incoming edges Proof: Case 1: If PG(S) has no cycles, S is serializable Assume that there are m transactions T 1, T 2, T m in S. We need to find a reordering T i1, T i2, T im of the transactions in order to construct an equivalent serial schedule By Lemma 1, in the precedence graph PG(S) there will be some vertex T k with no incoming edges. Let T i1 be T k. 26

Serializability HY 360 - Lecture 14 Since T k has no incoming edges in PG(S), there is no pair of conflicting operations of T k and some other transaction T j such that the operation of T j should precede that of T k. Hence in the equivalent serial schedule, T k. should be the first to be executed. Remove T k from PG(S) along with all its incident edges. The resulting graph is still acyclic. Hence we can find a vertex T l that has no incoming edges. Let T i2 be T l.then T l should follow T k in the serial schedule. Continue this process until the precedence graph contains one vertex. The corresponding transaction is the last one in the serial schedule. Case (2): If S is serializable, then PG(S) is acyclic. Let PG(S) contain a cycle: T1 << S T2 << S T3. << Tk << S T1 (contradiction) 27